~inddiana/sisb/sisb_caja_chica_cierre_comparar_plus_reposiciones

« back to all changes in this revision

Viewing changes to sisb_horas_extras/model/hr_variable_concepts.py

  • Committer: Aryrosa Fuentes
  • Date: 2017-10-20 14:03:01 UTC
  • mfrom: (975.2.9 sisb_061017)
  • Revision ID: afuentes@industriasdiana.gob.ve-20171020140301-8ra8dk3pfi1z841q

[MOD] Ajustes en las limitaciones para la asignación de sobretiempos.
[MOD] Corregida la manera en que se creaba el select del tipo de proceso.
[IMP] Agregado módulo para la carga de permisos.
[IMP] Agregado módulo para la carga automática de conceptos variables que
tengan que ver con los turnos.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from tools.translate import _
24
24
from datetime import datetime
25
25
import logging
 
26
from lxml import etree
 
27
 
26
28
 
27
29
class hr_variable_concepts(osv.osv):
28
30
    """
31
33
    variables
32
34
    """
33
35
    _inherit = 'hr.variable.concepts'
34
 
    _description = 'Variable Concepts'
35
 
 
36
 
    
37
 
    _columns = {
38
 
        'tipo_de_proceso': fields.selection([('sobretiempo','Sobretiempo')], "Tipo de proceso"),
39
 
    }
40
 
        
 
36
 
 
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
 
41
        """
 
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'))
 
46
        else:
 
47
            self._columns['tipo_de_proceso'] = fields.selection([('sobretiempo', 'Sobretiempo')], "Tipo de proceso")
 
48
 
 
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
 
53
        """
 
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']")
 
59
            if not node:
 
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))
 
63
                doc.append(tdp)
 
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', '{}'))
 
67
                if 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':
 
73
                                if o == 'in':
 
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)
 
78
                                break
 
79
                        else:
 
80
                            attrs['readonly'].append(('tipo_de_proceso', 'in', ('sobretiempo',)))
 
81
                    else:
 
82
                        attrs.update({'readonly': [('tipo_de_proceso', 'in', ('sobretiempo',))]})
 
83
                    n.set('attrs', str(attrs))
 
84
                else:
 
85
                    n.set('attrs', "{'readonly': [('tipo_de_proceso', 'in', ('sobretiempo',))]}")
 
86
            view['arch'] = etree.tostring(doc)
 
87
        return view
 
88
 
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')
45
 
        
 
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)
54
103
 
55
104
 
56
 
 
57
105
hr_variable_concepts()
58
106
 
 
107
 
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'
62
111
 
63
112
    def unlink(self, cr, uid, ids, context=None):
64
113
        if not isinstance(ids, list):
65
 
           ids = [ids]
 
114
            ids = [ids]
66
115
        if ids:
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)
72
 
        
73
 
        
74
 
        
75
120
 
76
121
 
77
122
hr_variable_concept_line()
78
 
 
79