From 998159835096baee78bf63c483871c103e2cb0ba Mon Sep 17 00:00:00 2001 From: sinergia Date: Wed, 3 Aug 2022 16:21:55 -0500 Subject: [PATCH] init model calibrations --- equipment.py | 4 +- maintenance.py | 73 +++++++++++++++++++++++++++++---- maintenance.xml | 11 ++++- view/maintenance_form.xml | 4 ++ view/optical_equipment_form.xml | 2 + 5 files changed, 84 insertions(+), 10 deletions(-) diff --git a/equipment.py b/equipment.py index 07475e9..70b4e63 100644 --- a/equipment.py +++ b/equipment.py @@ -1,7 +1,7 @@ from collections import defaultdict from trytond.pool import Pool from trytond.model import ( - Workflow, ModelSQL, ModelView, Unique, fields) + DeactivableMixin, Workflow, ModelSQL, ModelView, Unique, fields) from trytond.pyson import Eval, If from trytond.transaction import Transaction from trytond.i18n import gettext @@ -11,7 +11,7 @@ from trytond.exceptions import UserError _MAINTENANCE_FREQUENCY = [("none", ''), ("6", 'Seis Meses'), ("12", 'Doce Meses')] -class OpticalEquipment(Workflow, ModelSQL, ModelView): +class OpticalEquipment(DeactivableMixin, Workflow, ModelSQL, ModelView): 'Optical Equipment' __name__ = 'optical_equipment.equipment' diff --git a/maintenance.py b/maintenance.py index 686feef..fcf6c7c 100644 --- a/maintenance.py +++ b/maintenance.py @@ -3,6 +3,8 @@ from trytond.model import ( from trytond.transaction import Transaction from trytond.pyson import Eval, If + + class Maintenance(Workflow, ModelSQL, ModelView): 'Equipment Maintenance' __name__ = 'optical_equipment.maintenance' @@ -14,11 +16,13 @@ class Maintenance(Workflow, ModelSQL, ModelView): maintenance_type = fields.Selection([('preventive', 'Preventive'), ('corrective', 'Corrective') ], "Maintenance Type") - state = fields.Selection([ - ('draft', "Draft"), - ('agended', "Agended"), - ('in_progress', "In Progress") - ], "State",required=True, readonly=True, sort=False) + + state = fields.Selection([('draft', "Draft"), + ('agended', "Agended"), + ('in_progress', "In Progress"), + ('failed', "Failed"), + ('finished', "Finished") + ], "State",required=True, readonly=True, sort=False) company = fields.Many2One('company.company', "Company", readonly=True) propietary = fields.Many2One('party.party', "Propietary", required=True) @@ -26,7 +30,7 @@ class Maintenance(Workflow, ModelSQL, ModelView): domain=[('party', '=', Eval('propietary'))] ) equipment = fields.Many2One('optical_equipment.equipment', "Equipment", - domain=[]) + domain=[('state', '!=', 'draft')]) #when the maintenance is in agended status @@ -50,7 +54,7 @@ class Maintenance(Workflow, ModelSQL, ModelView): # maintenance_activity = fields.Many2Many('optical_equipment.maintenance-product.product', 'activity', 'maintenance', "Maintenance Activitys") maintenance_lines = fields.One2Many('optical_equipment.maintenance.line', 'maintenance', 'Lines') - + @classmethod def __setup__(cls): super(Maintenance, cls).__setup__() @@ -65,6 +69,7 @@ class Maintenance(Workflow, ModelSQL, ModelView): 'in_progress': {}, 'finished': {}, }) + @staticmethod def default_company(): return Transaction().context.get('company') @@ -73,6 +78,10 @@ class Maintenance(Workflow, ModelSQL, ModelView): def default_state(cls): return 'draft' + @classmethod + def default_maintenance_type(cls): + return 'preventive' + @classmethod def default_state_agended(cls): return 'no_agenda' @@ -101,6 +110,18 @@ class Maintenance(Workflow, ModelSQL, ModelView): def finished(cls, maintenances): pass + @classmethod + def view_attributes(cls): + return super(Maintenance, cls).view_attributes() + [ + ('//page[@id="preventive"]', 'states', { + 'invisible': If(Eval('maintenance_type') != 'preventive', True), + }), + ('//page[@id="corrective"]', 'states',{ + 'invisible': If(Eval('maintenance_type') != 'corrective', True), + }) + ] + + class MaintenanceActivity(ModelSQL): 'Maintenance - Products' __name__ = 'optical_equipment.maintenance-product.product' @@ -120,3 +141,41 @@ class MaintenanceLine(ModelSQL, ModelView): ],) maintenance = fields.Many2One('optical_equipment.maintenance', 'Maintenance', ondelete='CASCADE', select=True) maintenance_activity = fields.Many2One('product.product', 'Maintenance activity') + + +class Calibration(ModelSQL, ModelView): + 'Calibration of Maintenance' + __name__ = 'optical_equipment.maintenance.calibration' + + temperature_min = fields.Float("Temp Min") + temperature_max = fields.Float("Temp Max") + temperature_uom = fields.Many2One('product.uom', 'Temperature UOM', + domain=[('category', '=', Id('optical_equipment', "uom_cat_temperature"))], + states={'invisible' : If(Eval('temperature_min') == None, True)}, + depends=['itemperature_min']) + + moisture_min = fields.Float("Moisture Min") + moisture_max = fields.Float("Moisture Max") + moisture_uom = fields.Many2One('product.uom', "Moisture UOM", + domain=[('category', '=', Id('optical_equipment', 'uom_cat_relative_humedity'))], + states={'invisible' : If(Eval('moisture_min') == None, True)}, + depends=['moisture_min']) + + average = fields.Float("Average") + +class CalibrationSample(sequence_ordered(), ModelView, ModelSQL): + 'Samples of Calibration' + __name__ = 'optical_equipment.maintenance.calibration_sample' + + maintenance = fields.Many2One('optical_equipment.maintenance', 'Maintenance', + ondelete='CASCADE') + ) + number_sample = fields.Integer("Sample #") + value_pattern = fields.Integer("Value in Pattern") + value_equipment = fields.Float("Value in Equipment") + mistake = fields.Floatr("Mistake") + mistake_rate = fields.Float("% Mistake") + expanded_uncertainty = fields.Floats("Uncertainy Expanded") + + + diff --git a/maintenance.xml b/maintenance.xml index 75794b0..6559b38 100644 --- a/maintenance.xml +++ b/maintenance.xml @@ -60,9 +60,18 @@ + + Failed + + + + + Finished - + diff --git a/view/maintenance_form.xml b/view/maintenance_form.xml index d5d8cc8..e51999a 100644 --- a/view/maintenance_form.xml +++ b/view/maintenance_form.xml @@ -44,6 +44,10 @@ + +