From 740aceecc3d067644cefc86651c2a66833e89bc7 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Tue, 26 Apr 2011 17:38:26 +0530 Subject: [PATCH 01/14] [IMP] add help on code field of hr.salary.rule bzr revid: psi@tinyerp.co.in-20110426120826-3uid7tvyfwrj5fjt --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 6757b57c417..16189def579 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -638,7 +638,7 @@ class hr_salary_rule(osv.osv): _name = 'hr.salary.rule' _columns = { 'name':fields.char('Name', size=256, required=True, readonly=False), - 'code':fields.char('Code', size=64, required=True), + 'code':fields.char('Code', size=64, required=True, help="Code is case sensitive."), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), 'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True), 'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."), From ac07145e5ac10eabd2fac907a06639539d1f422a Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 28 Apr 2011 12:01:40 +0530 Subject: [PATCH 02/14] [IMP] hr_payroll: added ir.rule for employee payslip and modified access rights bzr revid: mtr@mtr-20110428063140-rxao7nev4xgzl9f2 --- addons/hr_payroll/security/hr_security.xml | 7 +++++++ addons/hr_payroll/security/ir.model.access.csv | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/hr_payroll/security/hr_security.xml b/addons/hr_payroll/security/hr_security.xml index 339fb1961b9..3c2d84ea089 100644 --- a/addons/hr_payroll/security/hr_security.xml +++ b/addons/hr_payroll/security/hr_security.xml @@ -6,5 +6,12 @@ + + Employee Payslip + + [('employee_id.user_id','=',user.id)] + + + \ No newline at end of file diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index 609fc99c034..d783db77455 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -1,10 +1,10 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,1,1,1 -"access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,1,1,1 -"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,1,1,1 -"access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,1,1,1 -"access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,1,1,1 -"access_res_partner_payroll","res.partner.payroll","base.model_res_partner","base.group_hr_user",1,1,1,1 +"access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,0,0,0 +"access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,0,0,0 +"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,0,0,0 +"access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,0,0,0 +"access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,0,0,0 +"access_hr_payslip_input_user","hr.payslip.input.user","model_hr_payslip_input","base.group_hr_user",1,0,0,0 "access_hr_payslip_manager","hr.payslip.manager","model_hr_payslip","base.group_hr_manager",1,1,1,1 "access_hr_payslip_line_manager","hr.payslip.line.manager","model_hr_payslip_line","base.group_hr_manager",1,1,1,1 "access_hr_payroll_structure_manager","hr.payroll.structure.manager","model_hr_payroll_structure","base.group_hr_manager",1,1,1,1 From 43327d9e9b3e3b22559b787e8de16c5ebe1d17fb Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 28 Apr 2011 14:05:38 +0530 Subject: [PATCH 03/14] [IMP] hr_payroll: 'HR / Officer' can now see the payslips of him and of employess for which he's the manager bzr revid: mtr@mtr-20110428083538-v08g50zk6sx18t4j --- addons/hr_payroll/security/hr_security.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/security/hr_security.xml b/addons/hr_payroll/security/hr_security.xml index 3c2d84ea089..d55f1c81cce 100644 --- a/addons/hr_payroll/security/hr_security.xml +++ b/addons/hr_payroll/security/hr_security.xml @@ -9,7 +9,7 @@ Employee Payslip - [('employee_id.user_id','=',user.id)] + ['|', ('employee_id.user_id', '=', user.id), ('employee_id.department_id.manager_id.user_id', '=', user.id)] From 148b1d45a12789be61ea6e8a731defcaec0a1b7f Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 28 Apr 2011 14:23:11 +0530 Subject: [PATCH 04/14] [IMP] hr_payroll: revert back the changes of access rights,made for hr user bzr revid: mtr@mtr-20110428085311-7017lofdf8jf7s3f --- addons/hr_payroll/security/ir.model.access.csv | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index d783db77455..ba816ea94f8 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -1,10 +1,10 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,0,0,0 -"access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,0,0,0 -"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,0,0,0 -"access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,0,0,0 -"access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,0,0,0 -"access_hr_payslip_input_user","hr.payslip.input.user","model_hr_payslip_input","base.group_hr_user",1,0,0,0 +"access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,1,1,1 +"access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,1,1,1 +"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,1,1,1 +"access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,1,1,1 +"access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,1,1,1 +"access_hr_payslip_input_user","hr.payslip.input.user","model_hr_payslip_input","base.group_hr_user",1,1,1,1 "access_hr_payslip_manager","hr.payslip.manager","model_hr_payslip","base.group_hr_manager",1,1,1,1 "access_hr_payslip_line_manager","hr.payslip.line.manager","model_hr_payslip_line","base.group_hr_manager",1,1,1,1 "access_hr_payroll_structure_manager","hr.payroll.structure.manager","model_hr_payroll_structure","base.group_hr_manager",1,1,1,1 From c44fef652682f9e33c96ad7eef91428a5a545218 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 28 Apr 2011 19:00:56 +0530 Subject: [PATCH 05/14] [IMP] improve the tooltip on code field of hr.salary.rule object bzr revid: psi@tinyerp.co.in-20110428133056-cramofq63y4s9nhy --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 16189def579..11c08db580f 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -638,7 +638,7 @@ class hr_salary_rule(osv.osv): _name = 'hr.salary.rule' _columns = { 'name':fields.char('Name', size=256, required=True, readonly=False), - 'code':fields.char('Code', size=64, required=True, help="Code is case sensitive."), + 'code':fields.char('Code', size=64, required=True, help="The code of salary rules can be used as reference in computation of other rules. In that case, it is case sensitive."), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), 'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True), 'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."), From efdb84c905fb039c305dad8fb62a7097da204a30 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Tue, 3 May 2011 14:42:02 +0530 Subject: [PATCH 06/14] [IMP] Payroll: form and tree view of Salary heads bzr revid: mra@mra-laptop-20110503091202-pmitrzjymkrr3otf --- addons/hr_payroll/hr_payroll_view.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index c4615ce0cc0..40a52a6c74e 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -359,11 +359,12 @@ - + + hr.salary.head.tree hr.salary.head @@ -371,9 +372,9 @@ - - + + From a13984cf7baf0b02f97a1d539f1c7eca94b7f41e Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 4 May 2011 16:43:48 +0530 Subject: [PATCH 07/14] [IMP] remove sequence form salary head object bzr revid: psi@tinyerp.co.in-20110504111348-kngj0i0tert4w9pt --- addons/hr_payroll/hr_payroll.py | 4 +--- addons/hr_payroll/hr_payroll_view.xml | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 132d8fc1104..a8b12327995 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -177,14 +177,12 @@ class hr_salary_head(osv.osv): 'parent_id':fields.many2one('hr.salary.head', 'Parent', help="Linking a salary head to its parent is used only for the reporting purpose."), 'note': fields.text('Description'), 'company_id':fields.many2one('res.company', 'Company', required=False), - 'sequence': fields.integer('Sequence', required=True, help='Display sequence order'), } _defaults = { 'company_id': lambda self, cr, uid, context: \ self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id, - 'sequence': 5 } hr_salary_head() @@ -218,7 +216,7 @@ class hr_payslip(osv.osv): cr.execute('''SELECT pl.slip_id, pl.id FROM hr_payslip_line AS pl \ LEFT JOIN hr_salary_head AS sh on (pl.category_id = sh.id) \ WHERE pl.slip_id in %s \ - GROUP BY pl.slip_id, sh.sequence, pl.sequence, pl.id ORDER BY sh.sequence, pl.sequence''',(tuple(ids),)) + GROUP BY pl.slip_id, pl.sequence, pl.id ORDER BY pl.sequence''',(tuple(ids),)) res = cr.fetchall() for r in res: result.setdefault(r[0], []) diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 40a52a6c74e..53f4eb8c6fb 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -186,8 +186,8 @@ - - + + @@ -249,18 +249,18 @@
- - - - - - + + + + + +
- + @@ -357,7 +357,6 @@ - @@ -373,7 +372,6 @@ - @@ -533,14 +531,14 @@ - + - + From 8666be5ebd2c9314b9c14e02c4d3f0348b86f012 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Mon, 9 May 2011 14:20:02 +0530 Subject: [PATCH 08/14] [IMP] rename object to worked_days and add one object hr.salary.input bzr revid: psi@tinyerp.co.in-20110509085002-l0ygkq5al9yedmz6 --- addons/hr_payroll/hr_payroll.py | 85 +++++++++++++++++-- addons/hr_payroll/hr_payroll_view.xml | 41 ++++++--- .../hr_payroll/security/ir.model.access.csv | 3 +- 3 files changed, 110 insertions(+), 19 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 132d8fc1104..c4dcec2f8bb 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -249,6 +249,7 @@ class hr_payslip(osv.osv): # 'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Line',readonly=True, states={'draft':[('readonly',False)]}), 'company_id': fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}), + 'worked_days_line_ids': fields.one2many('hr.payslip.worked_days', 'payslip_id', 'Payslip Worked Days', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'input_line_ids': fields.one2many('hr.payslip.input', 'payslip_id', 'Payslip Inputs', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'note': fields.text('Description'), @@ -415,7 +416,7 @@ class hr_payslip(osv.osv): self.write(cr, uid, [payslip.id], {'line_ids': lines}, context=context) return True - def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): + def get_worked_day_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): """ @param contract_ids: list of contract id @return: returns a list of dict containing the input that should be applied for the given contract between date_from and date_to @@ -472,6 +473,28 @@ class hr_payslip(osv.osv): res += [attendances] + leaves return res + def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): + res = [] + contract_obj = self.pool.get('hr.contract') + rule_obj = self.pool.get('hr.salary.rule') + + structure_ids = contract_obj.get_all_structures(cr, uid, contract_ids, context=context) + rule_ids = self.pool.get('hr.payroll.structure').get_all_rules(cr, uid, structure_ids, context=context) + sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] + + for contract in contract_obj.browse(cr, uid, contract_ids, context=context): + for rule in rule_obj.browse(cr, uid, sorted_rule_ids, context=context): + if rule.input_ids: + for input in rule.input_ids: + inputs = { + 'name': input.name, + 'sequence': 5, + 'code': input.code, + 'contract_id': contract.id, + } + res += [inputs] + return res + def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): def _sum_salary_head(localdict, head, amount): if head.parent_id: @@ -485,9 +508,12 @@ class hr_payslip(osv.osv): obj_rule = self.pool.get('hr.salary.rule') payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context) worked_days = {} + for worked_days_line in payslip.worked_days_line_ids: + worked_days[worked_days_line.code] = worked_days_line + input_lines = {} for input_line in payslip.input_line_ids: - worked_days[input_line.code] = input_line - localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days} + input_lines[input_line.code] = input_line + localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'input_lines': input_lines} #get the ids of the structures on the contracts and their parent id as well structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) #get the rules of the structure and thier children @@ -545,15 +571,22 @@ class hr_payslip(osv.osv): def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None): empolyee_obj = self.pool.get('hr.employee') contract_obj = self.pool.get('hr.contract') + worked_days_obj = self.pool.get('hr.payslip.worked_days') input_obj = self.pool.get('hr.payslip.input') if context is None: context = {} + #delete old worked days lines + old_worked_days_ids = ids and worked_days_obj.search(cr, uid, [('payslip_id', '=', ids[0])], context=context) or False + if old_worked_days_ids: + worked_days_obj.unlink(cr, uid, old_worked_days_ids, context=context) + #delete old input lines old_input_ids = ids and input_obj.search(cr, uid, [('payslip_id', '=', ids[0])], context=context) or False if old_input_ids: input_obj.unlink(cr, uid, old_input_ids, context=context) + #defaults res = {'value':{ 'line_ids':[], @@ -593,8 +626,10 @@ class hr_payslip(osv.osv): return res #computation of the salary input + worked_days_line_ids = self.get_worked_day_lines(cr, uid, contract_ids, date_from, date_to, context=context) input_line_ids = self.get_input_lines(cr, uid, contract_ids, date_from, date_to, context=context) res['value'].update({ + 'worked_days_line_ids': worked_days_line_ids, 'input_line_ids': input_line_ids, }) return res @@ -614,6 +649,28 @@ class hr_payslip(osv.osv): hr_payslip() +class hr_payslip_worked_days(osv.osv): + ''' + Payslip Worked Days + ''' + + _name = 'hr.payslip.worked_days' + _description = 'Payslip Worked Days' + _columns = { + 'name': fields.char('Description', size=256, required=True), + 'payslip_id': fields.many2one('hr.payslip', 'Pay Slip', required=True), + 'sequence': fields.integer('Sequence', required=True,), + 'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"), + 'number_of_days': fields.float('Number of Days'), + 'number_of_hours': fields.float('Number of Hours'), + 'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"), + } + _order = 'payslip_id, sequence' + _defaults = { + 'sequence': 10, + } +hr_payslip_worked_days() + class hr_payslip_input(osv.osv): ''' Payslip Input @@ -626,13 +683,13 @@ class hr_payslip_input(osv.osv): 'payslip_id': fields.many2one('hr.payslip', 'Pay Slip', required=True), 'sequence': fields.integer('Sequence', required=True,), 'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"), - 'number_of_days': fields.float('Number of Days'), - 'number_of_hours': fields.float('Number of Hours'), + 'quantity': fields.float('Quantity'), 'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"), } - _order = 'payslip_id,sequence' + _order = 'payslip_id, sequence' _defaults = { 'sequence': 10, + 'quantity': 0.0, } hr_payslip_input() @@ -674,6 +731,7 @@ class hr_salary_rule(osv.osv): help="Contribution register based on company", required=False ), + 'input_ids': fields.one2many('hr.rule.input', 'input_id', 'Inputs'), 'note':fields.text('Description'), } _defaults = { @@ -780,6 +838,21 @@ result = rules['NET'] > heads['NET'] * 0.10''', hr_salary_rule() +class hr_rule_input(osv.osv): + ''' + Salary Rule Input + ''' + + _name = 'hr.rule.input' + _description = 'Salary Rule Input' + _columns = { + 'name': fields.char('Description', size=256, required=True), + 'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"), + 'input_id': fields.many2one('hr.salary.rule', 'Salary Rule Input', required=True) + } + +hr_rule_input() + class hr_payslip_line(osv.osv): ''' Payslip Line diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 40a52a6c74e..1b0c8f82e32 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -186,8 +186,8 @@ - - + + @@ -249,18 +249,18 @@
- - - - - - + + + + + +
- + @@ -272,7 +272,7 @@ - + @@ -282,6 +282,15 @@ + + + + + + + + + @@ -533,17 +542,25 @@ - + - + + + + + + + + + diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index 609fc99c034..a5b2ee24201 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -8,5 +8,6 @@ "access_hr_payslip_manager","hr.payslip.manager","model_hr_payslip","base.group_hr_manager",1,1,1,1 "access_hr_payslip_line_manager","hr.payslip.line.manager","model_hr_payslip_line","base.group_hr_manager",1,1,1,1 "access_hr_payroll_structure_manager","hr.payroll.structure.manager","model_hr_payroll_structure","base.group_hr_manager",1,1,1,1 -"access_hr_payslip_input ","hr.payslip.input","model_hr_payslip_input","base.group_hr_manager",1,1,1,1 +"access_hr_payslip_worked_days ","hr.payslip.worked_days","model_hr_payslip_worked_days","base.group_hr_manager",1,1,1,1 "access_hr_salary_rule","hr.salary.rule","model_hr_salary_rule","base.group_hr_manager",1,1,1,1 +"access_hr_payslip_input","hr.payslip.input","model_hr_payslip_input","base.group_hr_manager",1,1,1,1 From c600603f3acd8e650522d9a32644961815d405c2 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Tue, 10 May 2011 16:49:31 +0530 Subject: [PATCH 09/14] [ADD] improve code and add demo rule for sales bzr revid: psi@tinyerp.co.in-20110510111931-4v21peqft66hblpp --- addons/hr_payroll/hr_payroll.py | 15 +- addons/hr_payroll/hr_payroll_demo.xml | 24 ++ addons/hr_payroll/hr_payroll_view.xml | 207 +++++++++++------- .../hr_payroll/security/ir.model.access.csv | 1 + 4 files changed, 156 insertions(+), 91 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index c4dcec2f8bb..2c8f957aa03 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -473,7 +473,7 @@ class hr_payslip(osv.osv): res += [attendances] + leaves return res - def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None): + def get_inputs(self, cr, uid, contract_ids, date_from, date_to, context=None): res = [] contract_obj = self.pool.get('hr.contract') rule_obj = self.pool.get('hr.salary.rule') @@ -488,7 +488,6 @@ class hr_payslip(osv.osv): for input in rule.input_ids: inputs = { 'name': input.name, - 'sequence': 5, 'code': input.code, 'contract_id': contract.id, } @@ -510,10 +509,10 @@ class hr_payslip(osv.osv): worked_days = {} for worked_days_line in payslip.worked_days_line_ids: worked_days[worked_days_line.code] = worked_days_line - input_lines = {} + inputs = {} for input_line in payslip.input_line_ids: - input_lines[input_line.code] = input_line - localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'input_lines': input_lines} + inputs[input_line.code] = input_line + localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs} #get the ids of the structures on the contracts and their parent id as well structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) #get the rules of the structure and thier children @@ -627,7 +626,7 @@ class hr_payslip(osv.osv): #computation of the salary input worked_days_line_ids = self.get_worked_day_lines(cr, uid, contract_ids, date_from, date_to, context=context) - input_line_ids = self.get_input_lines(cr, uid, contract_ids, date_from, date_to, context=context) + input_line_ids = self.get_inputs(cr, uid, contract_ids, date_from, date_to, context=context) res['value'].update({ 'worked_days_line_ids': worked_days_line_ids, 'input_line_ids': input_line_ids, @@ -683,7 +682,7 @@ class hr_payslip_input(osv.osv): 'payslip_id': fields.many2one('hr.payslip', 'Pay Slip', required=True), 'sequence': fields.integer('Sequence', required=True,), 'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"), - 'quantity': fields.float('Quantity'), + 'quantity': fields.float('Quantity', help="It is used in computation. For e.g. A rule for sales having 1% commission of basic salary for per product can defined in expression like result = inputs['S-ASUS']['qunatity']*contract.wage*0.01."), 'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"), } _order = 'payslip_id, sequence' @@ -744,6 +743,7 @@ class hr_salary_rule(osv.osv): # rules: rules code (previously computed) # heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes. # worked_days: dictionary containing the computed worked days. Keys are the worked days codes. +# inputs: dictionary containing the computed inputs. Keys are the inputs codes. # Note: returned value have to be set in the variable 'result' @@ -758,6 +758,7 @@ result = contract.wage * 0.10''', # rules: rules code (previously computed) # heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes. # worked_days: dictionary containing the computed worked days. Keys are the worked days codes. +# inputs: dictionary containing the computed inputs. Keys are the inputs codes. # Note: returned value have to be set in the variable 'result' diff --git a/addons/hr_payroll/hr_payroll_demo.xml b/addons/hr_payroll/hr_payroll_demo.xml index db903fbabfe..5a6ccc2c995 100644 --- a/addons/hr_payroll/hr_payroll_demo.xml +++ b/addons/hr_payroll/hr_payroll_demo.xml @@ -60,6 +60,30 @@ Meal Voucher + + + code + SALE + + Get 1% of sales + + result = (inputs['S-ASUS']['quantity'] + inputs['S-CHINA']['quantity']) * contract.wage * 0.01 + + + + + + S-ASUS + Sale to ASUStek + + + + + S-CHINA + Sale to China Export + + + diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 1b0c8f82e32..7f40b7e7312 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -272,7 +272,7 @@ - + @@ -281,8 +281,19 @@ +
+ + + + + + + + + +
- + @@ -290,6 +301,16 @@ +
+ + + + + + + + +
@@ -499,7 +520,7 @@ - + hr.salary.rule.tree hr.salary.rule tree @@ -513,94 +534,112 @@
- - hr.salary.rule.form + + hr.salary.rule.form + hr.salary.rule + form + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + hr.salary.rule.select hr.salary.rule - form + search -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ + + + + + + + + + + +
-
+
- - hr.salary.rule.select - hr.salary.rule - search - - - - - - - - - - - - - - - + + Salary Rules + hr.salary.rule + form + + [('parent_rule_id','=',False)] + + - - Salary Rules - hr.salary.rule - form - - [('parent_rule_id','=',False)] - - + - + - + + hr.contribution.register.form + hr.contribution.register + form + +
+ + + + + + + + + + +
diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index a5b2ee24201..7f54f1dd50b 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -11,3 +11,4 @@ "access_hr_payslip_worked_days ","hr.payslip.worked_days","model_hr_payslip_worked_days","base.group_hr_manager",1,1,1,1 "access_hr_salary_rule","hr.salary.rule","model_hr_salary_rule","base.group_hr_manager",1,1,1,1 "access_hr_payslip_input","hr.payslip.input","model_hr_payslip_input","base.group_hr_manager",1,1,1,1 +"access_hr_rule_input","hr.rule.input","model_hr_rule_input","base.group_hr_manager",1,1,1,1 From 84739f218e893b52e13f5024fd80ac12aa49062d Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 10 May 2011 17:24:11 +0530 Subject: [PATCH 10/14] [IMP] hr_payroll: renamed salary head into salary category bzr revid: mtr@mtr-20110510115411-lkf923pyakj1ykug --- addons/hr_payroll/hr_payroll.py | 38 +++++++++---------- addons/hr_payroll/hr_payroll_data.xml | 16 ++++---- addons/hr_payroll/hr_payroll_view.xml | 36 +++++++++--------- .../hr_payroll/security/ir.model.access.csv | 2 +- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 132d8fc1104..e4597aa0c8d 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -164,17 +164,17 @@ class contrib_register(osv.osv): contrib_register() -class hr_salary_head(osv.osv): +class hr_salary_category(osv.osv): """ - HR Salary Head + HR Salary Category """ - _name = 'hr.salary.head' - _description = 'Salary Head' + _name = 'hr.salary.category' + _description = 'Salary Category' _columns = { 'name':fields.char('Name', size=64, required=True, readonly=False), 'code':fields.char('Code', size=64, required=True, readonly=False), - 'parent_id':fields.many2one('hr.salary.head', 'Parent', help="Linking a salary head to its parent is used only for the reporting purpose."), + 'parent_id':fields.many2one('hr.salary.category', 'Parent', help="Linking a salary category to its parent is used only for the reporting purpose."), 'note': fields.text('Description'), 'company_id':fields.many2one('res.company', 'Company', required=False), 'sequence': fields.integer('Sequence', required=True, help='Display sequence order'), @@ -187,7 +187,7 @@ class hr_salary_head(osv.osv): 'sequence': 5 } -hr_salary_head() +hr_salary_category() class one2many_mod2(fields.one2many): @@ -212,11 +212,11 @@ class hr_payslip(osv.osv): _name = 'hr.payslip' _description = 'Pay Slip' - def _get_lines_salary_head(self, cr, uid, ids, field_names, arg=None, context=None): + def _get_lines_salary_category(self, cr, uid, ids, field_names, arg=None, context=None): result = {} if not ids: return result cr.execute('''SELECT pl.slip_id, pl.id FROM hr_payslip_line AS pl \ - LEFT JOIN hr_salary_head AS sh on (pl.category_id = sh.id) \ + LEFT JOIN hr_salary_category AS sh on (pl.category_id = sh.id) \ WHERE pl.slip_id in %s \ GROUP BY pl.slip_id, sh.sequence, pl.sequence, pl.id ORDER BY sh.sequence, pl.sequence''',(tuple(ids),)) res = cr.fetchall() @@ -253,7 +253,7 @@ class hr_payslip(osv.osv): 'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'note': fields.text('Description'), 'contract_id': fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}), - 'details_by_salary_head': fields.function(_get_lines_salary_head, method=True, type='one2many', relation='hr.payslip.line', string='Details by Salary Head'), + 'details_by_salary_category': fields.function(_get_lines_salary_category, method=True, type='one2many', relation='hr.payslip.line', string='Details by Salary Head'), 'credit_note': fields.boolean('Credit Note', help="Indicates this payslip has a refund of another"), } _defaults = { @@ -473,10 +473,10 @@ class hr_payslip(osv.osv): return res def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - def _sum_salary_head(localdict, head, amount): - if head.parent_id: - localdict = _sum_salary_head(localdict, head.parent_id, amount) - localdict['heads'][head.code] = head.code in localdict['heads'] and localdict['heads'][head.code] + amount or amount + def _sum_salary_category(localdict, category, amount): + if category.parent_id: + localdict = _sum_salary_category(localdict, category.parent_id, amount) + localdict['categories'][category.code] = category.code in localdict['categories'] and localdict['categories'][category.code] + amount or amount return localdict #we keep a dict with the result because a value can be overwritten by another rule with the same code @@ -487,7 +487,7 @@ class hr_payslip(osv.osv): worked_days = {} for input_line in payslip.input_line_ids: worked_days[input_line.code] = input_line - localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days} + localdict = {'categories': {}, 'payslip': payslip, 'worked_days': worked_days} #get the ids of the structures on the contracts and their parent id as well structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) #get the rules of the structure and thier children @@ -510,7 +510,7 @@ class hr_payslip(osv.osv): #set/overwrite the amount computed for this rule in the localdict localdict[rule.code] = amount #sum the amount for its salary head - localdict = _sum_salary_head(localdict, rule.category_id, amount - previous_amount) + localdict = _sum_salary_category(localdict, rule.category_id, amount - previous_amount) #create/overwrite the rule in the temporary results result_dict[key] = { 'salary_rule_id': rule.id, @@ -644,7 +644,7 @@ class hr_salary_rule(osv.osv): 'code':fields.char('Code', size=64, required=True), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), 'quantity': fields.char('Quantity', size=256, help="It is used in computation for percentage and fixed amount.For e.g. A rule for Meal Voucher having fixed amount of 1€ per worked day can have its quantity defined in expression like worked_days['WORK100']['number_of_days']."), - 'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True), + 'category_id':fields.many2one('hr.salary.category', 'Category', required=True), 'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."), 'appears_on_payslip': fields.boolean('Appears on Payslip', help="Used for the display of rule on payslip"), 'parent_rule_id':fields.many2one('hr.salary.rule', 'Parent Salary Rule', select=True), @@ -684,7 +684,7 @@ class hr_salary_rule(osv.osv): # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes. +# categories: dictionary containing the computed categories (sum of amount of all rules belonging to that category). Keys are the category codes. # worked_days: dictionary containing the computed worked days. Keys are the worked days codes. # Note: returned value have to be set in the variable 'result' @@ -698,12 +698,12 @@ result = contract.wage * 0.10''', # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes. +# categories: dictionary containing the computed categories (sum of amount of all rules belonging to that category). Keys are the category codes. # worked_days: dictionary containing the computed worked days. Keys are the worked days codes. # Note: returned value have to be set in the variable 'result' -result = rules['NET'] > heads['NET'] * 0.10''', +result = rules['NET'] > categories['NET'] * 0.10''', 'condition_range': 'contract.wage', 'sequence': 5, 'appears_on_payslip': True, diff --git a/addons/hr_payroll/hr_payroll_data.xml b/addons/hr_payroll/hr_payroll_data.xml index 21273bfa725..49253ca90b4 100644 --- a/addons/hr_payroll/hr_payroll_data.xml +++ b/addons/hr_payroll/hr_payroll_data.xml @@ -2,32 +2,32 @@ - + Basic BASIC - + Allowance ALW - + Deduction DED - + Gross GROSS - + Net NET - + Company Contribution COMP @@ -177,7 +177,7 @@ none code - result = heads['BASIC'] + ('ALW' in heads and heads['ALW'] or 0.0) + result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0) @@ -187,7 +187,7 @@ none code - result = heads['BASIC'] + ('ALW' in heads and heads['ALW'] or 0.0) + ('DED' in heads and heads['DED'] or 0.0) + result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0) + ('DED' in categories and categories['DED'] or 0.0) diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 40a52a6c74e..1f39afc2462 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -260,8 +260,8 @@
- - + + @@ -347,9 +347,9 @@ - - hr.salary.head.form - hr.salary.head + + hr.salary.category.form + hr.salary.category form
@@ -365,9 +365,9 @@ - - hr.salary.head.tree - hr.salary.head + + hr.salary.category.tree + hr.salary.category tree @@ -379,9 +379,9 @@ - - hr.salary.head.select - hr.salary.head + + hr.salary.category.select + hr.salary.category search @@ -391,16 +391,16 @@ - - Salary Heads - hr.salary.head + + Salary Categories + hr.salary.category form - - + + diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index 609fc99c034..9fe2fd67498 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -1,7 +1,7 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,1,1,1 "access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,1,1,1 -"access_hr_salary_head","hr.salary.head","model_hr_salary_head","base.group_hr_user",1,1,1,1 +"access_hr_salary_category","hr.salary.category","model_hr_salary_category","base.group_hr_user",1,1,1,1 "access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,1,1,1 "access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,1,1,1 "access_res_partner_payroll","res.partner.payroll","base.model_res_partner","base.group_hr_user",1,1,1,1 From 7e28aed3a08f44e58fcf83005f5a29d7c616e2fd Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Tue, 10 May 2011 18:41:10 +0530 Subject: [PATCH 11/14] [FIX] Payroll: Payslip lines readonly with all states of payslips bzr revid: mra@mra-laptop-20110510131110-gd32dkedh7m3gv2i --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 132d8fc1104..6894f32ad5c 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -247,7 +247,7 @@ class hr_payslip(osv.osv): \n* If the salary is paid then state is set to \'Paid Salary\'.\ \n* The \'Reject\' state is used when user cancel payslip.'), # 'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}), - 'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Line',readonly=True, states={'draft':[('readonly',False)]}), + 'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Line',readonly=True), 'company_id': fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'input_line_ids': fields.one2many('hr.payslip.input', 'payslip_id', 'Payslip Inputs', required=False, readonly=True, states={'draft': [('readonly', False)]}), 'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}), From 3eb0031cae88eba3f2443f8f42198cbd8c2b47fc Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Tue, 10 May 2011 19:02:27 +0530 Subject: [PATCH 12/14] [IMP] improve searh view of hr.employee add filter on categories bzr revid: psi@tinyerp.co.in-20110510133227-fzbbptd2tje5suf8 --- addons/hr/hr.py | 6 +++--- addons/hr/hr_view.xml | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index a2c4ee3805b..13db46ccc22 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -142,8 +142,8 @@ class hr_employee(osv.osv): 'work_email': fields.char('Work E-mail', size=240), 'work_location': fields.char('Office Location', size=32), 'notes': fields.text('Notes'), - 'parent_id': fields.many2one('hr.employee', 'Manager'), - 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel', 'emp_id', 'category_id', 'Category'), + 'parent_id': fields.many2one('hr.employee', 'Manager'), + 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel', 'emp_id', 'category_id', 'Categories'), 'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'), 'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True), 'coach_id': fields.many2one('hr.employee', 'Coach'), @@ -231,7 +231,7 @@ class res_users(osv.osv): except: # Tolerate a missing shortcut. See product/product.py for similar code. logging.getLogger('orm').debug('Skipped meetings shortcut for user "%s"', data.get('name',' + @@ -157,12 +158,12 @@ - - Employees - ir.ui.menu - - - + + Employees + ir.ui.menu + + + - - + + @@ -347,9 +347,9 @@ - - hr.salary.category.form - hr.salary.category + + hr.salary.rule.category.form + hr.salary.rule.category form @@ -364,9 +364,9 @@ - - hr.salary.category.tree - hr.salary.category + + hr.salary.rule.category.tree + hr.salary.rule.category tree @@ -377,9 +377,9 @@ - - hr.salary.category.select - hr.salary.category + + hr.salary.rule.category.select + hr.salary.rule.category search @@ -389,16 +389,16 @@ - - Salary Categories - hr.salary.category + + Salary Rule Categories + hr.salary.rule.category form - - + + diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index d91f380cf0e..f1a3a0f4ae4 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -1,7 +1,7 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_hr_payroll_structure","hr.payroll.structure","model_hr_payroll_structure","base.group_hr_user",1,1,1,1 "access_hr_contribution_register","hr.contribution.register","model_hr_contribution_register","base.group_hr_user",1,1,1,1 -"access_hr_salary_category","hr.salary.category","model_hr_salary_category","base.group_hr_user",1,1,1,1 +"access_hr_salary_rule_category","hr.salary.rule.category","model_hr_salary_rule_category","base.group_hr_user",1,1,1,1 "access_hr_payslip","hr.payslip","model_hr_payslip","base.group_hr_user",1,1,1,1 "access_hr_payslip_line","hr.payslip.line","model_hr_payslip_line","base.group_hr_user",1,1,1,1 "access_hr_payslip_input_user","hr.payslip.input.user","model_hr_payslip_input","base.group_hr_user",1,1,1,1 From dad5da0b60eac07686c09d46357d9b1f5f347d18 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Wed, 11 May 2011 19:05:22 +0530 Subject: [PATCH 14/14] [FIX] small fix bzr revid: psi@tinyerp.co.in-20110511133522-8e51br6tsnzs4dao --- addons/hr_payroll/hr_payroll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index b3962cef824..b15cb8ff03a 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -510,7 +510,7 @@ class hr_payslip(osv.osv): inputs = {} for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line - localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs} + localdict = {'categories': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs} #get the ids of the structures on the contracts and their parent id as well structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context) #get the rules of the structure and thier children