From d11dfd7e70d50910c554fd6d210a07a268bb6d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 6 Apr 2022 18:52:08 +0200 Subject: [PATCH] Delete stock moves from components when applying amendment issue11355 review386301002 (grafted from ffeafe1cbe9fa2dce255157936cfae676d07ebe7) --HG-- branch : 6.0 --- __init__.py | 2 ++ purchase.py | 12 ++++++++++++ sale.py | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/__init__.py b/__init__.py index 6f72541846..fbeaafa443 100644 --- a/__init__.py +++ b/__init__.py @@ -37,6 +37,7 @@ def register(): sale.HandleShipmentException, module='product_kit', type_='wizard', depends=['sale']) Pool.register( + sale.Amendment, sale.AmendmentLine, module='product_kit', type_='model', depends=['sale_amendment']) Pool.register( @@ -52,5 +53,6 @@ def register(): purchase.HandleShipmentException, module='product_kit', type_='wizard', depends=['purchase']) Pool.register( + purchase.Amendment, purchase.AmendmentLine, module='product_kit', type_='model', depends=['purchase_amendment']) diff --git a/purchase.py b/purchase.py index 1fcfcd7602..ba76c33c39 100644 --- a/purchase.py +++ b/purchase.py @@ -132,5 +132,17 @@ class HandleShipmentException( __name__ = 'purchase.handle.shipment.exception' +class Amendment(metaclass=PoolMeta): + __name__ = 'purchase.amendment' + + @classmethod + def _stock_moves(cls, line): + yield from super()._stock_moves(line) + for component in line.components: + for move in component.moves: + if move.state == 'draft': + yield move + + class AmendmentLine(AmendmentLineMixin, metaclass=PoolMeta): __name__ = 'purchase.amendment.line' diff --git a/sale.py b/sale.py index 47a564ca17..823e1c1d5c 100644 --- a/sale.py +++ b/sale.py @@ -144,5 +144,17 @@ class HandleShipmentException( __name__ = 'sale.handle.shipment.exception' +class Amendment(metaclass=PoolMeta): + __name__ = 'sale.amendment' + + @classmethod + def _stock_moves(cls, line): + yield from super()._stock_moves(line) + for component in line.components: + for move in component.moves: + if move.state == 'draft': + yield move + + class AmendmentLine(AmendmentLineMixin, metaclass=PoolMeta): __name__ = 'sale.amendment.line'