From 8666be5ebd2c9314b9c14e02c4d3f0348b86f012 Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Mon, 9 May 2011 14:20:02 +0530 Subject: [PATCH 1/2] [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 2/2] [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