~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to hr_payroll/wizard/wizard_create_analytic.py

  • Committer: Mantavya Gajjar
  • Date: 2009-11-23 08:55:16 UTC
  • Revision ID: mga@tinyerp.com-20091123085516-opohxaj3tkacm3kw
[ADD]: a new module for hr management that help to manage salaried

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#-*- coding:utf-8 -*-
 
3
##############################################################################
 
4
#
 
5
#    OpenERP, Open Source Management Solution    
 
6
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
7
#    d$
 
8
#
 
9
#    This program is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, either version 3 of the License, or
 
12
#    (at your option) any later version.
 
13
#
 
14
#    This program is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
import wizard
 
25
import pooler
 
26
 
 
27
class wizard_create_analytics(wizard.interface):
 
28
    '''
 
29
    OpenERP Wizard
 
30
    '''
 
31
    form = '''<?xml version="1.0"?>
 
32
    <form string="Process Form">
 
33
        <field name="company_id"/>
 
34
        <newline/>
 
35
        <field name="type"/>
 
36
    </form>'''
 
37
 
 
38
    fields = {
 
39
        'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company'},
 
40
        'type': {'string':'Type', 'type':'selection', 'selection':[('bydeg','By Employee Function'), ('byallded','By Allownce / Deduction')]}
 
41
    }
 
42
 
 
43
    def _get_defaults(self, cr, user, data, context):
 
44
        #TODO : initlize required data
 
45
        
 
46
        
 
47
        return data['form'] 
 
48
 
 
49
    def _do_duplicate(self, cr, uid, data, context):
 
50
        pool = pooler.get_pool(cr.dbname)
 
51
        account_pool = pool.get('account.analytic.account')
 
52
        func_pool = pool.get('hr.employee.grade')
 
53
        ad_pool = pool.get('hr.allounce.deduction.categoty')
 
54
        
 
55
        tpy = data['form']['type']
 
56
        company = data['form']['company_id']
 
57
        
 
58
        function_ids = func_pool.search(cr, uid, [])
 
59
        ad_ids = ad_pool.search(cr, uid, [])
 
60
        
 
61
        if tpy == 'bydeg':
 
62
            for function in func_pool.browse(cr, uid, function_ids):
 
63
                res = {
 
64
                    'name':function.name,
 
65
                    'company_id':company
 
66
                }
 
67
                fid = account_pool.create(cr, uid, res)
 
68
                res = {
 
69
                    'name':'Basic Salary',
 
70
                    'company_id':company,
 
71
                    'parent_id': fid
 
72
                }
 
73
                account_pool.create(cr, uid, res)
 
74
                for ad in ad_pool.browse(cr, uid, ad_ids):
 
75
                    res = {
 
76
                        'name':ad.name,
 
77
                        'company_id':company,
 
78
                        'parent_id': fid
 
79
                    }
 
80
                    account_pool.create(cr, uid, res)
 
81
                    
 
82
                    
 
83
            
 
84
        elif tpy == 'byallded':
 
85
            res = {
 
86
                'name':'Basic Salary',
 
87
                'company_id':company
 
88
            }
 
89
            adid = account_pool.create(cr, uid, res)
 
90
            for function in func_pool.browse(cr, uid, function_ids):
 
91
                res = {
 
92
                    'name':function.name,
 
93
                    'company_id':company,
 
94
                    'parent_id': adid
 
95
                }
 
96
                account_pool.create(cr, uid, res)
 
97
            
 
98
            for ad in ad_pool.browse(cr, uid, ad_ids):
 
99
                res = {
 
100
                    'name':ad.name,
 
101
                    'company_id':company,
 
102
                }
 
103
                adid = account_pool.create(cr, uid, res)
 
104
                for function in func_pool.browse(cr, uid, function_ids):
 
105
                    res = {
 
106
                        'name':function.name,
 
107
                        'company_id':company,
 
108
                        'parent_id': adid
 
109
                    }
 
110
                    account_pool.create(cr, uid, res)
 
111
            
 
112
        return {}
 
113
    
 
114
    states = {
 
115
        'init': {
 
116
            'actions': [_get_defaults],
 
117
            'result': {'type': 'form', 'arch': form, 'fields': fields, 'state': (('end', 'Cancel'), ('process', 'Process'))},
 
118
        },
 
119
        'process': {
 
120
            'actions': [_do_duplicate],
 
121
            'result': {'type': 'state', 'state': 'end'},
 
122
        },
 
123
    }
 
124
wizard_create_analytics('payroll.analysis')