This commit is contained in:
2026-06-29 22:43:03 +02:00
parent cc4a48c38c
commit cd49703879
4 changed files with 25 additions and 12 deletions

View File

@@ -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:

View File

@@ -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:

View File

@@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/notebook/page[@id='general']" position="replace">
<page string="General" id="general" col="12"
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr">
<field name="active_coffee_compatibility" invisible="1" colspan="12"/>
<group id="identity" colspan="12" col="10" panel="summary"
xalign="0" yalign="0"
col_widths="min-content,2fr,min-content,1.2fr,min-content,1.2fr,min-content,1fr,min-content,0.8fr">
@@ -137,7 +138,6 @@ this repository contains the full copyright notices and license terms. -->
<page string="Coffee Quality" id="coffee_quality" col="12"
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr"
states="{'invisible': ~Eval('active_coffee_compatibility')}">
<field name="active_coffee_compatibility" invisible="1"/>
<group id="coffee_summary" colspan="12" col="8" panel="summary"
xalign="0" yalign="0"
col_widths="min-content,1fr,min-content,1fr,min-content,1fr,min-content,1fr">

View File

@@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/notebook/page[@id='general']" position="replace">
<page string="General" id="general" col="12"
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr">
<field name="active_coffee_compatibility" invisible="1" colspan="12"/>
<group id="identity" colspan="12" col="8" panel="summary"
xalign="0" yalign="0"
col_widths="min-content,2fr,min-content,1.2fr,min-content,1fr,min-content,0.8fr">
@@ -130,7 +131,6 @@ this repository contains the full copyright notices and license terms. -->
<page string="Coffee Quality" id="coffee_quality" col="12"
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr"
states="{'invisible': ~Eval('active_coffee_compatibility')}">
<field name="active_coffee_compatibility" invisible="1"/>
<group id="coffee_summary" colspan="12" col="8" panel="summary"
xalign="0" yalign="0"
col_widths="min-content,1fr,min-content,1fr,min-content,1fr,min-content,1fr">