From f08332648b60259534c20b77658834c0f9f7cd37 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 28 Mar 2011 17:18:14 +0530 Subject: [PATCH 1/6] [IMP] hr_payroll:created a method for three function fields. bzr revid: mtr@mtr-20110328114814-70tl4ls5j36ztu9c --- addons/hr_payroll/hr_payroll.py | 67 +++++++++++---------------- addons/hr_payroll/hr_payroll_view.xml | 5 +- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 9b390691c33..30ffe8d6fde 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -475,15 +475,16 @@ class hr_payslip(osv.osv): parent = self._get_parent_structure(cr, uid, parent, context) return struct_id + parent - def _applied_salary_rule(self, cr, uid, ids, field_names, arg=None, context=None): + def _get_salary_rules(self, cr, uid, ids, field_names, arg=None, context=None): structure_obj = self.pool.get('hr.payroll.structure') - result = {} + res = {} + sal_structure = [] + lines = [] + rules = [] + rul = [] for record in self.browse(cr, uid, ids, context=context): function = record.struct_id.id - sal_structure = [] - lines = [] - rules = [] - rule = [] + res[record.id] = {} if function: sal_structure = self._get_parent_structure(cr, uid, [function], context=context) for struct in sal_structure: @@ -493,37 +494,25 @@ class hr_payslip(osv.osv): for r in rl.child_ids: lines.append(r) rules.append(rl) - for r in rules: - if r.id not in rule: - rule.append(r.id) - result[record.id] = rule - return result - - def _appears_on_payslip_rule(self, cr, uid, ids, field_names, arg=None, context=None): - struct_obj = self.pool.get('hr.payroll.structure') - result = {} - for record in self.browse(cr, uid, ids, context=context): - structure = record.struct_id.id - sal_struct = [] - lines = [] - rules = [] - rule = [] - if structure: - sal_struct = self._get_parent_structure(cr, uid, [structure], context=context) - for struct in sal_struct: - lines = struct_obj.browse(cr, uid, struct, context=context).rule_ids - for rl in lines: - if rl.child_ids: - for r in rl.child_ids: - lines.append(r) - rules.append(rl) - for r in rules: + for fn in field_names: + if fn == 'applied_salary_rule': + for r in rules: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + elif fn == 'appears_on_payslip_rule': + for r in rules: if r.appears_on_payslip: - if r.id not in rule: - rule.append(r.id) - result[record.id] = rule - return result - + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + elif fn == 'details_by_salary_head': + for r in rules: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + return res + def _compute(self, cr, uid, id, value, context=None): rule_obj = self.pool.get('hr.salary.rule') contrib = rule_obj.browse(cr, uid, id, context=context) @@ -569,9 +558,9 @@ class hr_payslip(osv.osv): 'igross': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'inet': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'holiday_ids': fields.function(_get_holidays, method=True, type='one2many', relation='hr.holidays', string='Holiday Lines', required=False), - 'applied_salary_rule': fields.function(_applied_salary_rule, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', required=False), - 'appears_on_payslip_rule': fields.function(_appears_on_payslip_rule, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', required=False), -# 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head'), + 'applied_salary_rule': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', multi='applied_salary_rule'), + 'appears_on_payslip_rule': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', multi='appears_on_payslip_rule'), + 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head', multi='details_by_salary_head'), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 3926c9bb19d..e7a51a4ae64 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -287,10 +287,11 @@ - + - + + From 8eaf9ae4a5afda5e5731c5acd658c84729e374d0 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 28 Mar 2011 18:02:41 +0530 Subject: [PATCH 2/6] [IMP] hr_payroll:created a method for three function fields. bzr revid: mtr@mtr-20110328123241-m0tul6jysd4cr2k8 --- addons/hr_payroll/hr_payroll.py | 65 +++++++++++---------------- addons/hr_payroll/hr_payroll_view.xml | 7 +-- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 55cadd1efc9..926e7723685 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -475,15 +475,16 @@ class hr_payslip(osv.osv): parent = self._get_parent_structure(cr, uid, parent, context) return struct_id + parent - def _applied_salary_rule(self, cr, uid, ids, field_names, arg=None, context=None): + def _get_salary_rules(self, cr, uid, ids, field_names, arg=None, context=None): structure_obj = self.pool.get('hr.payroll.structure') - result = {} + res = {} + sal_structure = [] + lines = [] + rules = [] + rul = [] for record in self.browse(cr, uid, ids, context=context): function = record.struct_id.id - sal_structure = [] - lines = [] - rules = [] - rule = [] + res[record.id] = {} if function: sal_structure = self._get_parent_structure(cr, uid, [function], context=context) for struct in sal_structure: @@ -493,36 +494,24 @@ class hr_payslip(osv.osv): for r in rl.child_ids: lines.append(r) rules.append(rl) - for r in rules: - if r.id not in rule: - rule.append(r.id) - result[record.id] = rule - return result - - def _appears_on_payslip_rule(self, cr, uid, ids, field_names, arg=None, context=None): - struct_obj = self.pool.get('hr.payroll.structure') - result = {} - for record in self.browse(cr, uid, ids, context=context): - structure = record.struct_id.id - sal_struct = [] - lines = [] - rules = [] - rule = [] - if structure: - sal_struct = self._get_parent_structure(cr, uid, [structure], context=context) - for struct in sal_struct: - lines = struct_obj.browse(cr, uid, struct, context=context).rule_ids - for rl in lines: - if rl.child_ids: - for r in rl.child_ids: - lines.append(r) - rules.append(rl) - for r in rules: + for fn in field_names: + if fn == 'applied_salary_rule': + for r in rules: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + elif fn == 'appears_on_payslip_rule': + for r in rules: if r.appears_on_payslip: - if r.id not in rule: - rule.append(r.id) - result[record.id] = rule - return result + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + elif fn == 'details_by_salary_head': + for r in rules: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + return res def _compute(self, cr, uid, id, value, context=None): rule_obj = self.pool.get('hr.salary.rule') @@ -569,9 +558,9 @@ class hr_payslip(osv.osv): 'igross': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'inet': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"), 'holiday_ids': fields.function(_get_holidays, method=True, type='one2many', relation='hr.holidays', string='Holiday Lines', required=False), - 'applied_salary_rule': fields.function(_applied_salary_rule, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', required=False), - 'appears_on_payslip_rule': fields.function(_appears_on_payslip_rule, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', required=False), -# 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head'), + 'applied_salary_rule': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', multi='applied_salary_rule'), + 'appears_on_payslip_rule': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', multi='appears_on_payslip_rule'), + 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head', multi='details_by_salary_head'), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d'), diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 65dbdc03049..57ab584d34a 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -286,11 +286,12 @@ - + - - + + + From 90ecf5b90fb8493789ec14557ae9f43f3dcaef01 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 28 Mar 2011 18:22:11 +0530 Subject: [PATCH 3/6] [IMP] hr_payroll:assigned default value for condition_select field on salary rules. bzr revid: mtr@mtr-20110328125211-iv509sw789vp8t2l --- addons/hr_payroll/hr_payroll.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 926e7723685..b92f9c51c60 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -1339,7 +1339,7 @@ class hr_salary_rule(osv.osv): 'gratuity':fields.boolean('Use for Gratuity ?', required=False), 'condition_select': fields.selection([('range', 'Range'), ('python', 'Python Expression')], "Condition based on"), 'computational_expression':fields.text('Computational Expression', required=True, readonly=False, help='This will use to computer the % fields values, in general its on basic, but You can use all heads code field in small letter as a variable name i.e. hra, ma, lta, etc...., also you can use, static varible basic'), - 'conditions':fields.char('Condition', size=1024, required=True, readonly=False, help='Applied this head for calculation if condition is true'), + 'conditions':fields.char('Condition', size=1024, required=True, readonly=False, help='Applied this rule for calculation if condition is true.You can specify condition like basic > 1000.'), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), '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."), 'python_compute':fields.text('Python Code'), @@ -1361,6 +1361,7 @@ class hr_salary_rule(osv.osv): 'company_id': lambda self, cr, uid, context: \ self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id, + 'condition_select': 'python', } # def _execute_function(self, cr, uid, id, value, context=None): From e9d028ea344c3f06411960e378ee37eee9661954 Mon Sep 17 00:00:00 2001 From: Osenda <> Date: Mon, 28 Mar 2011 15:50:32 +0200 Subject: [PATCH 4/6] [IMP]Changes on salary rule form bzr revid: osenda-20110328135032-yfumqec54ovtsbox --- addons/hr_payroll/hr_payroll.py | 3 ++- addons/hr_payroll/hr_payroll_view.xml | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index b92f9c51c60..f308f54cd9c 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -1338,7 +1338,7 @@ class hr_salary_rule(osv.osv): ), 'gratuity':fields.boolean('Use for Gratuity ?', required=False), 'condition_select': fields.selection([('range', 'Range'), ('python', 'Python Expression')], "Condition based on"), - 'computational_expression':fields.text('Computational Expression', required=True, readonly=False, help='This will use to computer the % fields values, in general its on basic, but You can use all heads code field in small letter as a variable name i.e. hra, ma, lta, etc...., also you can use, static varible basic'), + 'computational_expression':fields.char('Computational Expression',size=1024, required=True, readonly=False, help='This will use to computer the % fields values, in general its on basic, but You can use all heads code field in small letter as a variable name i.e. hra, ma, lta, etc...., also you can use, static varible basic'), 'conditions':fields.char('Condition', size=1024, required=True, readonly=False, help='Applied this rule for calculation if condition is true.You can specify condition like basic > 1000.'), 'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'), '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."), @@ -1350,6 +1350,7 @@ class hr_salary_rule(osv.osv): ],'Company Amount Type', select=True), 'contribute_per':fields.float('Company Contribution', digits=(16, 4), help='Define Company contribution ratio 1.00=100% contribution.'), 'company_contribution':fields.boolean('Company Contribution',help="This rule has Company Contributions."), + 'expression_result':fields.char('Expression based on',size=1024, required=True, readonly=False, help='result will be affected to a variable'), } _defaults = { 'python_compute': '''# basic\n# employee: hr.employee object or None\n# contract: hr.contract object or None\n\nresult = basic * 0.10''', diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index 57ab584d34a..5c12d6bee7b 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -616,18 +616,17 @@ - - - - + + + @@ -639,10 +638,10 @@ - - + + - + From f440181021ca88a77306803d8fc4506efc5d1ce7 Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 29 Mar 2011 12:00:55 +0530 Subject: [PATCH 5/6] [IMP] hr_payroll:improved code of _get_salary_rules for variable contracts bzr revid: mtr@mtr-20110329063055-a7vek0zrwij9099g --- addons/hr_payroll/hr_payroll.py | 62 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index f308f54cd9c..131f6ca58b9 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -477,40 +477,50 @@ class hr_payslip(osv.osv): def _get_salary_rules(self, cr, uid, ids, field_names, arg=None, context=None): structure_obj = self.pool.get('hr.payroll.structure') + contract_obj = self.pool.get('hr.contract') res = {} - sal_structure = [] lines = [] rules = [] rul = [] + structure = [] + sal_structure =[] for record in self.browse(cr, uid, ids, context=context): - function = record.struct_id.id + if record.struct_id.id: + structure.append(record.struct_id.id) + elif not record.struct_id: + contracts = self.get_contract(cr, uid, record.employee_id, record.date, context=context) + for ct in contracts: + contract_id = ct.get('id') + contract = contract_obj.browse(cr, uid, contract_id, context=context) + structure.append(contract.struct_id.id) res[record.id] = {} - if function: - sal_structure = self._get_parent_structure(cr, uid, [function], context=context) - for struct in sal_structure: - lines = structure_obj.browse(cr, uid, struct, context=context).rule_ids - for rl in lines: - if rl.child_ids: - for r in rl.child_ids: - lines.append(r) - rules.append(rl) - for fn in field_names: - if fn == 'applied_salary_rule': - for r in rules: - if r.id not in rul: - rul.append(r.id) - res[record.id] = {fn: rul} - elif fn == 'appears_on_payslip_rule': - for r in rules: - if r.appears_on_payslip: + for st in structure: + if st: + sal_structure = self._get_parent_structure(cr, uid, [st], context=context) + for struct in sal_structure: + lines = structure_obj.browse(cr, uid, struct, context=context).rule_ids + for rl in lines: + if rl.child_ids: + for r in rl.child_ids: + lines.append(r) + rules.append(rl) + for fn in field_names: + if fn == 'applied_salary_rule': + for r in rules: if r.id not in rul: rul.append(r.id) - res[record.id] = {fn: rul} - elif fn == 'details_by_salary_head': - for r in rules: - if r.id not in rul: - rul.append(r.id) - res[record.id] = {fn: rul} + res[record.id] = {fn: rul} + elif fn == 'appears_on_payslip_rule': + for r in rules: + if r.appears_on_payslip: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} + elif fn == 'details_by_salary_head': + for r in rules: + if r.id not in rul: + rul.append(r.id) + res[record.id] = {fn: rul} return res def _compute(self, cr, uid, id, value, context=None): From 5146542ccb5ae6310d94dbfc8dcc2e136fb268ff Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Tue, 29 Mar 2011 12:31:25 +0530 Subject: [PATCH 6/6] [FIX] payroll: expression_result make it required=false for now will work with attrs if python code bzr revid: mra@mra-laptop-20110329070125-qzk5o0zdcogvmci3 --- 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 131f6ca58b9..ed1e4b9ae39 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -1360,7 +1360,7 @@ class hr_salary_rule(osv.osv): ],'Company Amount Type', select=True), 'contribute_per':fields.float('Company Contribution', digits=(16, 4), help='Define Company contribution ratio 1.00=100% contribution.'), 'company_contribution':fields.boolean('Company Contribution',help="This rule has Company Contributions."), - 'expression_result':fields.char('Expression based on',size=1024, required=True, readonly=False, help='result will be affected to a variable'), + 'expression_result':fields.char('Expression based on', size=1024, required=False, readonly=False, help='result will be affected to a variable'), } _defaults = { 'python_compute': '''# basic\n# employee: hr.employee object or None\n# contract: hr.contract object or None\n\nresult = basic * 0.10''',