changeset f22b14e99ceb in modules/stock_consignment:default
details: 
https://hg.tryton.org/modules/stock_consignment?cmd=changeset;node=f22b14e99ceb
description:
        Create invoice line based on line origin instead of move origin

        Since issue8253, the inventory move has an origin set to the 
outgoing/incoming
        move, so we can not rely on it to decide to create invoice lines or not.

        issue8566
        review270101002
diffstat:

 stock.py                             |  15 +++++++++------
 tests/scenario_stock_consignment.rst |   4 ++--
 2 files changed, 11 insertions(+), 8 deletions(-)

diffs (49 lines):

diff -r 04931059a81b -r f22b14e99ceb stock.py
--- a/stock.py  Mon May 06 15:14:40 2019 +0200
+++ b/stock.py  Sun Aug 18 18:47:20 2019 +0200
@@ -51,11 +51,12 @@
         to_save = []
         move2line = {}
         for move in moves:
-            if not move.origin:
+            if not move.invoice_lines:
                 lines = move.get_invoice_lines_consignment()
                 if lines:
                     to_save.extend(lines)
-                    move2line[move] = lines[0]
+                    if not move.origin:
+                        move2line[move] = lines[0]
         if to_save:
             InvoiceLine.save(to_save)
             for move, line in move2line.items():
@@ -76,10 +77,12 @@
         InvoiceLine = pool.get('account.invoice.line')
         lines, to_save = [], []
         for move in moves:
-            if isinstance(move.origin, InvoiceLine):
-                lines.extend(move.invoice_lines)
-                move.origin = None
-                to_save.append(move)
+            for invoice_line in move.invoice_lines:
+                if invoice_line.origin == move:
+                    lines.append(invoice_line)
+                    if isinstance(move.origin, InvoiceLine):
+                        move.origin = None
+                    to_save.append(move)
         if lines:
             InvoiceLine.delete(lines)
             cls.save(to_save)
diff -r 04931059a81b -r f22b14e99ceb tests/scenario_stock_consignment.rst
--- a/tests/scenario_stock_consignment.rst      Mon May 06 15:14:40 2019 +0200
+++ b/tests/scenario_stock_consignment.rst      Sun Aug 18 18:47:20 2019 +0200
@@ -185,8 +185,8 @@
     >>> shipment_out.click('assign_try')
     True
     >>> move, = shipment_out.inventory_moves
-    >>> isinstance(move.origin, InvoiceLine)
-    True
+    >>> len(move.invoice_lines)
+    1
 
 Fill customer consignment location::
 

Reply via email to