diff --git a/move.py b/move.py index 81da767778..483c6b55e8 100644 --- a/move.py +++ b/move.py @@ -432,14 +432,16 @@ class Move(Workflow, ModelSQL, ModelView): from_type = self.from_location.type if self.from_location else None to_type = self.to_location.type if self.to_location else None - if from_type == 'supplier' and to_type == 'storage': + if from_type == 'supplier' and to_type in {'storage', 'drop'}: return True if from_type == 'production': return True - if from_type == 'storage' and to_type == 'customer': + if from_type in {'storage', 'drop'} and to_type == 'customer': return True if from_type == 'storage' and to_type == 'supplier': return True + if from_type == 'customer' and to_type == 'storage': + return True return False @fields.depends('from_location', 'to_location') diff --git a/shipment.py b/shipment.py index 25c2d22b70..19f148e5b5 100644 --- a/shipment.py +++ b/shipment.py @@ -1113,7 +1113,7 @@ class ShipmentOut(ShipmentMixin, Workflow, ModelSQL, ModelView): 'Return inventory move for the outgoing move' pool = Pool() Move = pool.get('stock.move') - return Move( + inventory_move = Move( from_location=self.warehouse_storage, to_location=move.from_location, product=move.product, @@ -1122,11 +1122,13 @@ class ShipmentOut(ShipmentMixin, Workflow, ModelSQL, ModelView): shipment=self, planned_date=move.planned_date, company=move.company, - currency=move.currency, - unit_price=move.unit_price, origin=move, state='staging' if move.state == 'staging' else 'draft', ) + if inventory_move.on_change_with_unit_price_required(): + inventory_move.unit_price = move.unit_price + inventory_move.currency = move.currency + return inventory_move @classmethod @Workflow.transition('assigned') @@ -1164,11 +1166,13 @@ class ShipmentOut(ShipmentMixin, Workflow, ModelSQL, ModelView): ) if template: move.origin = template.origin - move.currency = template.currency - move.unit_price = template.unit_price - else: - move.currency = self.company.currency - move.unit_price = 0 + if move.on_change_with_unit_price_required(): + if template: + move.unit_price = template.unit_price + move.currency = template.currency + else: + move.unit_price = 0 + move.currency = self.company.currency return move @classmethod @@ -2224,11 +2228,13 @@ class ShipmentInternal(ShipmentMixin, Workflow, ModelSQL, ModelView): ) if template: move.origin = template.origin - move.currency = template.currency - move.unit_price = template.unit_price - else: - move.currency = self.company.currency - move.unit_price = 0 + if move.on_change_with_unit_price_required(): + if template: + move.unit_price = template.unit_price + move.currency = template.currency + else: + move.unit_price = 0 + move.currency = self.company.currency return move @classmethod diff --git a/tests/scenario_stock_shipment_out_return_same_storage_input.rst b/tests/scenario_stock_shipment_out_return_same_storage_input.rst index 9d151a6fab..2f5efe47c6 100644 --- a/tests/scenario_stock_shipment_out_return_same_storage_input.rst +++ b/tests/scenario_stock_shipment_out_return_same_storage_input.rst @@ -66,6 +66,8 @@ Create Shipment Out Return:: >>> move.quantity = 1 >>> move.from_location = customer_loc >>> move.to_location = storage1 + >>> move.unit_price = Decimal('20') + >>> move.currency = company.currency >>> shipment.save() >>> len(shipment.incoming_moves)