~anna-g/micronaet/anna

« back to all changes in this revision

Viewing changes to contract_manage_employee/employee.py

  • Committer: Anna Micronaet
  • Date: 2013-07-18 09:08:36 UTC
  • Revision ID: anna@micronaet.it-20130718090836-ssmst48rrnvcd69w
Tolti tutti i moduli

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP module
5
 
#    Copyright (C) 2010 Micronaet srl (<http://www.micronaet.it>) 
6
 
#    
7
 
#    Italian OpenERP Community (<http://www.openerp-italia.com>)
8
 
#
9
 
#############################################################################
10
 
#
11
 
#    OpenERP, Open Source Management Solution   
12
 
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
13
 
#    $Id$
14
 
#
15
 
#    This program is free software: you can redistribute it and/or modify
16
 
#    it under the terms of the GNU General Public License as published by
17
 
#    the Free Software Foundation, either version 3 of the License, or
18
 
#    (at your option) any later version.
19
 
#
20
 
#    This program is distributed in the hope that it will be useful,
21
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 
#    GNU General Public License for more details.
24
 
#
25
 
#    You should have received a copy of the GNU General Public License
26
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 
#
28
 
##############################################################################
29
 
 
30
 
from osv import osv, fields
31
 
import time 
32
 
from tools.translate import _
33
 
 
34
 
week_days = [('mo','Monday'),  # python represent weekday starting from 0 = Monday
35
 
             ('tu','Tuesday'),     
36
 
             ('we','Wednesday'),     
37
 
             ('th','Thursday'),     
38
 
             ('fr','Friday'),     
39
 
             ('sa','Saturday'),     
40
 
             ('su','Sunday'),]
41
 
             
42
 
class contract_employee_timesheet_tipology(osv.osv):
43
 
    ''' Contract tipology: contains a list of "day of a week" elements and the
44
 
        total amount of hour to be worked that day
45
 
    '''
46
 
    
47
 
    _name = 'contract.employee.timesheet.tipology'
48
 
    _description = 'Timesheet tipology'
49
 
    
50
 
    _columns = {
51
 
        'name':fields.char('Description', size=64, required=False, readonly=False),
52
 
    }
53
 
contract_employee_timesheet_tipology()
54
 
 
55
 
class contract_employee_timesheet_tipology_line(osv.osv):
56
 
    ''' Sub element of contract tipology: contains dow and tot. hours
57
 
    '''
58
 
    
59
 
    _name = 'contract.employee.timesheet.tipology.line'
60
 
    _description = 'Timesheet tipology line'
61
 
    
62
 
    _columns = {
63
 
        'name': fields.float('Tot. hours', required=True, digits=(4, 2)),
64
 
        'week_day':fields.selection(week_days,'Week day', select=True, readonly=False),
65
 
        'contract_tipology_id':fields.many2one('contract.employee.timesheet.tipology', 'Contract tipology', required=True, ondelete='cascade'),
66
 
    }
67
 
contract_employee_timesheet_tipology_line()
68
 
 
69
 
class contract_employee_timesheet_tipology(osv.osv):
70
 
    ''' Contract tipology: add relation 2many fields
71
 
    '''
72
 
    
73
 
    _name = 'contract.employee.timesheet.tipology'
74
 
    _inherit = 'contract.employee.timesheet.tipology'
75
 
 
76
 
    _columns = {
77
 
        'line_ids':fields.one2many('contract.employee.timesheet.tipology.line', 'contract_tipology_id', 'Lines', required=False),
78
 
    }
79
 
contract_employee_timesheet_tipology()
80
 
 
81
 
class contract_employee_festivity(osv.osv):
82
 
    ''' Festivity manage: 
83
 
        manage static festivity (also with from-to period)
84
 
        manage dynamic list of festivity (ex. Easter monday)
85
 
    '''
86
 
    
87
 
    _name = 'contract.employee.festivity'
88
 
    _description = 'Contract festivity'
89
 
    
90
 
    import time
91
 
    # TODO: function for compute festivity
92
 
    # TODO: function for validate: 
