From 5ec0f06ffb9901211cfcb0ec886108155d3d510f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 23 Apr 2019 09:10:22 +0200 Subject: [PATCH] Don't set default unit price on stock move issue8119 review255251002 --- stock.py | 21 +++++++++++++++++++++ tests/scenario_stock_consignment.rst | 1 + 2 files changed, 22 insertions(+) diff --git a/stock.py b/stock.py index 74ac338fed..4b3c6a1587 100644 --- a/stock.py +++ b/stock.py @@ -60,6 +60,10 @@ def set_origin_consignment(func): InvoiceLine.save(to_save) for move, line in move2line.items(): move.origin = line + if (not move.unit_price + and move.on_change_with_unit_price_required()): + move.unit_price = line.unit_price + move.currency = line.currency cls.save(list(move2line.keys())) return func(cls, moves) return wrapper @@ -89,6 +93,23 @@ class Move(metaclass=PoolMeta): invoice_lines = fields.One2Many( 'account.invoice.line', 'origin', "Invoice Lines", readonly=True) + @fields.depends('origin', 'from_location', 'to_location') + def on_change_with_unit_price_required(self, name=None): + required = super().on_change_with_unit_price_required(name) + if (required + and not self.origin + and self.from_location + and self.to_location + and ((self.from_location.type == 'supplier' + and self.to_location.type in { + 'storage', 'production', 'customer'}) + or (self.from_location.type in { + 'storage', 'production', 'supplier'} + and self.to_location.type == 'customer')) + and self.from_location.consignment_party): + required = False + return required + @classmethod def _get_origin(cls): return super(Move, cls)._get_origin() + ['account.invoice.line'] diff --git a/tests/scenario_stock_consignment.rst b/tests/scenario_stock_consignment.rst index 3addc88dbd..978d3418e5 100644 --- a/tests/scenario_stock_consignment.rst +++ b/tests/scenario_stock_consignment.rst @@ -176,6 +176,7 @@ Use supplier consignment stock for shipment out:: >>> move = shipment_out.outgoing_moves.new() >>> move.product = product >>> move.quantity = 3 + >>> move.unit_price = Decimal('10') >>> move.from_location = output_loc >>> move.to_location = customer_loc >>> shipment_out.click('wait')