diff --git a/stock.py b/stock.py index e49f4f8bde..7d1d9eeb6a 100644 --- a/stock.py +++ b/stock.py @@ -65,7 +65,7 @@ def set_origin_consignment(func): to_save = [] move2line = {} for move in moves: - if all(l.origin != move for l in move.invoice_lines): + if not move.consignment_invoice_lines: lines = move.get_invoice_lines_consignment() if lines: to_save.extend(lines) @@ -90,12 +90,11 @@ def unset_origin_consignment(func): InvoiceLine = pool.get('account.invoice.line') lines, to_save = [], [] for move in moves: - for invoice_line in move.invoice_lines: - if invoice_line.origin == move: - lines.append(invoice_line) - if move.origin == move: - move.origin = None - to_save.append(move) + for invoice_line in move.consignment_invoice_lines: + lines.append(invoice_line) + if move.origin == move: + move.origin = None + to_save.append(move) if lines: InvoiceLine.delete(lines) cls.save(to_save) @@ -106,6 +105,13 @@ def unset_origin_consignment(func): class Move(metaclass=PoolMeta): __name__ = 'stock.move' + consignment_invoice_lines = fields.One2Many( + 'account.invoice.line', 'origin', "Consignment Invoice Lines", + readonly=True, + states={ + 'invisible': ~Eval('consignment_invoice_lines'), + }) + @fields.depends('state', 'from_location', 'to_location') def on_change_with_unit_price_required(self, name=None): required = super().on_change_with_unit_price_required(name) diff --git a/stock.xml b/stock.xml index 82f4599b8c..4ebdbcc5c4 100644 --- a/stock.xml +++ b/stock.xml @@ -8,5 +8,11 @@ this repository contains the full copyright notices and license terms. --> location_form + + + stock.move + + stock_move_form + diff --git a/view/stock_move_form.xml b/view/stock_move_form.xml new file mode 100644 index 0000000000..cd936b9796 --- /dev/null +++ b/view/stock_move_form.xml @@ -0,0 +1,10 @@ + + + + + + + + +