From 881cbcfb2caf16ddd6e2178d25243c212636dd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 12 Mar 2023 22:11:34 +0100 Subject: [PATCH] Rename moves exception and simplify computation --- modules/product_kit/common.py | 18 ++++++++---------- modules/purchase/purchase.py | 19 ++++++++----------- modules/sale/sale.py | 19 ++++++++----------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/modules/product_kit/common.py b/modules/product_kit/common.py index 459505f317..77b675afb2 100644 --- a/modules/product_kit/common.py +++ b/modules/product_kit/common.py @@ -229,10 +229,10 @@ def order_line_mixin(prefix): move = None return move - def get_move_exception(self, name): - exception = super().get_move_exception(name) + def get_moves_exception(self, name): + exception = super().get_moves_exception(name) if self.components: - exception = any(c.move_exception for c in self.components) + exception = any(c.moves_exception for c in self.components) return exception def get_moves_progress(self, name): @@ -269,8 +269,8 @@ def order_line_component_mixin(prefix): moves_recreated = fields.Many2Many( prefix + '.line.component-recreated-stock.move', 'component', 'move', "Recreated Moves", readonly=True) - move_exception = fields.Function( - fields.Boolean('Moves Exception'), 'get_move_exception') + moves_exception = fields.Function( + fields.Boolean('Moves Exception'), 'get_moves_exception') moves_progress = fields.Function( fields.Float("Moves Progress", digits=(1, 4)), 'get_moves_progress') @@ -351,13 +351,11 @@ def order_line_component_mixin(prefix): move.uom, move.quantity, self.unit) return quantity - def get_move_exception(self, name): + def get_moves_exception(self, name): skips = set(self.moves_ignored) skips.update(self.moves_recreated) - for move in self.moves: - if move.state == 'cancelled' and move not in skips: - return True - return False + return any( + m.state == 'cancelled' for m in self.moves if m not in skips) def get_moves_progress(self, name): progress = None diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index e74f8d1c79..051dbab3f0 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -633,7 +633,7 @@ class Purchase( Return the shipment state for the purchase. ''' if self.moves: - if any(l.move_exception for l in self.lines): + if any(l.moves_exception for l in self.lines): return 'exception' elif all(l.moves_progress >= 1 for l in self.lines if l.moves_progress is not None): @@ -1225,8 +1225,8 @@ class Line(sequence_ordered(), ModelSQL, ModelView): 'purchase_line', 'move', 'Ignored Moves', readonly=True) moves_recreated = fields.Many2Many('purchase.line-recreated-stock.move', 'purchase_line', 'move', 'Recreated Moves', readonly=True) - move_exception = fields.Function(fields.Boolean('Moves Exception'), - 'get_move_exception') + moves_exception = fields.Function( + fields.Boolean("Moves Exception"), 'get_moves_exception') moves_progress = fields.Function( fields.Float("Moves Progress", digits=(1, 4)), 'get_moves_progress') @@ -1344,14 +1344,11 @@ class Line(sequence_ordered(), ModelSQL, ModelView): quantity -= Uom.compute_qty(move.uom, move.quantity, self.unit) return quantity - def get_move_exception(self, name): - skip_ids = set(x.id for x in self.moves_ignored - + self.moves_recreated) - for move in self.moves: - if move.state == 'cancelled' \ - and move.id not in skip_ids: - return True - return False + def get_moves_exception(self, name): + skips = set(self.moves_ignored) + skips.update(self.moves_recreated) + return any( + m.state == 'cancelled' for m in self.moves if m not in skips) def get_moves_progress(self, name): progress = None diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 42db08a8d3..f5f241a247 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -643,7 +643,7 @@ class Sale( Return the shipment state for the sale. ''' if self.moves: - if any(l.move_exception for l in self.lines): + if any(l.moves_exception for l in self.lines): return 'exception' elif all(l.moves_progress >= 1.0 for l in self.lines if l.moves_progress is not None): @@ -1291,8 +1291,8 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView): 'sale_line', 'move', 'Ignored Moves', readonly=True) moves_recreated = fields.Many2Many('sale.line-recreated-stock.move', 'sale_line', 'move', 'Recreated Moves', readonly=True) - move_exception = fields.Function(fields.Boolean('Moves Exception'), - 'get_move_exception') + moves_exception = fields.Function( + fields.Boolean("Moves Exception"), 'get_moves_exception') moves_progress = fields.Function( fields.Float("Moves Progress", digits=(1, 4)), 'get_moves_progress') @@ -1373,14 +1373,11 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView): quantity -= Uom.compute_qty(move.uom, move.quantity, self.unit) return quantity - def get_move_exception(self, name): - skip_ids = set(x.id for x in self.moves_ignored) - skip_ids.update(x.id for x in self.moves_recreated) - for move in self.moves: - if move.state == 'cancelled' \ - and move.id not in skip_ids: - return True - return False + def get_moves_exception(self, name): + skips = set(self.moves_ignored) + skips.update(self.moves_recreated) + return any( + m.state == 'cancelled' for m in self.moves if m not in skips) def get_moves_progress(self, name): progress = None