[IMP] hr_payroll:improved code for child_rules,added display_child_rules field
authormtr <mtr@mtr>
Thu, 17 Mar 2011 13:29:13 +0000 (18:59 +0530)
committermtr <mtr@mtr>
Thu, 17 Mar 2011 13:29:13 +0000 (18:59 +0530)
bzr revid: mtr@mtr-20110317132913-ffrst2r4dxgtw3w8

addons/hr_payroll/hr_payroll.py
addons/hr_payroll/hr_payroll_view.xml

index 9ef2b13..6c2713b 100644 (file)
@@ -963,38 +963,40 @@ class hr_payslip(osv.osv):
                 raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
             if line.amount_type == 'per':
                 try:
-                    if line.parent_rule_id:
-                        for rul in [line.parent_rule_id]:
-#                            if rul.child_depend:
-                            val = rul.amount * amt
-                            amt = val
-                    value = line.amount * amt
-                    if line.condition_range_min or line.condition_range_max:
-                        if ((value < line.condition_range_min) or (value > line.condition_range_max)):
-                            value = 0.0
+                    if line.child_depend == False:
+                        if line.parent_rule_id:
+                            for rul in [line.parent_rule_id]:
+                                val = rul.amount * amt
+                                amt = val
+                        value = line.amount * amt
+                        if line.condition_range_min or line.condition_range_max:
+                            if ((value < line.condition_range_min) or (value > line.condition_range_max)):
+                                value = 0.0
+                            else:
+                                value = value
                         else:
                             value = value
-                    else:
-                        value = value
                 except Exception, e:
                     raise osv.except_osv(_('Variable Error !'), _('Variable Error: %s ') % (e))
+                
             elif line.amount_type == 'fix':
-                if line.parent_rule_id:
+                if line.child_depend == False:
+                    if line.parent_rule_id:
                         for rul in [line.parent_rule_id]:
-#                            if rul.child_depend:
                             value = value
-                if line.condition_range_min or line.condition_range_max:
-                    if ((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)):
-                        value = value
+                    if line.condition_range_min or line.condition_range_max:
+                        if ((line.amount < line.condition_range_min) or (line.amount > line.condition_range_max)):
+                            value = value
+                        else:
+                            value = line.amount
                     else:
                         value = line.amount
-                else:
-                    value = line.amount
             elif line.amount_type=='code':
                 localdict = {'basic':amt}
                 exec line.python_code in localdict
                 value = localdict['result']
             total += value
+            
             vals = {
                 'category_id': line.category_id.id,
                 'name': line.name,
@@ -1008,12 +1010,18 @@ class hr_payslip(osv.osv):
 #                'function_id': False,
                 'base': line.computational_expression
             }
-            if line.appears_on_payslip and not line.parent_rule_id:
-                if line.condition_range_min or line.condition_range_max:
-                    if not ((value < line.condition_range_min) or (value > line.condition_range_max)):
-                        update['value']['line_ids'].append(vals)
+            if line.appears_on_payslip:
+                if line.parent_rule_id:
+                    for l in salary_rule_pool.browse(cr, uid, [line.parent_rule_id.id], context=context):
+                        if l.display_child_rules == True:
+                            update['value']['line_ids'].append(vals)
                 else:
-                    update['value']['line_ids'].append(vals)
+                    if line.condition_range_min or line.condition_range_max:
+                        if not ((value < line.condition_range_min) or (value > line.condition_range_max)):
+                            update['value']['line_ids'].append(vals)
+                    else:
+                        update['value']['line_ids'].append(vals)
+                    
         basic = contract.wage
         number = sequence_obj.get(cr, uid, 'salary.slip')
         update['value'].update({
@@ -1120,6 +1128,7 @@ class hr_payslip(osv.osv):
             'worked_days': working_day - leave,
             'working_days': working_day,
         })
+        
         return update
 
 hr_payslip()
@@ -1215,6 +1224,7 @@ class hr_salary_rule(osv.osv):
         'active':fields.boolean('Active'),
         'python_code': fields.text('Python code'),
         'python_compute':fields.text('Python Code'),
+        'display_child_rules': fields.boolean('Display Child Rules', help="Used for the display of Child Rules on payslip"),
      }
     _defaults = {
         'python_compute': '''# basic\n\nresult = basic * 0.10''',
index 74bc26a..49dd802 100644 (file)
                     <page string="Child Rules">
                        <separator colspan="4" string="Children definition"/>
                        <field name="child_depend"/>
+                       <field name="display_child_rules"/>
                        <field colspan="4" name="child_ids" nolabel="1"/>
                     </page>
                     <page string="Description">