changeset a62d5e858c94 in modules/account_invoice_correction:default
details: 
https://hg.tryton.org/modules/account_invoice_correction?cmd=changeset;node=a62d5e858c94
description:
        Keep stock moves when credit or correct an invoice

        issue9140
        review273041002
diffstat:

 CHANGELOG  |   2 ++
 invoice.py |  25 +++++++++++++------------
 2 files changed, 15 insertions(+), 12 deletions(-)

diffs (45 lines):

diff -r 3495379010b8 -r a62d5e858c94 CHANGELOG
--- a/CHANGELOG Thu Mar 19 18:59:23 2020 +0100
+++ b/CHANGELOG Sat Mar 28 16:51:52 2020 +0100
@@ -1,3 +1,5 @@
+* Add _account_invoice_correction context keyword when copying for correction
+
 Version 5.4.0 - 2019-11-04
 * Bug fixes (see mercurial logs for details)
 
diff -r 3495379010b8 -r a62d5e858c94 invoice.py
--- a/invoice.py        Thu Mar 19 18:59:23 2020 +0100
+++ b/invoice.py        Sat Mar 28 16:51:52 2020 +0100
@@ -68,19 +68,20 @@
         Line = pool.get('account.invoice.line')
 
         invoice = Invoice(Transaction().context['active_id'])
-        correction, = Invoice.copy([invoice], default={
-                'lines': [],
-                })
-        # Copy each line one by one to get negative and positive lines
-        # following each other
-        for line in self.start.lines:
-            Line.copy([line], default={
-                    'invoice': correction.id,
-                    'quantity': -line.quantity,
+        with Transaction().set_context(_account_invoice_correction=True):
+            correction, = Invoice.copy([invoice], default={
+                    'lines': [],
                     })
-            Line.copy([line], default={
-                    'invoice': correction.id,
-                    })
+            # Copy each line one by one to get negative and positive lines
+            # following each other
+            for line in self.start.lines:
+                Line.copy([line], default={
+                        'invoice': correction.id,
+                        'quantity': -line.quantity,
+                        })
+                Line.copy([line], default={
+                        'invoice': correction.id,
+                        })
         Invoice.update_taxes([correction])
         data = {'res_id': [correction.id]}
         return action, data

Reply via email to