[MERGE] merged mtr's branch: added field 'quantity' on salary rule object and changed the computation engine accordingly

bzr revid: qdp-launchpad@openerp.com-20110428124014-31j04y8kx3cm31k6
This commit is contained in:
Quentin (OpenERP) 2011-04-28 14:40:14 +02:00
commit 4023e0d5e9
3 changed files with 16 additions and 6 deletions

View File

@ -533,10 +533,12 @@ class hr_payslip(osv.osv):
'register_id': rule.register_id.id,
'total': amount,
'employee_id': contract.employee_id.id,
'quantity': rule.quantity,
}
else:
#blacklist this rule and its children
blacklist += [id for id, seq in self.pool.get('hr.salary.rule')._recursive_search_of_rules(cr, uid, [rule], context=context)]
result = [value for code, value in result_dict.items()]
return result
@ -641,6 +643,7 @@ class hr_salary_rule(osv.osv):
'name':fields.char('Name', size=256, required=True, readonly=False),
'code':fields.char('Code', size=64, required=True),
'sequence': fields.integer('Sequence', required=True, help='Use to arrange calculation sequence'),
'quantity': fields.char('Quantity', size=256, help="It is used in computation for percentage and fixed amount.For e.g. A rule for Meal Voucher having fixed amount of 1€ can have its quantity defined in expression like worked_days['WORK100']['number_of_days']."),
'category_id':fields.many2one('hr.salary.head', 'Salary Head', required=True),
'active':fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the salary rule without removing it."),
'appears_on_payslip': fields.boolean('Appears on Payslip', help="Used for the display of rule on payslip"),
@ -712,6 +715,7 @@ result = rules['NET'] > heads['NET'] * 0.10''',
'amount_select': 'fix',
'amount_fix': 0.0,
'amount_percentage': 0.0,
'quantity': '1',
}
def _recursive_search_of_rules(self, cr, uid, rule_ids, context=None):
@ -734,12 +738,16 @@ result = rules['NET'] > heads['NET'] * 0.10''',
"""
rule = self.browse(cr, uid, rule_id, context=context)
if rule.amount_select == 'fix':
return rule.amount_fix
try:
return rule.amount_fix * eval(rule.quantity, localdict)
except:
raise osv.except_osv(_('Error'), _('Wrong quantity defined for salary rule %s (%s)')% (rule.name, rule.code))
elif rule.amount_select == 'percentage':
try:
return rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100
amount = rule.amount_percentage * eval(rule.amount_percentage_base, localdict) / 100
return amount * eval(rule.quantity, localdict)
except:
raise osv.except_osv(_('Error'), _('Wrong percentage base defined for salary rule %s (%s)')% (rule.name, rule.code))
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)

View File

@ -52,8 +52,9 @@
</record>
<record id="hr_salary_rule_meal_voucher" model="hr.salary.rule">
<field name="amount_select">code</field>
<field name="amount_python_compute">result = worked_days['WORK100']['number_of_days'] * 1</field>
<field name="amount_select">fix</field>
<field eval="1" name="amount_fix"/>
<field name="quantity">worked_days['WORK100']['number_of_days']</field>
<field name="code">MA</field>
<field name="category_id" ref="hr_payroll.ALW"/>
<field name="name">Meal Voucher</field>

View File

@ -528,7 +528,8 @@
<field name="condition_range_min" colspan="2" attrs="{'invisible':[('condition_select','&lt;&gt;','range')], 'required':[('condition_select','=','range')]}"/>
<field name="condition_range_max" colspan="2" attrs="{'invisible':[('condition_select','&lt;&gt;','range')], 'required':[('condition_select','=','range')]}"/>
<separator colspan="4" string="Computation"/>
<field name="amount_select"/><newline/>
<field name="amount_select"/>
<field name="quantity" attrs="{'invisible':[('amount_select','=','code')], 'required':[('amount_select','!=','code')]}"/><newline/>
<field name="amount_fix" attrs="{'invisible':[('amount_select','&lt;&gt;','fix')], 'required':[('amount_select','=','fix')]}"/>
<field colspan="4" name="amount_python_compute" attrs="{'invisible':[('amount_select','&lt;&gt;','code')], 'required':[('amount_select','=','code')]}"/>
<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','&lt;&gt;','percentage')], 'required': [('amount_select','=','percentage')]}"/>