From ead6ea96dde98625faa80f9c2fbc99713b922b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 25 Aug 2024 11:00:20 +0200 Subject: [PATCH] Group generation of BOM's code at creation --- modules/production/bom.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/production/bom.py b/modules/production/bom.py index d3bd6b9b70..eed892e182 100644 --- a/modules/production/bom.py +++ b/modules/production/bom.py @@ -87,20 +87,21 @@ class BOM(DeactivableMixin, ModelSQL, ModelView): return 0 @classmethod - def _new_code(cls): + def _code_sequence(cls): pool = Pool() Configuration = pool.get('production.configuration') config = Configuration(1) - sequence = config.bom_sequence - if sequence: - return sequence.get() + return config.bom_sequence @classmethod def create(cls, vlist): vlist = [v.copy() for v in vlist] - for values in vlist: - if not values.get('code'): - values['code'] = cls._new_code() + missing_code = [v for v in vlist if not v.get('code')] + if missing_code: + if sequence := cls._code_sequence(): + for values, code in zip( + missing_code, sequence.get_many(len(missing_code))): + values['code'] = code return super().create(vlist) @classmethod