trytondo-optical_equipment/equipment.py

81 lines
3.2 KiB
Python

from collections import defaultdict
from trytond.pool import Pool
from trytond.model import ModelSQL, ModelView, Unique, fields
from trytond.pyson import Eval
from trytond.exceptions import UserError
class OpticalEquipment(ModelSQL, ModelView):
'Optical Equipment'
__name__ = 'optical_equipment.equipment'
code_readinly = fields.Function(
fields.Boolean("Code Readonly"), 'get_code_readonly')
code = fields.Char(
"Code", select=True,states={
'readonly': Eval('code_readonly', False),
})
company = fields.Many2One('company.company', "Company")
location = fields.Many2One('stock.location', "Location")
propietary = fields.Many2One('party.party', "Propietary")
propietary_address = fields.Many2One('party.address', "Propietary Address", required=True)
product = fields.Many2One('product.product', "Product")
refurbish = fields.Boolean("Refurbish", readonly=True)
equipment_type = fields.Char('type', readonly=True)
risk = fields.Char('Type risk')
use = fields.Char('Use')
biomedical_class = fields.Char('Biomedical Class')
main_tecnology = fields.Char('Main tecnology')
calibration = fields.Boolean("Apply calibration", readonly=True)
mark_category = fields.Many2One('product.category', 'Mark', required=True,
domain=[('parent', '=', None),
('accounting', '=', False)],
)
model_category = fields.Many2One('product.category', "Model", required=True,
domain=[('parent', '=', Eval('mark_category')),
('accounting', '=', False)],)
reference = fields.Char("Reference", size=None)
origin_country = fields.Many2One('country.country',"Origin Country")
software_version = fields.Char("Software version", size=None)
useful_life = fields.Integer("Useful life")
warranty = fields.Integer("Warranty")
serial = fields.Char("Serial", size=None)
health_register = fields.Char("Health Register", size=None)
subscription_history = fields.Many2Many('sale.subscription-optical_equipment.equipment',
'equipment','subscription', "Subscriptions",
states={'readonly': True})
current_subscription = fields.Many2One('sale.subscription')
@staticmethod
def get_origin():
return None
@classmethod
def __setup__(cls):
super(OpticalEquipment, cls).__setup__()
t = cls.__table__()
cls._sql_constraints = [
('serial_unique', Unique(t, t.serial),
'optical_equipment.msg_serial_unique')
]
def default_code_readonly(cls):
pool = Pool()
Configuration = pool.get('optical_equipment.configuration')
config = Configuration(1)
return bool(config.equipment_sequence)
def get_code_readonly(self, name):
return self.default_code_readonly()
@classmethod
def _new_code(cls):
pool = Pool()
Configuration = pool.get('optical_equipment.configuration')
config = Configuration(1)
sequence = config.equipment_sequence
if sequence:
return sequence.get()