From 32c8d6cb70f796d83acc9a0de2761c8c35925138 Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 19 May 2011 11:01:18 +0530 Subject: [PATCH 1/7] [IMP] hr_payroll: The python code expression can now be defined using 'browse',accordingly changed data file bzr revid: mtr@mtr-20110519053118-yzcmr39m3hqdb4u5 --- addons/hr_payroll/hr_payroll.py | 28 +++++++++++++++++++++------ addons/hr_payroll/hr_payroll_data.xml | 4 ++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index b70b30676a8..e1ff7aa7e59 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -467,15 +467,29 @@ class hr_payslip(osv.osv): return res def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - def _sum_salary_rule_category(localdict, category, amount): + + class Categories(object): + def __init__(self, pool, cr, uid, employee_id, dict): + self.pool = pool + self.cr = cr + self.uid = uid + self.employee_id = employee_id + self.dict = dict + + def __getattr__(self, key): + value = self.dict[key] + return value + + def _sum_salary_rule_category(categories_dict, category, amount): if category.parent_id: - localdict = _sum_salary_rule_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 + categories_dict = _sum_salary_rule_category(categories_dict, category.parent_id, amount) + categories_dict[category.code] = category.code in categories_dict and categories_dict[category.code] + amount or amount + return categories_dict #we keep a dict with the result because a value can be overwritten by another rule with the same code result_dict = {} blacklist = [] + categories_dict = {} obj_rule = self.pool.get('hr.salary.rule') payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context) worked_days = {} @@ -484,7 +498,7 @@ class hr_payslip(osv.osv): inputs = {} for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line - localdict = {'categories': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs} + localdict = {'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 @@ -507,7 +521,9 @@ 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 category - localdict = _sum_salary_rule_category(localdict, rule.category_id, amount - previous_amount) + categories_dict = _sum_salary_rule_category(categories_dict, rule.category_id, amount - previous_amount) + categories_obj = Categories(self.pool, cr, uid, payslip.employee_id.id, categories_dict) + localdict['categories'] = categories_obj #create/overwrite the rule in the temporary results result_dict[key] = { 'salary_rule_id': rule.id, diff --git a/addons/hr_payroll/hr_payroll_data.xml b/addons/hr_payroll/hr_payroll_data.xml index c7ba6e62062..de70ee9d762 100644 --- a/addons/hr_payroll/hr_payroll_data.xml +++ b/addons/hr_payroll/hr_payroll_data.xml @@ -49,7 +49,7 @@ none code - result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0) + result = categories.BASIC + (categories.ALW or 0.0) @@ -59,7 +59,7 @@ none code - result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0) + ('DED' in categories and categories['DED'] or 0.0) + result = categories.BASIC + (categories.ALW or 0.0) + (categories.DED or 0.0) From 961e04cc9e9c1acecb3a1d1aeeea4a27dd82372a Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 23 May 2011 15:05:04 +0530 Subject: [PATCH 2/7] [IMP] hr_payroll: initiate object outside the for loop bzr revid: mtr@mtr-20110523093504-m2ibjrkk755dejuu --- addons/hr_payroll/hr_payroll.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index e1ff7aa7e59..8c95bda99e8 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -489,7 +489,6 @@ class hr_payslip(osv.osv): #we keep a dict with the result because a value can be overwritten by another rule with the same code result_dict = {} blacklist = [] - categories_dict = {} obj_rule = self.pool.get('hr.salary.rule') payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context) worked_days = {} @@ -498,7 +497,9 @@ class hr_payslip(osv.osv): inputs = {} for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line - localdict = {'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs} + categories_dict = {} + categories_obj = Categories(self.pool, cr, uid, payslip.employee_id.id, categories_dict) + localdict = {'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs, 'categories': categories_obj} #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 @@ -522,8 +523,6 @@ class hr_payslip(osv.osv): localdict[rule.code] = amount #sum the amount for its salary category categories_dict = _sum_salary_rule_category(categories_dict, rule.category_id, amount - previous_amount) - categories_obj = Categories(self.pool, cr, uid, payslip.employee_id.id, categories_dict) - localdict['categories'] = categories_obj #create/overwrite the rule in the temporary results result_dict[key] = { 'salary_rule_id': rule.id, From 33f2f16249694f02da5e2f65dcafc1a0aca390e9 Mon Sep 17 00:00:00 2001 From: mtr Date: Mon, 23 May 2011 16:52:03 +0530 Subject: [PATCH 3/7] [IMP] hr_payroll: inherited 'Inputline' class and changed help strings bzr revid: mtr@mtr-20110523112203-3xj8q54ffiqxmyz3 --- addons/hr_payroll/hr_payroll.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 8c95bda99e8..94d993bdb80 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -468,17 +468,10 @@ class hr_payslip(osv.osv): def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - class Categories(object): - def __init__(self, pool, cr, uid, employee_id, dict): - self.pool = pool - self.cr = cr - self.uid = uid - self.employee_id = employee_id - self.dict = dict + class Categories(InputLine): def __getattr__(self, key): - value = self.dict[key] - return value + return self.dict[key] def _sum_salary_rule_category(categories_dict, category, amount): if category.parent_id: @@ -734,7 +727,7 @@ class hr_salary_rule(osv.osv): # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# categories: dictionary containing the computed salary rule categories (sum of amount of all rules belonging to that category). Keys are the category codes. +# categories: object containing the computed salary rule categories. # 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. @@ -749,7 +742,7 @@ result = contract.wage * 0.10''', # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# categories: dictionary containing the computed salary rule categories (sum of amount of all rules belonging to that category). Keys are the category codes. +# categories: object containing the computed salary rule categories. # 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. From a54773c65d84a860bfaf7a7fd055a009096faa01 Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 24 May 2011 16:03:12 +0530 Subject: [PATCH 4/7] [IMP] hr_payroll: used 'BrowsableObject' method instead of inheritancy bzr revid: mtr@mtr-20110524103312-dvn8fbyzfp2grpll --- addons/hr_payroll/hr_payroll.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 004142cc271..d0b4f9c78d6 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -468,11 +468,6 @@ class hr_payslip(osv.osv): def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - class Categories(InputLine): - - def __getattr__(self, key): - return self.dict[key] - def _sum_salary_rule_category(categories_dict, category, amount): if category.parent_id: categories_dict = _sum_salary_rule_category(categories_dict, category.parent_id, amount) @@ -553,7 +548,7 @@ class hr_payslip(osv.osv): for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line categories_dict = {} - categories_obj = Categories(self.pool, cr, uid, payslip.employee_id.id, categories_dict) + categories_obj = BrowsableObject(self.pool, cr, uid, payslip.employee_id.id, categories_dict) input_obj = InputLine(self.pool, cr, uid, payslip.employee_id.id, inputs) worked_days_obj = WorkedDays(self.pool, cr, uid, payslip.employee_id.id, worked_days) payslip_obj = Payslips(self.pool, cr, uid, payslip.employee_id.id, payslip) From 8b32533bec753785111635c770daa87591b5c640 Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 26 May 2011 11:24:02 +0530 Subject: [PATCH 5/7] [IMP] hr_payroll: revert back the changes from localdict => category_dict bzr revid: mtr@mtr-20110526055402-ua3mu846d8zw4jso --- addons/hr_payroll/hr_payroll.py | 17 +++++++++-------- addons/hr_payroll/hr_payroll_data.xml | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 7bf242cfaa3..8113e8d4521 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -468,12 +468,11 @@ class hr_payslip(osv.osv): return res def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context): - - def _sum_salary_rule_category(categories_dict, category, amount): + def _sum_salary_rule_category(localdict, category, amount): if category.parent_id: - categories_dict = _sum_salary_rule_category(categories_dict, category.parent_id, amount) - categories_dict[category.code] = category.code in categories_dict and categories_dict[category.code] + amount or amount - return categories_dict + localdict = _sum_salary_rule_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 class BrowsableObject(object): def __init__(self, pool, cr, uid, employee_id, dict): @@ -537,6 +536,7 @@ class hr_payslip(osv.osv): #we keep a dict with the result because a value can be overwritten by another rule with the same code result_dict = {} + categories_dict = {} blacklist = [] payslip_obj = self.pool.get('hr.payslip') inputs_obj = self.pool.get('hr.payslip.worked_days') @@ -548,13 +548,13 @@ class hr_payslip(osv.osv): inputs = {} for input_line in payslip.input_line_ids: inputs[input_line.code] = input_line - categories_dict = {} + categories_obj = BrowsableObject(self.pool, cr, uid, payslip.employee_id.id, categories_dict) input_obj = InputLine(self.pool, cr, uid, payslip.employee_id.id, inputs) worked_days_obj = WorkedDays(self.pool, cr, uid, payslip.employee_id.id, worked_days) payslip_obj = Payslips(self.pool, cr, uid, payslip.employee_id.id, payslip) - localdict = {'payslip': payslip_obj, 'worked_days': worked_days_obj, 'inputs': input_obj, 'categories': categories_obj} + localdict = {'categories': {}, 'payslip': payslip_obj, 'worked_days': worked_days_obj, 'inputs': input_obj, 'rule_categories': categories_obj} #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 @@ -577,7 +577,8 @@ 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 category - categories_dict = _sum_salary_rule_category(categories_dict, rule.category_id, amount - previous_amount) + localdict = _sum_salary_rule_category(localdict, rule.category_id, amount - previous_amount) + categories_dict.update(localdict['categories']) #create/overwrite the rule in the temporary results result_dict[key] = { 'salary_rule_id': rule.id, diff --git a/addons/hr_payroll/hr_payroll_data.xml b/addons/hr_payroll/hr_payroll_data.xml index de70ee9d762..92ec453a301 100644 --- a/addons/hr_payroll/hr_payroll_data.xml +++ b/addons/hr_payroll/hr_payroll_data.xml @@ -49,7 +49,7 @@ none code - result = categories.BASIC + (categories.ALW or 0.0) + result = rule_categories.BASIC + (rule_categories.ALW or 0.0) @@ -59,7 +59,7 @@ none code - result = categories.BASIC + (categories.ALW or 0.0) + (categories.DED or 0.0) + result = rule_categories.BASIC + (rule_categories.ALW or 0.0) + (rule_categories.DED or 0.0) From 09b88682e1ceadca89938e796fbe67fa34dde01d Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 26 May 2011 11:26:55 +0530 Subject: [PATCH 6/7] [IMP] hr_payroll: improved help string categories=>rule_categories bzr revid: mtr@mtr-20110526055655-iw9yg4999a5l8g1z --- addons/hr_payroll/hr_payroll.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 8113e8d4521..6c3d894f977 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -791,7 +791,7 @@ class hr_salary_rule(osv.osv): # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# categories: object containing the computed salary rule categories. +# rule_categories: object containing the computed salary rule categories. # worked_days: object containing the computed worked days. # inputs: object containing the computed inputs. @@ -806,7 +806,7 @@ result = contract.wage * 0.10''', # employee: hr.employee object # contract: hr.contract object # rules: rules code (previously computed) -# categories: object containing the computed salary rule categories. +# rule_categories: object containing the computed salary rule categories. # worked_days: object containing the computed worked days # inputs: object containing the computed inputs From 2eb5bb33f7265c57b3f6a9739590f0fb185de743 Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 26 May 2011 17:05:25 +0530 Subject: [PATCH 7/7] [IMP] hr_payroll: improved help string on 'amount_python_compute' field bzr revid: mtr@mtr-20110526113525-de0h5y8bp7c5shdm --- 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 55d78d919ab..0a96ca0bb25 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -803,7 +803,7 @@ result = contract.wage * 0.10''', # Note: returned value have to be set in the variable 'result' -result = rules['NET'] > categories['NET'] * 0.10''', +result = rules['NET'] > rule_categories.NET * 0.10''', 'condition_range': 'contract.wage', 'sequence': 5, 'appears_on_payslip': True,