108 lines
4.0 KiB
Python
108 lines
4.0 KiB
Python
from collections import defaultdict
|
|
from trytond.pool import Pool
|
|
from trytond.model import (
|
|
Workflow, ModelSQL, ModelView, Unique, fields)
|
|
from trytond.pyson import Eval, If
|
|
from trytond.exceptions import UserError
|
|
|
|
class OpticalEquipment(Workflow, ModelSQL, ModelView):
|
|
'Optical Equipment'
|
|
__name__ = 'optical_equipment.equipment'
|
|
|
|
|
|
code = fields.Char(
|
|
"Code", select=True,states={'readonly': True })
|
|
|
|
state = fields.Selection([
|
|
('draft', "Draft"),
|
|
('registred', "Registred"),
|
|
('contrated', "Contrated")
|
|
], "State",
|
|
required=True, readonly=True, sort=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')
|
|
|
|
@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')
|
|
]
|
|
cls._transitions = ({
|
|
('draft', 'registred'),
|
|
('registred', 'contrated'),
|
|
})
|
|
cls._buttons.update({
|
|
'draft': {
|
|
'invisible': Eval('state') == 'draft'},
|
|
'registred': {
|
|
'invisible': Eval('state').in_(['registred', 'contrated'])}}
|
|
)
|
|
|
|
@classmethod
|
|
def set_code(cls, equipments):
|
|
pool = Pool()
|
|
Config = pool.get('optical_equipment.configuration')
|
|
config = Config(1)
|
|
for equipment in equipments:
|
|
if not equipment.code:
|
|
try:
|
|
equipment.code = config.equipment_sequence.get()
|
|
equipment.state = 'registred'
|
|
cls.save(equipments) #Revisar
|
|
except UserError:
|
|
raise UserError(str('Validation Error'))
|
|
|
|
@classmethod
|
|
def default_state(cls):
|
|
return 'draft'
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('draft')
|
|
def draft(cls, equipments):
|
|
pass
|
|
#raise userError(str('draft'))
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('registred')
|
|
def registred(cls, equipments):
|
|
#raise UserError(str(equipments))
|
|
cls.set_code(equipments)
|
|
#state = 'registred'
|
|
|