lims_industry: add unique on equipment type, brand, component type and equipment template

This commit is contained in:
Sebastián Marró 2020-06-14 14:25:55 -03:00
parent de0f116549
commit a60cb783ba
3 changed files with 61 additions and 0 deletions

View File

@ -81,6 +81,15 @@ class EquipmentType(ModelSQL, ModelView):
name = fields.Char('Name', required=True)
@classmethod
def __setup__(cls):
super(EquipmentType, cls).__setup__()
t = cls.__table__()
cls._sql_constraints = [
('name_unique', Unique(t, t.name),
'lims_industry.msg_equipment_type_name_unique'),
]
class Brand(ModelSQL, ModelView):
'Brand'
@ -88,6 +97,15 @@ class Brand(ModelSQL, ModelView):
name = fields.Char('Name', required=True)
@classmethod
def __setup__(cls):
super(Brand, cls).__setup__()
t = cls.__table__()
cls._sql_constraints = [
('name_unique', Unique(t, t.name),
'lims_industry.msg_brand_name_unique'),
]
class ComponentType(ModelSQL, ModelView):
'Component Type'
@ -97,6 +115,15 @@ class ComponentType(ModelSQL, ModelView):
product_type = fields.Many2One('lims.product.type', 'Product type',
required=True)
@classmethod
def __setup__(cls):
super(ComponentType, cls).__setup__()
t = cls.__table__()
cls._sql_constraints = [
('name_unique', Unique(t, t.name),
'lims_industry.msg_component_type_name_unique'),
]
class EquipmentTemplate(ModelSQL, ModelView):
'Equipment Template'
@ -116,6 +143,11 @@ class EquipmentTemplate(ModelSQL, ModelView):
cls._order.insert(0, ('type', 'ASC'))
cls._order.insert(1, ('brand', 'ASC'))
cls._order.insert(2, ('model', 'ASC'))
t = cls.__table__()
cls._sql_constraints = [
('type_brand_model_unique', Unique(t, t.type, t.brand, t.model),
'lims_industry.msg_equipment_template_unique'),
]
def get_rec_name(self, name):
res = '%s - %s' % (self.type.rec_name, self.brand.rec_name)

View File

@ -653,6 +653,14 @@ msgctxt "model:ir.message,text:lbl_sample_missing_data"
msgid "Missing data in Sample"
msgstr "Faltan datos en Muestra"
msgctxt "model:ir.message,text:msg_brand_name_unique"
msgid "There is already a brand with the same name"
msgstr "Ya existe una marca con el mismo nombre"
msgctxt "model:ir.message,text:msg_component_type_name_unique"
msgid "There is already a component type with the same name"
msgstr "Ya existe un tipo de componente con el mismo nombre"
msgctxt "model:ir.message,text:msg_component_type_unique"
msgid "A component of the same type already exists for the equipment"
msgstr "Ya existe un componente del mismo tipo para el equipo"
@ -661,6 +669,15 @@ msgctxt "model:ir.message,text:msg_equipment_name_unique"
msgid "There is already an equipment with the same name for the plant"
msgstr "Ya existe un equipo con el mismo nombre para la planta"
msgctxt "model:ir.message,text:msg_equipment_template_unique"
msgid ""
"There is already a equipment template with the same type, brand and model"
msgstr "Ya existe una plantilla de equipo con el mismo tipo, marca y modelo"
msgctxt "model:ir.message,text:msg_equipment_type_name_unique"
msgid "There is already a equipment type with the same name"
msgstr "Ya existe un tipo de equipo con el mismo nombre"
msgctxt "model:ir.message,text:msg_party_no_email"
msgid "Party \"%(party)s\" has no Email"
msgstr "La entidad «%(party)s» no tiene correo electrónico"

View File

@ -37,5 +37,17 @@
<record model="ir.message" id="msg_plant_name_unique">
<field name="text">There is already a plant with the same name for the party</field>
</record>
<record model="ir.message" id="msg_equipment_type_name_unique">
<field name="text">There is already a equipment type with the same name</field>
</record>
<record model="ir.message" id="msg_brand_name_unique">
<field name="text">There is already a brand with the same name</field>
</record>
<record model="ir.message" id="msg_component_type_name_unique">
<field name="text">There is already a component type with the same name</field>
</record>
<record model="ir.message" id="msg_equipment_template_unique">
<field name="text">There is already a equipment template with the same type, brand and model</field>
</record>
</data>
</tryton>