← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-payroll-python-code-browse-using-dot-mtr into lp:~openerp-dev/openobject-addons/trunk-payroll

 

Meera Trambadia (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-payroll-python-code-browse-using-dot-mtr into lp:~openerp-dev/openobject-addons/trunk-payroll.

Requested reviews:
  qdp (OpenERP) (qdp)
  Mustufa Rangwala (Open ERP) (mra-tinyerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-python-code-browse-using-dot-mtr/+merge/61954

hr_payroll:- The python code expression can now be defined using browse('.'),accordingly changed data file.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-payroll-python-code-browse-using-dot-mtr/+merge/61954
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-payroll.
=== modified file 'hr_payroll/hr_payroll.py'
--- hr_payroll/hr_payroll.py	2011-05-12 11:57:19 +0000
+++ hr_payroll/hr_payroll.py	2011-05-23 11:24:57 +0000
@@ -467,11 +467,17 @@
         return res
 
     def get_payslip_lines(self, cr, uid, contract_ids, payslip_id, context):
-        def _sum_salary_rule_category(localdict, category, amount):
+        
+        class Categories(InputLine):
+
+            def __getattr__(self, key):
+                return self.dict[key]
+            
+        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 = {}
@@ -484,7 +490,9 @@
         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}
+        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
@@ -507,7 +515,7 @@
                     #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)
                     #create/overwrite the rule in the temporary results
                     result_dict[key] = {
                         'salary_rule_id': rule.id,
@@ -719,7 +727,7 @@
 # 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.
 
@@ -734,7 +742,7 @@
 # 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.
 

=== modified file 'hr_payroll/hr_payroll_data.xml'
--- hr_payroll/hr_payroll_data.xml	2011-05-11 07:18:54 +0000
+++ hr_payroll/hr_payroll_data.xml	2011-05-23 11:24:57 +0000
@@ -49,7 +49,7 @@
             <field name="category_id" ref="hr_payroll.GROSS"/>
             <field name="condition_select">none</field>
             <field name="amount_select">code</field>
-            <field name="amount_python_compute">result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0)</field>
+            <field name="amount_python_compute">result = categories.BASIC + (categories.ALW or 0.0)</field>
         </record>
 
         <record id="hr_rule_net" model="hr.salary.rule">
@@ -59,7 +59,7 @@
             <field name="category_id" ref="hr_payroll.NET"/>
             <field name="condition_select">none</field>
             <field name="amount_select">code</field>
-            <field name="amount_python_compute">result = categories['BASIC'] + ('ALW' in categories and categories['ALW'] or 0.0) + ('DED' in categories and categories['DED'] or 0.0)</field>
+            <field name="amount_python_compute">result = categories.BASIC + (categories.ALW or 0.0) + (categories.DED or 0.0)</field>
         </record>
 
 


Follow ups