93
 
    #       static date (max day for day-month)
94
 
    #       from to period evaluation (no interference)
95
 
    #       no double comment in dynamic date (2 Easter monday for ex. in the same year)
96
 
    
97
 
    def is_festivity(self, cr, uid, date, context=None):
98
 
        ''' Test if datetime element date is in festifity rules
99
 
        '''
100
 
        # Static festivity (periodic):
101
 
        date_ids = self.search(cr, uid, [('static','=',True), 
102
 
                                         ('periodic','=',True), 
103
 
                                         ('day','=',date.day),
104
 
                                         ('month','=',date.month),
105
 
                                         ('periodic_from','>=',date.year),
106
 
                                         ('periodic_to','<=',date.year),
107
 
                                        ]) 
108
 
        if date_ids:
109
 
            return True
110
 
 
111
 
        # Static festivity not periodic:
112
 
        date_ids = self.search(cr, uid, [('static','=',True), 
113
 
                                         ('periodic','=',False), 
114
 
                                         ('day','=',date.day),
115
 
                                         ('month','=',date.month),
116
 
                                        ]) 
117
 
        if date_ids:
118
 
            return True
119
 
 
120
 
        # Dinamic festivity:
121
 
        date_ids = self.search(cr, uid, [('static','=',False), 
122
 
                                         ('dynamic_date','=',date.strftime("%Y-%m-%d")),
123
 
                                         ])
124
 
        if date_ids:
125
 
            return True
126
 
        
127
 
        return False
128
 
    
129
 
    _columns = {
130
 
        'name':fields.char('Description', size=64, required=False, readonly=False),
131
 
 
132
 
        # static festivity:
133
 
        'static':fields.boolean('Static festivity', help="It means that every year this festivity is the same day (ex. Christmas = 25 of dec.), if not it's dynamic (ex. Easter monday)"),
134
 
        'day': fields.integer('Static day'),
135
 
        'month': fields.integer('Static month'),
136
 
        # static but periodic:
137
 
        'periodic':fields.boolean('Periodic festivity', help="Festivity is only for a from-to period (ex.: Patronal festivity but for a period because of changing city)"),
138
 
        'periodic_from': fields.integer('From year'),
139
 
        'periodic_to': fields.integer('To year'),
140
 
        
141
 
        # dinamic festivity (no periodic is allowed):
142
 
        'dynamic_date': fields.date('Dynamic Date'),
143
 
    }
144
 
    
145
 
    _defaults = {
146
 
        'periodic_from': lambda *a: time.strftime('%Y'),
147
 
        'periodic_to': lambda *a: time.strftime('%Y'),
148
 
    }
149
 
contract_employee_festivity()
150
 
 
151
 
class hr_employee_extra(osv.osv):
152
 
    """ Employee extra fields for manage contract and working hours
153
 
        TODO: create a list of working hour contract (for history of elements)
154
 
    """    
155
 
    _inherit = 'hr.employee'
156
 
    _name = 'hr.employee'
157
 
    
158
 
    def check_consistency_employee_user_department(self, cr, uid, context=None):
159
 
        ''' Procedure for xml-rpc call for check consistency of DB
160
 
            1. check if employee has user linked
161
 
            2. check if 
162
 
        '''
163
 
        #TODO finirla
164
 
        user_pool = self.pool.get("res.users")
165
 
        employee_proxy=self.browse(cr, uid, self.search(cr, uid, [], context=context))
166
 
        
167
 
        for employee in employee_proxy:
168
 
            if employee.user_id and employee.department_id:                
169
 
                update=user_pool.write(cr, uid, employee.user_id.id, {'context_department_id': employee.department_id.id})
170
 
                
171
 
        return True
172
 
        
173
 
    _columns = {
174
 
        'contract_tipology_id':fields.many2one('contract.employee.timesheet.tipology', 'Work time', required=False, help="Working time for this employee, tipically a contract tipology, like: full time, part time etc. (for manage hour and presence)"),
175
 
    }
176
 
hr_employee_extra()
177
 
 
178
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: