[IMP] hr_payroll: modified the payroll engine in order to return the rate separately. Added a float precision for payroll rate. Original ideas from Yannick Buron.

bzr revid: qdp-launchpad@openerp.com-20120105081325-2pstk4naim07cy2o
This commit is contained in:
Quentin (OpenERP) 2012-01-05 09:13:25 +01:00
parent 12494f165e
commit 5602ac13b7
3 changed files with 28 additions and 15 deletions

View File

@ -585,14 +585,15 @@ class hr_payslip(osv.osv):
#check if the rule can be applied
if obj_rule.satisfy_condition(cr, uid, rule.id, localdict, context=context) and rule.id not in blacklist:
#compute the amount of the rule
amount, qty = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context)
amount, qty, rate = obj_rule.compute_rule(cr, uid, rule.id, localdict, context=context)
#check if there is already a rule computed with that code
previous_amount = rule.code in localdict and localdict[rule.code] or 0.0
#set/overwrite the amount computed for this rule in the localdict
localdict[rule.code] = amount * qty
tot_rule = amount * qty * rate / 100.0
localdict[rule.code] = tot_rule
rules[rule.code] = rule
#sum the amount for its salary category
localdict = _sum_salary_rule_category(localdict, rule.category_id, (amount * qty) - previous_amount)
localdict = _sum_salary_rule_category(localdict, rule.category_id, tot_rule - previous_amount)
#create/overwrite the rule in the temporary results
result_dict[key] = {
'salary_rule_id': rule.id,
@ -616,6 +617,7 @@ class hr_payslip(osv.osv):
'amount': amount,
'employee_id': contract.employee_id.id,
'quantity': qty,
'rate': rate,
}
else:
#blacklist this rule and its children
@ -780,7 +782,7 @@ class hr_salary_rule(osv.osv):
('code','Python Code'),
],'Amount Type', select=True, required=True, help="The computation method for the rule amount."),
'amount_fix': fields.float('Fixed Amount', digits_compute=dp.get_precision('Payroll'),),
'amount_percentage': fields.float('Percentage (%)', digits_compute=dp.get_precision('Payroll'), help='For example, enter 50.0 to apply a percentage of 50%'),
'amount_percentage': fields.float('Percentage (%)', digits_compute=dp.get_precision('Payroll Rate'), help='For example, enter 50.0 to apply a percentage of 50%'),
'amount_python_compute':fields.text('Python Code'),
'amount_percentage_base':fields.char('Percentage based on',size=1024, required=False, readonly=False, help='result will be affected to a variable'),
'child_ids':fields.one2many('hr.salary.rule', 'parent_rule_id', 'Child Salary Rule'),
@ -846,26 +848,26 @@ result = rules.NET > categories.NET * 0.10''',
#TODO should add some checks on the type of result (should be float)
def compute_rule(self, cr, uid, rule_id, localdict, context=None):
"""
@param rule_id: id of rule to compute
@param localdict: dictionary containing the environement in which to compute the rule
@return: returns the result of computation and the quantity as floats
:param rule_id: id of rule to compute
:param localdict: dictionary containing the environement in which to compute the rule
:return: returns a tuple build as the base/amount computed, the quantity and the rate
:rtype: (float, float, float)
"""
rule = self.browse(cr, uid, rule_id, context=context)
if rule.amount_select == 'fix':
try:
return rule.amount_fix, eval(rule.quantity, localdict)
return rule.amount_fix, eval(rule.quantity, localdict), 100.0
except:
raise osv.except_osv(_('Error'), _('Wrong quantity defined for salary rule %s (%s)')% (rule.name, rule.code))
elif rule.amount_select == 'percentage':
try:
amount = rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100
return amount, eval(rule.quantity, localdict)
return eval(rule.amount_percentage_base, localdict), eval(rule.quantity, localdict), rule.amount_percentage
except:
raise osv.except_osv(_('Error'), _('Wrong percentage base or quantity defined for salary rule %s (%s)')% (rule.name, rule.code))
else:
try:
eval(rule.amount_python_compute, localdict, mode='exec', nocopy=True)
return localdict['result'], 'result_qty' in localdict and localdict['result_qty'] or 1.0
return localdict['result'], 'result_qty' in localdict and localdict['result_qty'] or 1.0, 'result_rate' in localdict and localdict['result_rate'] or 100.0
except:
raise osv.except_osv(_('Error'), _('Wrong python code defined for salary rule %s (%s) ')% (rule.name, rule.code))
@ -923,7 +925,7 @@ class hr_payslip_line(osv.osv):
if not ids: return {}
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = float(line.quantity) * line.amount
res[line.id] = float(line.quantity) * line.amount * line.rate / 100
return res
_columns = {
@ -931,6 +933,7 @@ class hr_payslip_line(osv.osv):
'salary_rule_id':fields.many2one('hr.salary.rule', 'Rule', required=True),
'employee_id':fields.many2one('hr.employee', 'Employee', required=True),
'contract_id':fields.many2one('hr.contract', 'Contract', required=True, select=True),
'rate': fields.float('Rate (%)', digits_compute=dp.get_precision('Payroll Rate')),
'amount': fields.float('Amount', digits_compute=dp.get_precision('Payroll')),
'quantity': fields.float('Quantity', digits_compute=dp.get_precision('Payroll')),
'total': fields.function(_calculate_total, method=True, type='float', string='Total', digits_compute=dp.get_precision('Payroll'),store=True ),
@ -938,6 +941,7 @@ class hr_payslip_line(osv.osv):
_defaults = {
'quantity': 1.0,
'rate': 100.0,
}
hr_payslip_line()

View File

@ -79,5 +79,11 @@
<field name="digits">2</field>
</record>
<record forcecreate="True" id="decimal_payroll_rate" model="decimal.precision">
<field name="name">Payroll Rate</field>
<field name="digits">4</field>
</record>
</data>
</openerp>

View File

@ -169,7 +169,8 @@
<field name="sequence" groups="base.group_extended"/>
<field name="name"/>
<field name="code"/>
<field name="quantity" string="Quantity/Rate"/>
<field name="quantity"/>
<field name="rate"/>
<field name="amount"/>
<field name="total"/>
<field name="amount_select" invisible="1"/>
@ -319,7 +320,8 @@
<field name="code"/>
<field name="category_id"/>
<field name="sequence" invisible="1"/>
<field name="quantity" string="Quantity/Rate"/>
<field name="quantity"/>
<field name="rate"/>
<field name="amount"/>
<field name="total"/>
</tree>
@ -329,7 +331,8 @@
<field name="code" select="1"/>
<field name="category_id"/>
<field name="sequence" groups="base.group_extended"/>
<field name="quantity" string="Quantity/Rate"/>
<field name="quantity"/>
<field name="rate"/>
<field name="amount"/>
<field name="total"/>
<field name="salary_rule_id" groups="base.group_extended"/>