From d1f511c381eb2c0221b172e21c263340eb11d7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 18 Aug 2019 18:47:20 +0200 Subject: [PATCH] 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 --- stock.py | 15 +++++++++------ tests/scenario_stock_consignment.rst | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/stock.py b/stock.py index 4b3c6a1587..ac961f9395 100644 --- a/stock.py +++ b/stock.py @@ -51,11 +51,12 @@ def set_origin_consignment(func): 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 @@ def unset_origin_consignment(func): 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 --git a/tests/scenario_stock_consignment.rst b/tests/scenario_stock_consignment.rst index 978d3418e5..9cfb9bc4d5 100644 --- a/tests/scenario_stock_consignment.rst +++ b/tests/scenario_stock_consignment.rst @@ -185,8 +185,8 @@ Use supplier consignment stock for shipment out:: >>> 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::