Coffee
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from trytond.model import ModelSQL, ModelView, Workflow, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
@@ -1072,11 +1074,23 @@ class CoffeeLabAnalysis(Workflow, ModelSQL, ModelView):
|
||||
|
||||
|
||||
class CoffeeLineMixin:
|
||||
_coffee_view_fields = {
|
||||
'coffee_quality_status',
|
||||
'coffee_origin',
|
||||
'coffee_type',
|
||||
'coffee_process',
|
||||
'coffee_variety',
|
||||
'coffee_crop_year',
|
||||
'coffee_screen_size',
|
||||
'coffee_moisture_max',
|
||||
'coffee_defect_max',
|
||||
'coffee_cup_score_min',
|
||||
'coffee_samples',
|
||||
}
|
||||
|
||||
active_coffee_compatibility = fields.Function(
|
||||
fields.Boolean('Active coffee compatibility'),
|
||||
'get_active_coffee_compatibility')
|
||||
coffee_samples = fields.One2Many(
|
||||
'coffee.sample', None, 'Coffee samples')
|
||||
coffee_quality_status = fields.Function(fields.Selection([
|
||||
(None, ''),
|
||||
('none', 'No sample'),
|
||||
@@ -1107,14 +1121,24 @@ class CoffeeLineMixin:
|
||||
return self.get_active_coffee_compatibility(name)
|
||||
|
||||
@classmethod
|
||||
def view_attributes(cls):
|
||||
attributes = super().view_attributes()
|
||||
if not coffee_compatibility_active():
|
||||
attributes += [
|
||||
('//page[@id="coffee_quality"]', 'states',
|
||||
{'invisible': True}),
|
||||
]
|
||||
return attributes
|
||||
def fields_view_get(cls, view_id=None, view_type='form', level=None):
|
||||
result = super().fields_view_get(
|
||||
view_id=view_id, view_type=view_type, level=level)
|
||||
if view_type == 'form' and not coffee_compatibility_active():
|
||||
cls._remove_coffee_quality_page(result)
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def _remove_coffee_quality_page(cls, view):
|
||||
parser = etree.XMLParser(remove_blank_text=True, resolve_entities=False)
|
||||
tree = etree.fromstring(view['arch'], parser)
|
||||
for page in tree.xpath('//page[@id="coffee_quality"]'):
|
||||
parent = page.getparent()
|
||||
if parent is not None:
|
||||
parent.remove(page)
|
||||
view['arch'] = etree.tostring(tree, encoding='unicode')
|
||||
for field_name in cls._coffee_view_fields:
|
||||
view.get('fields', {}).pop(field_name, None)
|
||||
|
||||
def get_coffee_quality_status(self, name=None):
|
||||
samples = self._coffee_samples()
|
||||
|
||||
@@ -5,7 +5,6 @@ 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">
|
||||
@@ -136,8 +135,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page[@id='general']" position="after">
|
||||
<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')}">
|
||||
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr">
|
||||
<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">
|
||||
|
||||
@@ -5,7 +5,6 @@ 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">
|
||||
@@ -129,8 +128,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
</xpath>
|
||||
<xpath expr="/form/notebook/page[@id='general']" position="after">
|
||||
<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')}">
|
||||
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr">
|
||||
<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">
|
||||
|
||||
Reference in New Issue
Block a user