mirror of
https://github.com/Kalenis/kalenislims.git
synced 2023-12-14 07:13:04 +01:00
lims_industry: Equipment refactoring
This commit is contained in:
parent
be6b029b0a
commit
06706f4181
|
@ -4,6 +4,7 @@
|
|||
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pool import Pool
|
||||
|
||||
__all__ = ['Plant', 'EquipmentType', 'Brand', 'ComponentType',
|
||||
'EquipmentTemplate', 'EquipmentTemplateComponentType', 'Equipment',
|
||||
|
@ -72,7 +73,7 @@ class EquipmentTemplate(ModelSQL, ModelView):
|
|||
|
||||
type = fields.Many2One('lims.equipment.type', 'Type', required=True)
|
||||
brand = fields.Many2One('lims.brand', 'Brand', required=True)
|
||||
model = fields.Char('Model', required=True)
|
||||
model = fields.Char('Model')
|
||||
power = fields.Char('Power')
|
||||
component_types = fields.Many2Many(
|
||||
'lims.equipment.template-component.type',
|
||||
|
@ -86,8 +87,10 @@ class EquipmentTemplate(ModelSQL, ModelView):
|
|||
cls._order.insert(2, ('model', 'ASC'))
|
||||
|
||||
def get_rec_name(self, name):
|
||||
return '%s - %s - %s' % (
|
||||
self.type.rec_name, self.brand.rec_name, self.model)
|
||||
res = '%s - %s' % (self.type.rec_name, self.brand.rec_name)
|
||||
if self.model:
|
||||
res += ' - ' + self.model
|
||||
return res
|
||||
|
||||
|
||||
class EquipmentTemplateComponentType(ModelSQL):
|
||||
|
@ -108,6 +111,7 @@ class Equipment(ModelSQL, ModelView):
|
|||
template = fields.Many2One('lims.equipment.template', 'Template',
|
||||
required=True)
|
||||
name = fields.Char('Name', required=True)
|
||||
model = fields.Char('Model', required=True)
|
||||
serial_number = fields.Char('Serial number')
|
||||
internal_id = fields.Char('Internal ID Code')
|
||||
latitude = fields.Numeric('Latitude', digits=(3, 14))
|
||||
|
@ -123,6 +127,7 @@ class Equipment(ModelSQL, ModelView):
|
|||
depends=['party'])
|
||||
party = fields.Function(fields.Many2One('party.party', 'Party'),
|
||||
'get_party', searcher='search_party')
|
||||
missing_data = fields.Boolean('Missing data')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -138,6 +143,23 @@ class Equipment(ModelSQL, ModelView):
|
|||
def search_party(cls, name, clause):
|
||||
return [('plant.party',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('template')
|
||||
def on_change_template(self):
|
||||
pool = Pool()
|
||||
Component = pool.get('lims.component')
|
||||
|
||||
model = None
|
||||
components = []
|
||||
if self.template:
|
||||
model = self.template.model
|
||||
for type in self.template.component_types:
|
||||
value = Component(**Component.default_get(
|
||||
list(Component._fields.keys())))
|
||||
value.type = type.id
|
||||
components.append(value)
|
||||
self.model = model
|
||||
self.components = components
|
||||
|
||||
|
||||
class Component(ModelSQL, ModelView):
|
||||
'Component'
|
||||
|
@ -146,13 +168,7 @@ class Component(ModelSQL, ModelView):
|
|||
equipment = fields.Many2One('lims.equipment', 'Equipment',
|
||||
required=True, ondelete='CASCADE', select=True,)
|
||||
type = fields.Many2One('lims.component.type', 'Type',
|
||||
required=True, domain=['OR',
|
||||
('id', '=', Eval('type')),
|
||||
('id', 'in', Eval('type_domain')),
|
||||
],
|
||||
depends=['type_domain'])
|
||||
type_domain = fields.Function(fields.Many2Many('lims.component.type',
|
||||
None, None, 'Type domain'), 'on_change_with_type_domain')
|
||||
required=True)
|
||||
capacity = fields.Char('Capacity (lts)')
|
||||
serial_number = fields.Char('Serial number')
|
||||
model = fields.Char('Model')
|
||||
|
@ -178,13 +194,6 @@ class Component(ModelSQL, ModelView):
|
|||
res += ' - ' + self.model
|
||||
return res
|
||||
|
||||
@fields.depends('equipment')
|
||||
def on_change_with_type_domain(self, name=None):
|
||||
types = []
|
||||
if self.equipment and self.equipment.template.component_types:
|
||||
types = [t.id for t in self.equipment.template.component_types]
|
||||
return types
|
||||
|
||||
def get_party(self, name):
|
||||
if self.equipment:
|
||||
return self.equipment.plant.party.id
|
||||
|
|
|
@ -86,10 +86,6 @@ msgctxt "field:lims.component,type:"
|
|||
msgid "Type"
|
||||
msgstr "Tipo"
|
||||
|
||||
msgctxt "field:lims.component,type_domain:"
|
||||
msgid "Type domain"
|
||||
msgstr "Dominio para Tipo"
|
||||
|
||||
msgctxt "field:lims.component,write_date:"
|
||||
msgid "Write Date"
|
||||
msgstr "Fecha modificación"
|
||||
|
@ -166,6 +162,14 @@ msgctxt "field:lims.equipment,longitude:"
|
|||
msgid "Longitude"
|
||||
msgstr "Longitud"
|
||||
|
||||
msgctxt "field:lims.equipment,missing_data:"
|
||||
msgid "Missing data"
|
||||
msgstr "Falta información"
|
||||
|
||||
msgctxt "field:lims.equipment,model:"
|
||||
msgid "Model"
|
||||
msgstr "Modelo"
|
||||
|
||||
msgctxt "field:lims.equipment,name:"
|
||||
msgid "Name"
|
||||
msgstr "Nombre"
|
||||
|
|
|
@ -20,5 +20,4 @@
|
|||
<field name="power"/>
|
||||
<label name="year_manufacturing"/>
|
||||
<field name="year_manufacturing"/>
|
||||
<field name="type_domain" colspan="4" invisible="1"/>
|
||||
</form>
|
||||
|
|
|
@ -6,8 +6,12 @@
|
|||
<field name="template"/>
|
||||
<notebook>
|
||||
<page id="general" string="General">
|
||||
<label name="model"/>
|
||||
<field name="model"/>
|
||||
<label name="plant"/>
|
||||
<field name="plant" colspan="3"/>
|
||||
<field name="plant"/>
|
||||
<label name="party"/>
|
||||
<field name="party" colspan="3"/>
|
||||
<label name="serial_number"/>
|
||||
<field name="serial_number"/>
|
||||
<label name="internal_id"/>
|
||||
|
@ -24,6 +28,8 @@
|
|||
<label name="longitude"/>
|
||||
<field name="longitude"/>
|
||||
</group>
|
||||
<label name="missing_data"/>
|
||||
<field name="missing_data"/>
|
||||
</page>
|
||||
<page id="components" string="Components">
|
||||
<field name="components" colspan="4"/>
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
<tree>
|
||||
<field name="template" expand="1"/>
|
||||
<field name="name" expand="1"/>
|
||||
<field name="model" expand="1"/>
|
||||
<field name="serial_number"/>
|
||||
<field name="internal_id"/>
|
||||
<field name="plant" expand="1"/>
|
||||
<field name="party" expand="1"/>
|
||||
<field name="missing_data"/>
|
||||
</tree>
|
||||
|
|
Loading…
Reference in a new issue