~openerp-dev/openobject-addons/trunk-payroll-india

« back to all changes in this revision

Viewing changes to hr_payroll/hr_payroll.py

Tags: openerp-buildfail-95-9212
[MERGE] merged mra's branch: now we can access rules directly by giving rule code no need to give rules[Code name] in dictionary

Show diffs side-by-side

added added

removed removed

Lines of Context:
482
482
        #we keep a dict with the result because a value can be overwritten by another rule with the same code
483
483
        result_dict = {}
484
484
        blacklist = []
 
485
        obj_rule = self.pool.get('hr.salary.rule')
485
486
        payslip = self.pool.get('hr.payslip').browse(cr, uid, payslip_id, context=context)
486
487
        worked_days = {}
487
488
        for input_line in payslip.input_line_ids:
488
489
            worked_days[input_line.code] = input_line
489
 
        localdict = {'rules': {}, 'heads': {}, 'payslip': payslip, 'worked_days': worked_days}
 
490
        localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days}
490
491
        #get the ids of the structures on the contracts and their parent id as well
491
492
        structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context)
492
493
        #get the rules of the structure and thier children
497
498
        for contract in self.pool.get('hr.contract').browse(cr, uid, contract_ids, context=context):
498
499
            employee = contract.employee_id
499
500
            localdict.update({'employee': employee, 'contract': contract})
500
 
            for rule in self.pool.get('hr.salary.rule').browse(cr, uid, sorted_rule_ids, context=context):
 
501
            for rule in obj_rule.browse(cr, uid, sorted_rule_ids, context=context):
501
502
                key = rule.code + '-' + str(contract.id)
502
503
                localdict['result'] = None
503
504
                #check if the rule can be applied
504
 
                if self.pool.get('hr.salary.rule').satisfy_condition(cr, uid, rule.id, localdict, context=context) and rule.id not in blacklist:
 
505
                if obj_rule.satisfy_condition(cr, uid, rule.id, localdict, context=context) and rule.id not in blacklist:
505
506
                    #compute the amount of the rule
506
 
                    amount = self.pool.get('hr.salary.rule').compute_rule(cr, uid, rule.id, localdict, context=context)
 
507
                    amount = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context)
507
508
                    #check if there is already a rule computed with that code
508
 
                    previous_amount = rule.code in localdict['rules'] and localdict['rules'][rule.code] or 0.0
 
509
                    previous_amount = rule.code in localdict and localdict[rule.code] or 0.0
509
510
                    #set/overwrite the amount computed for this rule in the localdict
510
 
                    localdict['rules'][rule.code] = amount
 
511
                    localdict[rule.code] = amount
511
512
                    #sum the amount for its salary head
512
513
                    localdict = _sum_salary_head(localdict, rule.category_id, amount - previous_amount)
513
514
                    #create/overwrite the rule in the temporary results
679
680
# payslip: hr.payslip object
680
681
# employee: hr.employee object
681
682
# contract: hr.contract object
682
 
# rules: dictionary containing the previsouly computed rules. Keys are the rule codes.
 
683
# rules: rules code (previously computed)
683
684
# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
684
685
# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
685
686
 
693
694
# payslip: hr.payslip object
694
695
# employee: hr.employee object
695
696
# contract: hr.contract object
696
 
# rules: dictionary containing the previsouly computed rules. Keys are the rule codes.
 
697
# rules: rules code (previously computed)
697
698
# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
698
699
# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
699
700