[IMP] onchange_employee on holidays will update the contract also, and now get_contract function will return list of contract object

bzr revid: psi@tinyerp.co.in-20110329133243-ki3uigbuskveb6sd
This commit is contained in:
psi (Open ERP) 2011-03-29 19:02:43 +05:30
parent fa5ceb85c2
commit bc6a98c3ab
2 changed files with 63 additions and 50 deletions

View File

@ -485,9 +485,9 @@ class hr_payslip(osv.osv):
elif not record.struct_id:
contracts = self.get_contract(cr, uid, record.employee_id, record.date, context=context)
for ct in contracts:
contract_id = ct.get('id')
contract = contract_obj.browse(cr, uid, contract_id, context=context)
structure.append(contract.struct_id.id)
# contract_id = ct.get('id')
# contract = contract_obj.browse(cr, uid, contract_id, context=context)
structure.append(ct.struct_id.id)
res[record.id] = {}
for st in structure:
if st:
@ -652,18 +652,22 @@ class hr_payslip(osv.osv):
return True
def get_contract(self, cr, uid, employee, date, context=None):
sql_req= '''
SELECT c.id as id, c.wage as wage, struct_id as function
FROM hr_contract c
LEFT JOIN hr_employee emp on (c.employee_id=emp.id)
WHERE
(emp.id=%s) AND
(date_start <= %s) AND
(date_end IS NULL OR date_end >= %s)
'''
cr.execute(sql_req, (employee.id, date, date))
contracts = cr.dictfetchall()
return contracts and contracts or {}
contract_obj = self.pool.get('hr.contract')
contracts = contract_obj.search(cr, uid, [('employee_id', '=', employee.id),('date_start','<=', date),'|',('date_end', '=', False),('date_end','>=', date)], context=context)
contract_ids = contract_obj.browse(cr, uid, contracts, context=context)
# sql_req= '''
# SELECT c.id as id, c.wage as wage, struct_id as function
# FROM hr_contract c
# LEFT JOIN hr_employee emp on (c.employee_id=emp.id)
# WHERE
# (emp.id=%s) AND
# (date_start <= %s) AND
# (date_end IS NULL OR date_end >= %s)
# '''
# cr.execute(sql_req, (employee.id, date, date))
# contracts = cr.dictfetchall()
return contract_ids and contract_ids or []
def _get_leaves(self, cr, user, ddate, employee, context=None):
"""
@ -712,11 +716,11 @@ class hr_payslip(osv.osv):
update.update({'struct_id': False})
contracts = self.get_contract(cr, uid, slip.employee_id, date, context=context)
else:
contracts = [contract_obj.read(cr, uid, contract_id, ['wage', 'struct_id', 'id'], context=context)]
update.update({
'struct_id': contracts[0].get('struct_id', False)[0],
'contract_id': contract_id
})
contracts = [contract_obj.browse(cr, uid, contract_id, context=context)]
# update.update({
# 'struct_id': contracts[0].get('struct_id', False)[0],
# 'contract_id': contract_id
# })
if not contracts:
update.update({
'basic_amount': 0.0,
@ -730,10 +734,6 @@ class hr_payslip(osv.osv):
self.write(cr, uid, [slip.id], update, context=context)
continue
for contract in contracts:
if contract.get('id', False) == False:
continue
contract_id = contract.get('id')
contract = contract_obj.browse(cr, uid, contract_id, context=context)
function = contract.struct_id.id
sal_structure = []
if function:
@ -958,12 +958,14 @@ class hr_payslip(osv.osv):
if not contract_id:
update['value'].update({'struct_id': False})
contracts = self.get_contract(cr, uid, employee_id, ddate, context=context)
# update['value'].update({
# 'struct_id': contracts[0].get('function', False),
# 'contract_id': contracts[0].get('id', False)
# })
else:
contracts = [contract_obj.read(cr, uid, contract_id, ['wage', 'struct_id', 'id'], context=context)]
update['value'].update({
'struct_id': contracts[0].get('struct_id', False),
'contract_id': contract_id
})
contracts = [contract_obj.browse(cr, uid, contract_id, context=context)]
update['value'].update({'struct_id': contracts[0].struct_id.id})
if not contracts:
update['value'].update({
'basic_amount': 0.0,
@ -977,11 +979,7 @@ class hr_payslip(osv.osv):
final_total = 0.0
all_basic = 0.0
for contract in contracts:
if contract.get('id', False) == False:
continue
contract_id = contract.get('id')
contract_id = contract_obj.browse(cr, uid, contract_id, context=context)
function = contract_id.struct_id.id
function = contract.struct_id.id
sal_structure = []
if function:
sal_structure = self._get_parent_structure(cr, uid, [function], context=context)
@ -996,7 +994,7 @@ class hr_payslip(osv.osv):
rules.append(rl)
ad = []
total = 0.0
obj = {'basic': contract_id.wage}
obj = {'basic': contract.wage}
for line in rules:
cd = line.code.lower()
obj[cd] = line.amount or 0.0
@ -1091,7 +1089,7 @@ class hr_payslip(osv.osv):
else:
update['value']['line_ids'].append(vals)
basic = contract_id.wage
basic = contract.wage
all_basic += basic
final_total += basic + total
number = sequence_obj.get(cr, uid, 'salary.slip')
@ -1102,7 +1100,7 @@ class hr_payslip(osv.osv):
'basic_before_leaves': basic,
'total_pay': final_total,
'name': 'Salary Slip of %s for %s' % (employee_id.name, tools.ustr(ttyme.strftime('%B-%Y'))),
# 'contract_id': contract_id.id,
# 'contract_id': contract.id,
'company_id': employee_id.company_id.id
})
@ -1259,6 +1257,18 @@ class hr_holidays(osv.osv):
'contract_id': fields.many2one('hr.contract', 'Contract', readonly=True, states={'draft':[('readonly',False)]})
}
def onchange_employee_id(self, cr, uid, ids, employee_id=False, context=None):
if not employee_id:
return {}
contract_obj = self.pool.get('hr.contract')
res = {}
contracts = contract_obj.search(cr, uid, [('employee_id', '=', employee_id)], context=context)
contract_ids = contract_obj.browse(cr, uid, contracts, context=context)
res.update({
'contract_id': contract_ids and contract_ids[0].id or False,
})
return {'value': res}
hr_holidays()
class hr_payslip_line(osv.osv):
@ -1351,7 +1361,7 @@ class hr_salary_rule(osv.osv):
],'Company Amount Type', select=True),
'contribute_per':fields.float('Company Contribution', digits=(16, 4), help='Define Company contribution ratio 1.00=100% contribution.'),
'company_contribution':fields.boolean('Company Contribution',help="This rule has Company Contributions."),
'expression_result':fields.char('Expression based on', size=1024, required=False, readonly=False, help='result will be affected to a variable'),
'expression_result':fields.char('Expression based on', size=1024, required=False, readonly=False, help='result will be affected to a variable'),
}
_defaults = {
'python_compute': '''# basic\n# employee: hr.employee object or None\n# contract: hr.contract object or None\n\nresult = basic * 0.10''',

View File

@ -64,8 +64,11 @@
<field name="inherit_id" ref="hr_holidays.edit_holiday_new"/>
<field name="arch" type="xml">
<data>
<xpath expr="/form/group/group/field[@name='employee_id']" position="replace">
<field name="employee_id" on_change="onchange_employee_id(employee_id)" attrs="{'required':[('holiday_type','=','employee')], 'invisible':[('holiday_type','=','category')]}"/>
</xpath>
<xpath expr="/form/notebook/page/field[@name='number_of_days_temp']" position="after">
<field name="contract_id" select="1" domain="[('employee_id', '=', employee_id)]" attrs="{'invisible':[('holiday_type','=','category')], 'required':[('holiday_type','=','employee')]}"/>
<field name="contract_id" select="1" domain="[('employee_id', '=', employee_id)]" attrs="{'invisible':[('holiday_type','=','category')]}"/>
</xpath>
</data>
</field>
@ -225,7 +228,7 @@
<field name="arch" type="xml">
<form string="Payslip">
<group col="6" colspan="4">
<field name="employee_id" on_change="onchange_employee_id(date, employee_id, contract_id)"/>
<field name="employee_id" context="{'employee': True}" on_change="onchange_employee_id(date, employee_id, contract_id, context)"/>
<field name="name"/>
<field name="number"/>
<field name="date"/>
@ -303,12 +306,11 @@
<page string="Applied Salary Rules">
<field name="applied_salary_rule" nolabel="1" />
</page>
<page string="Appears On Payslip">
<page string="Appears on payslip">
<field name="appears_on_payslip_rule" nolabel="1"/>
</page>
<page string="Details By Salary Head">
<field name="details_by_salary_head" nolabel="1" context="{'group_by': 'category_id'}"/>
</page>
<page string="Details by salary head">
</page>
</notebook>
<group col="10" colspan="4">
<field name="state"/>
@ -633,17 +635,18 @@
<notebook colspan="6">
<page string="General">
<group col="6" colspan="6">
<group col="2" colspan="4">
<separator colspan="4" string="Computational Expression"/>
<field name="computational_expression" colspan="4" nolabel="1"/>
</group>
<group col="2" colspan="2">
<separator colspan="4" string="Calculations"/>
<!--<field name="type"/>-->
<field name="computational_expression"/>
<field name="condition_select"/>
<field name="conditions" attrs="{'invisible':[('condition_select','=','range')]}"/>
<field name="condition_range_min" attrs="{'invisible':[('condition_select','=','python')]}" colspan="1"/>
<field name="condition_range_max" attrs="{'invisible':[('condition_select','=','python')]}" colspan="1"/>
<field name="amount_type"/>
<field name="expression_result"/>
<field name="amount" on_change="onchange_amount(amount, amount_type)" attrs="{'invisible':[('amount_type','=','code')]}"/>
<group col="2" colspan="2" attrs="{'invisible':[('amount_type','&lt;&gt;','code')]}">
<separator colspan="2" string="Compute Code"/>
@ -655,10 +658,10 @@
<separator colspan="4" string="Company contribution"/>
<field name="company_contribution"/>
<group col="2" colspan="2" attrs="{'readonly':[('company_contribution','=',False)]}">
<!-- <field name="amt_type" />-->
<!-- <field name="contribute_per"/>-->
<field name="amt_type" />
<field name="contribute_per"/>
<field name="register_id"/>
<!-- <field name="company_contrib"/>-->
<field name="company_contrib"/>
</group>
</group>
</group>