33
35
_inherit = 'hr.variable.concepts'
34
_description = 'Variable Concepts'
38
'tipo_de_proceso': fields.selection([('sobretiempo','Sobretiempo')], "Tipo de proceso"),
37
def __init__(self, *args, **kargs):
38
""" Corregida la manera en que se agregaba el campo 'tipo_de_proceso', para que
39
se tome en cuenta si ya existe y se deba agregar el tipo al selection, o si
40
se debe crear por primera vez
42
super(hr_variable_concepts, self).__init__(*args, **kargs)
43
if 'tipo_de_proceso' in self._columns:
44
if ('sobretiempo', 'Sobretiempo') not in self._columns['tipo_de_proceso'].selection:
45
self._columns['tipo_de_proceso'].selection.append(('sobretiempo', 'Sobretiempo'))
47
self._columns['tipo_de_proceso'] = fields.selection([('sobretiempo', 'Sobretiempo')], "Tipo de proceso")
49
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
50
""" Se sobrecarga el metodo fields_view_get para hacer solo-lectura todos los campos en la vista de
51
formulario de los conceptos variables cuando el tipo de proceso sea de sobretiempo. Se hace de
52
esta forma para tomar en cuenta cuando otros modulos alteran los atributos 'readonly' de esta vista
54
view = super(hr_variable_concepts, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
55
if view_type == 'form':
56
doc = etree.XML(view['arch'])
57
# In case 'tipo_de_proceso' field is not in the view, add it to compare it
58
node = doc.xpath("//field[@name='tipo_de_proceso']")
60
tdp = etree.Element('field', name='tipo_de_proceso', invisible="1")
61
if 'tipo_de_proceso' not in view['fields']:
62
view['fields'].update(self.pool.get('hr.variable.concepts').fields_get(cr, uid, fields=['tipo_de_proceso'], context=context))
64
# Now, we must iterate all fields to set them all readonly
65
for n in doc.xpath("//field"):
66
attrs = eval(n.get('attrs', '{}'))
68
if 'readonly' in attrs:
69
attrs['readonly'].insert(0, '|')
70
for i, d in enumerate(attrs['readonly']):
71
f, o, v = d if type(d) == tuple else False, False, False
72
if f == 'tipo_de_proceso':
74
v = v + ['sobretiempo'] if type(v) == list else v + ('sobretiempo',)
75
else: # assuming '=' is the operator, 'not in' or another operator should not be used
76
o, v = 'in', ['sobretiempo', v]
77
attrs['readonly'][i] = (f, v, o)
80
attrs['readonly'].append(('tipo_de_proceso', 'in', ('sobretiempo',)))
82
attrs.update({'readonly': [('tipo_de_proceso', 'in', ('sobretiempo',))]})
83
n.set('attrs', str(attrs))
85
n.set('attrs', "{'readonly': [('tipo_de_proceso', 'in', ('sobretiempo',))]}")
86
view['arch'] = etree.tostring(doc)
41
89
def unlink(self, cr, uid, ids, context=None):
42
90
brw = self.browse(cr, uid, ids[0])
43
91
horas_extras_obj = self.pool.get('horas.extras.planificacion')
44
92
variables_lines_obj = self.pool.get('hr.variable.concept.line')
93
context = {} if context is None else context
46
94
if brw.tipo_de_proceso == 'sobretiempo':
47
if brw.state not in ['done', 'execute']:
48
context.update({"eliminar_sobretiempo":True})
49
horas_extras_id = horas_extras_obj.search(cr, uid, [('variable_concept_id','in',ids)])
50
horas_extras_obj.write(cr, uid, horas_extras_id, {'state':'processing', 'variable_concept_id':False})
51
lines = [i.id for i in brw.variable_concept_line_ids]
52
variables_lines_obj.unlink(cr, uid, lines, context=context)
95
if brw.state not in ['done', 'execute']:
96
context.update({"eliminar_sobretiempo": True})
97
horas_extras_id = horas_extras_obj.search(cr, uid, [('variable_concept_id', 'in', ids)])
98
horas_extras_obj.write(cr, uid, horas_extras_id, {'state': 'processing', 'variable_concept_id': False})
99
horas_extras_obj.write_state_lines(cr, uid, horas_extras_id, 'processing')
100
lines = [i.id for i in brw.variable_concept_line_ids]
101
variables_lines_obj.unlink(cr, uid, lines, context=context)
53
102
return super(hr_variable_concepts, self).unlink(cr, uid, ids)
57
105
hr_variable_concepts()
59
108
class hr_variable_concept_line(osv.osv):
60
_inherit = 'hr.variable.concept.line'
109
_inherit = 'hr.variable.concept.line'
61
110
_description = 'Variable Concept Lines'
63
112
def unlink(self, cr, uid, ids, context=None):
64
113
if not isinstance(ids, list):
67
116
brw = self.browse(cr, uid, ids[0])
68
117
if brw.variable_concept_id.tipo_de_proceso == 'sobretiempo' and not context.get('eliminar_sobretiempo', False):
69
raise osv.except_osv(_('ERROR!'), _("""No se pueden borrar
70
las lineas de conceptos variables tipo %s """ %(brw.variable_concept_id.tipo_de_proceso)))
118
raise osv.except_osv(_('ERROR!'), _("No se pueden borrar las lineas de conceptos variables tipo %s " % (brw.variable_concept_id.tipo_de_proceso)))
71
119
return super(hr_variable_concept_line, self).unlink(cr, uid, ids, context=context)
77
122
hr_variable_concept_line()