diff --git a/modules/purchase_trade/coffee.py b/modules/purchase_trade/coffee.py index 56b7a10..cf2e88f 100644 --- a/modules/purchase_trade/coffee.py +++ b/modules/purchase_trade/coffee.py @@ -1074,7 +1074,7 @@ class CoffeeLabAnalysis(Workflow, ModelSQL, ModelView): class CoffeeLineMixin: active_coffee_compatibility = fields.Function( fields.Boolean('Active coffee compatibility'), - 'on_change_with_active_coffee_compatibility') + 'get_active_coffee_compatibility') coffee_samples = fields.One2Many( 'coffee.sample', None, 'Coffee samples') coffee_quality_status = fields.Function(fields.Selection([ @@ -1100,9 +1100,12 @@ class CoffeeLineMixin: def _coffee_samples(self): return list(getattr(self, 'coffee_samples', None) or []) - def on_change_with_active_coffee_compatibility(self, name=None): + def get_active_coffee_compatibility(self, name=None): return coffee_compatibility_active() + def on_change_with_active_coffee_compatibility(self, name=None): + return self.get_active_coffee_compatibility(name) + def get_coffee_quality_status(self, name=None): samples = self._coffee_samples() if not samples: diff --git a/modules/purchase_trade/configuration.py b/modules/purchase_trade/configuration.py index c846074..d88636b 100644 --- a/modules/purchase_trade/configuration.py +++ b/modules/purchase_trade/configuration.py @@ -171,15 +171,25 @@ class Configuration(ModelSingleton, ModelSQL, ModelView): def create(cls, vlist): records = super().create(vlist) cls._sync_report_labels(records) - cls._sync_coffee_menu_visibility(records) + active = any( + bool(values.get( + 'active_coffee_compatibility', + cls.default_active_coffee_compatibility())) + for values in vlist) + cls._sync_coffee_menu_visibility(records, active=active) return records @classmethod def write(cls, *args): + actions = list(zip(args[::2], args[1::2])) + active = None + for records, values in actions: + if 'active_coffee_compatibility' in values: + active = bool(values['active_coffee_compatibility']) super().write(*args) records = sum(args[::2], []) cls._sync_report_labels(records) - cls._sync_coffee_menu_visibility(records) + cls._sync_coffee_menu_visibility(records, active=active) @classmethod def _sync_report_labels(cls, records): @@ -202,15 +212,15 @@ class Configuration(ModelSingleton, ModelSQL, ModelView): ActionReport.write(*to_write) @classmethod - def _sync_coffee_menu_visibility(cls, records): - if not records: - return + def _sync_coffee_menu_visibility(cls, records=None, active=None): + if active is None: + configurations = cls.search([], limit=1) + active = bool( + configurations + and configurations[0].active_coffee_compatibility) pool = Pool() ModelData = pool.get('ir.model.data') Menu = pool.get('ir.ui.menu') - active = any( - bool(record.active_coffee_compatibility) - for record in records) menus = [] for xml_id in cls._COFFEE_MENU_XML_IDS: try: diff --git a/modules/purchase_trade/view/purchase_line_form.xml b/modules/purchase_trade/view/purchase_line_form.xml index 9fdf900..45abd6a 100755 --- a/modules/purchase_trade/view/purchase_line_form.xml +++ b/modules/purchase_trade/view/purchase_line_form.xml @@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. --> + @@ -137,7 +138,6 @@ this repository contains the full copyright notices and license terms. --> - diff --git a/modules/purchase_trade/view/sale_line_form.xml b/modules/purchase_trade/view/sale_line_form.xml index 234a4c2..c47eb4d 100755 --- a/modules/purchase_trade/view/sale_line_form.xml +++ b/modules/purchase_trade/view/sale_line_form.xml @@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. --> + @@ -130,7 +131,6 @@ this repository contains the full copyright notices and license terms. --> -