From 15feef82d89a64d9ce4cf475bf9700c210747f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 21 Jan 2025 00:25:18 +0100 Subject: [PATCH] Use compute fields for places on stock move --- modules/stock_product_location_place/stock.py | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/stock_product_location_place/stock.py b/modules/stock_product_location_place/stock.py index ad00149e5b..842bc99915 100644 --- a/modules/stock_product_location_place/stock.py +++ b/modules/stock_product_location_place/stock.py @@ -123,11 +123,19 @@ class Move(metaclass=PoolMeta): filter(None, [name, self.to_place.rec_name])).strip() return name - @classmethod - def create(cls, vlist): - moves = super().create(vlist) - cls._sync_places(moves) - return moves + def compute_fields(self, field_names=None): + cls = self.__class__ + values = super().compute_fields(field_names=field_names) + if getattr(self, 'state', None) not in {'done', 'cancelled'}: + if not field_names or cls.from_place.on_change_with & field_names: + from_place = self.on_change_with_from_place() + if getattr(self, 'from_place', None) != from_place: + values['from_place'] = from_place + if not field_names or cls.to_place.on_change_with & field_names: + to_place = self.on_change_with_to_place() + if getattr(self, 'to_place', None) != to_place: + values['to_place'] = to_place + return values @classmethod def write(cls, *args): @@ -142,21 +150,6 @@ class Move(metaclass=PoolMeta): args.extend((moves, values)) super().write(*args) - moves = sum(args[0:None:2], []) - cls._sync_places(moves) - - @classmethod - def _sync_places(cls, moves): - for move in moves: - if move.state in {'done', 'cancelled'}: - continue - from_place = move.on_change_with_from_place() - to_place = move.on_change_with_to_place() - if (move.from_place != from_place - or move.to_place != to_place): - move.from_place = from_place - move.to_place = to_place - cls.save(moves) class ShipmentIn(metaclass=PoolMeta):