sequence in equipments
This commit is contained in:
parent
0fe894d10f
commit
ffaed5fe49
49
equipment.py
49
equipment.py
@ -2,15 +2,13 @@ from collections import defaultdict
|
||||
from trytond.pool import Pool
|
||||
from trytond.model import (
|
||||
Workflow, ModelSQL, ModelView, Unique, fields)
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
class OpticalEquipment(Workflow, ModelSQL, ModelView):
|
||||
'Optical Equipment'
|
||||
__name__ = 'optical_equipment.equipment'
|
||||
|
||||
code_readonly = fields.Function(
|
||||
fields.Boolean("Code Readonly"), 'get_code_readonly')
|
||||
|
||||
code = fields.Char(
|
||||
"Code", select=True,states={'readonly': True })
|
||||
@ -55,10 +53,6 @@ class OpticalEquipment(Workflow, ModelSQL, ModelView):
|
||||
|
||||
current_subscription = fields.Many2One('sale.subscription')
|
||||
|
||||
@staticmethod
|
||||
def get_origin():
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(OpticalEquipment, cls).__setup__()
|
||||
@ -72,32 +66,30 @@ class OpticalEquipment(Workflow, ModelSQL, ModelView):
|
||||
('registred', 'contrated'),
|
||||
})
|
||||
cls._buttons.update({
|
||||
'draft': {},
|
||||
'registred': {}})
|
||||
'draft': {
|
||||
'invisible': Eval('state') == 'draft'},
|
||||
'registred': {
|
||||
'invisible': Eval('state').in_(['registred', 'contrated'])}}
|
||||
)
|
||||
|
||||
|
||||
def default_code_readonly(cls):
|
||||
@classmethod
|
||||
def set_code(cls, equipments):
|
||||
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()
|
||||
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
|
||||
def _new_code(cls):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('optical_equipment.configuration')
|
||||
config = Configuration(1)
|
||||
sequence = config.equipment_sequence
|
||||
if sequence:
|
||||
return sequence.get()
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('draft')
|
||||
@ -109,4 +101,7 @@ class OpticalEquipment(Workflow, ModelSQL, ModelView):
|
||||
@ModelView.button
|
||||
@Workflow.transition('registred')
|
||||
def registred(cls, equipments):
|
||||
pass
|
||||
#raise UserError(str(equipments))
|
||||
cls.set_code(equipments)
|
||||
#state = 'registred'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user