[MERGE, IMP] Merge with mtr's branch and improve compute_sheet method for multiple contracts of an employee

bzr revid: psi@tinyerp.co.in-20110328052714-7p6lh6p9hzj9s7pr
This commit is contained in:
psi (Open ERP) 2011-03-28 10:57:14 +05:30
commit cfb4267d8a
2 changed files with 227 additions and 163 deletions

View File

@ -464,6 +464,66 @@ class hr_payslip(osv.osv):
result[record.id] = [x[0] for x in res]
return result
def _get_parent_structure(self, cr, uid, struct_id, context=None):
if not struct_id:
return []
parent = []
for line in self.pool.get('hr.payroll.structure').browse(cr, uid, struct_id):
if line.parent_id:
parent.append(line.parent_id.id)
if parent:
parent = self._get_parent_structure(cr, uid, parent, context)
return struct_id + parent
def _applied_salary_rule(self, cr, uid, ids, field_names, arg=None, context=None):
structure_obj = self.pool.get('hr.payroll.structure')
result = {}
for record in self.browse(cr, uid, ids, context=context):
function = record.struct_id.id
sal_structure = []
lines = []
rules = []
rule = []
if function:
sal_structure = self._get_parent_structure(cr, uid, [function], context=context)
for struct in sal_structure:
lines = structure_obj.browse(cr, uid, struct, context=context).rule_ids
for rl in lines:
if rl.child_ids:
for r in rl.child_ids:
lines.append(r)
rules.append(rl)
for r in rules:
if r.id not in rule:
rule.append(r.id)
result[record.id] = rule
return result
def _appears_on_payslip_rule(self, cr, uid, ids, field_names, arg=None, context=None):
struct_obj = self.pool.get('hr.payroll.structure')
result = {}
for record in self.browse(cr, uid, ids, context=context):
structure = record.struct_id.id
sal_struct = []
lines = []
rules = []
rule = []
if structure:
sal_struct = self._get_parent_structure(cr, uid, [structure], context=context)
for struct in sal_struct:
lines = struct_obj.browse(cr, uid, struct, context=context).rule_ids
for rl in lines:
if rl.child_ids:
for r in rl.child_ids:
lines.append(r)
rules.append(rl)
for r in rules:
if r.appears_on_payslip:
if r.id not in rule:
rule.append(r.id)
result[record.id] = rule
return result
def _compute(self, cr, uid, id, value, context=None):
rule_obj = self.pool.get('hr.salary.rule')
contrib = rule_obj.browse(cr, uid, id, context=context)
@ -509,6 +569,9 @@ class hr_payslip(osv.osv):
'igross': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"),
'inet': fields.float('Calculaton Field', readonly=True, digits=(16, 2), help="Calculation field used for internal calculation, do not place this on form"),
'holiday_ids': fields.function(_get_holidays, method=True, type='one2many', relation='hr.holidays', string='Holiday Lines', required=False),
'applied_salary_rule': fields.function(_applied_salary_rule, method=True, type='one2many', relation='hr.salary.rule', string='Applied Salary Rules', required=False),
'appears_on_payslip_rule': fields.function(_appears_on_payslip_rule, method=True, type='one2many', relation='hr.salary.rule', string='Appears on Payslip', required=False),
# 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head'),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
@ -633,17 +696,6 @@ class hr_payslip(osv.osv):
result = [x[0] for x in res]
return result
def _get_parent_structure(self, cr, uid, struct_id, context=None):
if not struct_id:
return []
parent = []
for line in self.pool.get('hr.payroll.structure').browse(cr, uid, struct_id):
if line.parent_id:
parent.append(line.parent_id.id)
if parent:
parent = self._get_parent_structure(cr, uid, parent, context)
return struct_id + parent
def compute_sheet(self, cr, uid, ids, context=None):
func_pool = self.pool.get('hr.payroll.structure')
slip_line_pool = self.pool.get('hr.payslip.line')
@ -662,19 +714,24 @@ class hr_payslip(osv.osv):
update = {}
ttyme = datetime.fromtimestamp(time.mktime(time.strptime(slip.date, "%Y-%m-%d")))
contracts = self.get_contract(cr, uid, slip.employee_id, date, context)
if contracts.get('id', False) == False:
if not contracts:
update.update({
'basic': 0.0,
'basic_amount': 0.0,
'basic_before_leaves': 0.0,
'name': 'Salary Slip of %s for %s' % (slip.employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
'state': 'draft',
'contract_id': False,
'struct_id': False,
'company_id': slip.employee_id.company_id.id
})
self.write(cr, uid, [slip.id], update, context=context)
continue
contract = slip.employee_id.contract_id
for contract in contracts:
if contract.get('id', False) == False:
continue
contract_id = contract.get('id')
contract = self.pool.get('hr.contract').browse(cr, uid, contract_id, context=context)
function = contract.struct_id.id
sal_structure = []
if function:
@ -974,6 +1031,7 @@ class hr_payslip(osv.osv):
val = rul.amount * amt
amt = val
value = line.amount * amt
if line.condition_select == 'range':
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
@ -989,6 +1047,7 @@ class hr_payslip(osv.osv):
if line.parent_rule_id:
for rul in [line.parent_rule_id]:
value = value
if line.condition_select == 'range':
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
@ -998,13 +1057,14 @@ class hr_payslip(osv.osv):
value = line.amount
elif line.amount_type=='code':
localdict = {'basic':amt, 'employee':employee_id, 'contract':contract_id}
localdict = {'basic':amt, 'employee':employee_id, 'contract':contract}
exec line.python_compute in localdict
val = localdict['result']
if line.child_depend == False:
if line.parent_rule_id:
for rul in [line.parent_rule_id]:
value = val
if line.condition_select == 'range':
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
@ -1012,7 +1072,6 @@ class hr_payslip(osv.osv):
value = val
else:
value = val
total += value
vals = {
'category_id': line.category_id.id,
@ -1115,6 +1174,7 @@ class hr_payslip(osv.osv):
val = rul.amount * amt
amt = val
value = salary_rule.amount * amt * days
if line.condition_select == 'range':
if salary_rule.condition_range_min or salary_rule.condition_range_max:
if ((value < salary_rule.condition_range_min) or (value > salary_rule.condition_range_max)):
value = 0.0
@ -1131,6 +1191,7 @@ class hr_payslip(osv.osv):
if salary_rule.parent_rule_id:
for rul in [salary_rule.parent_rule_id]:
value = salary_rule.amount * days
if line.condition_select == 'range':
if salary_rule.condition_range_min or salary_rule.condition_range_max:
if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)):
value = 0.0
@ -1147,6 +1208,7 @@ class hr_payslip(osv.osv):
if salary_rule.parent_rule_id:
for rul in [salary_rule.parent_rule_id]:
value = val
if line.condition_select == 'range':
if salary_rule.condition_range_min or salary_rule.condition_range_max:
if ((salary_rule.amount < salary_rule.condition_range_min) or (salary_rule.amount > salary_rule.condition_range_max)):
value = value

View File

@ -284,8 +284,10 @@
</page>
<page string="Applied Salary Rules">
<field name="applied_salary_rule" nolabel="1" />
</page>
<page string="Appears on payslip">
<field name="appears_on_payslip_rule" nolabel="1"/>
</page>
<page string="Details by salary head">
</page>