~hr-core-editors/openerp-hr/6.1

« back to all changes in this revision

Viewing changes to hr_holidays_request/wizard/hr_holiday.py

[MRG] 6.1-modules-from-other-projects (hr_skill kept unchanged on conflict resolution)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#    
 
2
#
 
3
#
4
4
#    OpenERP, Open Source Management Solution
5
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6
6
#
15
15
#    GNU Affero General Public License for more details.
16
16
#
17
17
#    You should have received a copy of the GNU Affero General Public License
18
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19
 
#
20
 
##############################################################################
 
18
#    along with this program. If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
#
 
21
 
 
22
from osv import osv
21
23
import time
22
 
import wizard
23
24
import datetime
 
25
 
24
26
error = '''<?xml version="1.0"?>
25
27
<form string="Select period">
26
28
    <label string="Error in Data !!"/>
50
52
            <field name="todate"/>
51
53
            </group>
52
54
</form>'''
 
55
 
 
56
 
53
57
def _get_months(sel, cr, uid, context):
54
 
    i=0
55
 
    res=[]
56
 
    while i<12:
57
 
        t=()
58
 
        t=(i+1,i+1)
 
58
    i = 0
 
59
    res = []
 
60
    while i < 12:
 
61
        t = ()
 
62
        t = (i + 1, i + 1)
59
63
        res.append(t)
60
 
        i+=1
 
64
        i += 1
61
65
    return res
 
66
 
62
67
field1 = {
63
 
    'emp_ids': {'string':'Employees', 'type':'many2many', 'relation':'hr.employee'},
64
 
    'month': {'string':'Month','type':'selection', 'selection':_get_months},
65
 
    'year':{'string':'Year','type':'integer'},
66
 
    'fromdate': {'string':'From', 'type':'date'},
67
 
    'todate': {'string':'To', 'type':'date'},
68
 
    'active1':{'string':'Month Wise','type':'boolean'},
69
 
    'active2':{'string':'Date Wise','type':'boolean'}
 
68
    'emp_ids': {'string': 'Employees', 'type': 'many2many', 'relation': 'hr.employee'},
 
69
    'month': {'string': 'Month', 'type': 'selection', 'selection': _get_months},
 
70
    'year': {'string': 'Year', 'type': 'integer'},
 
71
    'fromdate': {'string': 'From', 'type': 'date'},
 
72
    'todate': {'string': 'To', 'type': 'date'},
 
73
    'active1': {'string': 'Month Wise', 'type': 'boolean'},
 
74
    'active2': {'string': 'Date Wise', 'type': 'boolean'}
70
75
}
71
76
 
72
77
 
73
 
class hr_holidays_report(wizard.interface):
 
78
class hr_holidays_report(osv.osv_memory):
 
79
 
74
80
    def year_get(self, cr, uid, data, context):
75
 
       p=int(time.strftime('%Y'))
76
 
       return {'year':p}
77
 
    def _riase_error(self, cr, uid, data, context):
78
 
        form=data['form']
79
 
        if not form['emp_ids'][0][2] :
80
 
            raise wizard.except_wizard('Error', 'You must select Employee(s) For report !')
81
 
        
 
81
        p = int(time.strftime('%Y'))
 
82
        return {'year': p}
 
83
 
 
84
    def _raise_error(self, cr, uid, data, context):
 
85
        form = data['form']
 
86
        if not form['emp_ids'][0][2]:
 
87
            raise osv.except_osv(
 
88
                'Error', 'You must select Employee(s) for report !')
82
89
        if form['active1'] and form['active2']:
83
 
            raise wizard.except_wizard('TyepError', 'You must select only one type For report !')
 
90
            raise osv.except_osv(
 
91
                'TyepError', 'You must select only one type for report !')
84
92
        if form['active1']:
85
 
            temp=form['year']
 
93
            temp = form['year']
86
94
            if not form['month']:
87
 
                raise wizard.except_wizard('MonthError', 'You must select month For month-wise report !')
88
 
            
89
 
                
 
95
                raise osv.except_osv(
 
96
                    'MonthError', 'You must select month for month-wise report !')
90
97
        elif form['active2']:
91
 
            temp=0
 
98
            temp = 0
92
99
            if not form['fromdate'] or not form['todate']:
93
 
                raise wizard.except_wizard('DateError', 'You must select Dates For date-wise report !')
 
100
                raise osv.except_osv(
 
101
                    'DateError', 'You must select Dates for date-wise report !')
94
102
            else:
95
 
                d=form['fromdate']
96
 
                dd=form['todate']
97
 
                d1=d.split('-')
98
 
                d2=dd.split('-')
99
 
                d1[2]=d1[2].split(' ')
100
 
                d2[2]=d2[2].split(' ')
101
 
                a=datetime.date(int(d1[0]),int(d1[1]),int(d1[2][0]))
102
 
                b=datetime.date(int(d2[0]),int(d2[1]),int(d2[2][0]))
103
 
                if  a>b :
104
 
                    raise wizard.except_wizard('DateError', 'You must select Dates proparly !')
 
103
                d = form['fromdate']
 
104
                dd = form['todate']
 
105
                d1 = d.split('-')
 
106
                d2 = dd.split('-')
 
107
                d1[2] = d1[2].split(' ')
 
108
                d2[2] = d2[2].split(' ')
 
109
                a = datetime.date(int(d1[0]), int(d1[1]), int(d1[2][0]))
 
110
                b = datetime.date(int(d2[0]), int(d2[1]), int(d2[2][0]))
 
111
                if a > b:
 
112
                    raise osv.except_osv(
 
113
                        'DateError', 'You must select Dates properly !')
105
114
        else:
106
 
            raise wizard.except_wizard('typeError', 'You must select Type !')
107
 
        return {'year':temp}
 
115
            raise osv.except_osv('typeError', 'You must select Type !')
 
116
        return {'year': temp}
108
117
    states = {
109
118
        'init': {
110
119
            'actions': [year_get],
111
 
            'result': {'type':'form', 'arch':form1, 'fields':field1,  'state' : [('print', 'Ok'),('end', 'Cancel')]}
 
120
            'result': {'type': 'form', 'arch': form1, 'fields': field1, 'state': [('print', 'Ok'), ('end', 'Cancel')]}
112
121
        },
113
 
         'print': {
114
 
            'actions': [_riase_error],
115
 
            'result': {'type':'print', 'report':'hr.holiday.req.report','state':'end'}
 
122
        'print': {
 
123
            'actions': [_raise_error],
 
124
            'result': {'type': 'print', 'report': 'hr.holiday.req.report', 'state': 'end'}
116
125
        }
117
 
        
118
126
    }
119
127
hr_holidays_report('hr_holiday_req')
 
128
 
120
129
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
121