changeset 23cf8d3c4d2d in modules/stock_consignment:default
details:
https://hg.tryton.org/modules/stock_consignment?cmd=changeset;node=23cf8d3c4d2d
description:
Don't set default unit price on stock move
issue8119
review255251002
diffstat:
stock.py | 21 +++++++++++++++++++++
tests/scenario_stock_consignment.rst | 1 +
2 files changed, 22 insertions(+), 0 deletions(-)
diffs (49 lines):
diff -r da6c0296576a -r 23cf8d3c4d2d stock.py
--- a/stock.py Sun Apr 07 19:50:04 2019 +0200
+++ b/stock.py Tue Apr 23 09:10:22 2019 +0200
@@ -60,6 +60,10 @@
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 @@
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 -r da6c0296576a -r 23cf8d3c4d2d tests/scenario_stock_consignment.rst
--- a/tests/scenario_stock_consignment.rst Sun Apr 07 19:50:04 2019 +0200
+++ b/tests/scenario_stock_consignment.rst Tue Apr 23 09:10:22 2019 +0200
@@ -176,6 +176,7 @@
>>> 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')