[IMP]hr_payroll: create button
bzr revid: pat@tinyerp.com-20120713120927-pnx0qdmsjxgn9som
This commit is contained in:
parent
87bdb4895d
commit
1b4dd5856e
|
@ -236,35 +236,7 @@ class hr_payslip_run(osv.osv):
|
|||
def close_payslip_run(self, cr, uid, ids, context=None):
|
||||
return self.write(cr, uid, ids, {'state': 'close'}, context=context)
|
||||
|
||||
def create_advice_run(self, cr, uid, ids, context=None):
|
||||
advice_pool = self.pool.get('hr.payroll.advice')
|
||||
advice_line_pool = self.pool.get('hr.payroll.advice.line')
|
||||
payslip_pool = self.pool.get('hr.payslip')
|
||||
payslip_line_pool = self.pool.get('hr.payslip.line')
|
||||
users = self.pool.get('res.users').browse(cr, uid, [uid], context=context)
|
||||
for run in self.browse(cr, uid, ids, context=context):
|
||||
advice_data = {
|
||||
'company_id': users[0].company_id.id,
|
||||
'name': run.name,
|
||||
'date': run.date_end,
|
||||
'bank_id': users[0].company_id.bank_ids and users[0].company_id.bank_ids[0].id or False
|
||||
}
|
||||
advice_id = advice_pool.create(cr, uid, advice_data, context=context)
|
||||
slip_ids = payslip_pool.search(cr, uid, [('payslip_run_id', '=', run.id), ('state', '=', 'done')], context=context)
|
||||
for slip in payslip_pool.browse(cr, uid, slip_ids, context=context):
|
||||
if not slip.employee_id.bank_account_id and not slip.employee_id.bank_account_id.acc_number:
|
||||
raise osv.except_osv(_('Error !'), _('Please define bank account for the %s employee') % (slip.employee_id.name))
|
||||
line_ids = payslip_line_pool.search(cr, uid, [('slip_id', '=', slip.id), ('code', '=', 'NET')], context=context)
|
||||
if line_ids:
|
||||
line = payslip_line_pool.browse(cr, uid, line_ids, context=context)[0]
|
||||
advice_line = {
|
||||
'advice_id': advice_id,
|
||||
'name': slip.employee_id.bank_account_id.acc_number,
|
||||
'employee_id': slip.employee_id.id,
|
||||
'bysal': line.total
|
||||
}
|
||||
advice_line_id = advice_line_pool.create(cr, uid, advice_line, context=context)
|
||||
return True
|
||||
hr_payslip_run()
|
||||
|
||||
class hr_payslip(osv.osv):
|
||||
'''
|
||||
|
|
|
@ -727,7 +727,6 @@
|
|||
<button name="close_payslip_run" type="object" string="Close" states="draft" class="oe_highlight"/>
|
||||
<button name="%(action_hr_payslip_by_employees)d" type="action" states="draft" string="Generate Payslips" class="oe_highlight"/>
|
||||
<button name="draft_payslip_run" string="Set to Draft" type="object" states="close" />
|
||||
<button name="create_advice_run" string="Create Advice" type="object" states="close" />
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
|
|
@ -210,6 +210,47 @@ class payroll_advice(osv.osv):
|
|||
|
||||
payroll_advice()
|
||||
|
||||
class hr_payslip_run(osv.osv):
|
||||
|
||||
_inherit = 'hr.payslip.run'
|
||||
_description = 'Payslip Batches'
|
||||
_columns = {
|
||||
}
|
||||
|
||||
def create_advice_run(self, cr, uid, ids, context=None):
|
||||
res = super(hr_payslip_run, self).close_payslip_run(cr, uid, ids, context=context)
|
||||
payslip_pool = self.pool.get('hr.payslip')
|
||||
payslip_line_pool = self.pool.get('hr.payslip.line')
|
||||
advice_pool = self.pool.get('hr.payroll.advice')
|
||||
advice_line_pool = self.pool.get('hr.payroll.advice.line')
|
||||
users = self.pool.get('res.users').browse(cr, uid, [uid], context=context)
|
||||
for run in self.browse(cr, uid, ids, context=context):
|
||||
advice_data = {
|
||||
'company_id': users[0].company_id.id,
|
||||
'name': run.name,
|
||||
'date': run.date_end,
|
||||
'bank_id': users[0].company_id.bank_ids and users[0].company_id.bank_ids[0].id or False
|
||||
}
|
||||
advice_id = advice_pool.create(cr, uid, advice_data, context=context)
|
||||
|
||||
slip_ids = payslip_pool.search(cr, uid, [('payslip_run_id', '=', run.id), ('state', '=', 'done')], context=context)
|
||||
for slip in payslip_pool.browse(cr, uid, slip_ids, context=context):
|
||||
if not slip.employee_id.bank_account_id and not slip.employee_id.bank_account_id.acc_number:
|
||||
raise osv.except_osv(_('Error !'), _('Please define bank account for the %s employee') % (slip.employee_id.name))
|
||||
line_ids = payslip_line_pool.search(cr, uid, [('slip_id', '=', slip.id), ('code', '=', 'NET')], context=context)
|
||||
if line_ids:
|
||||
line = payslip_line_pool.browse(cr, uid, line_ids, context=context)[0]
|
||||
advice_line = {
|
||||
'advice_id': advice_id,
|
||||
'name': slip.employee_id.bank_account_id.acc_number,
|
||||
'employee_id': slip.employee_id.id,
|
||||
'bysal': line.total
|
||||
}
|
||||
advice_line_pool.create(cr, uid, advice_line, context=context)
|
||||
return res
|
||||
|
||||
hr_payslip_run()
|
||||
|
||||
class payroll_advice_line(osv.osv):
|
||||
'''
|
||||
Bank Advice Lines
|
||||
|
|
|
@ -48,6 +48,20 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_payslip_run_form_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.payslip.run.form.inherit</field>
|
||||
<field name="model">hr.payslip.run</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="hr_payroll.hr_payslip_run_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//button[@string='Set to Draft']" position="after">
|
||||
<button name="create_advice_run" string="Create Advice" type="object" states="close" />
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_bank_advice_tree" model="ir.ui.view">
|
||||
<field name="name">hr.payroll.advice.tree</field>
|
||||
<field name="model">hr.payroll.advice</field>
|
||||
|
|
Loading…
Reference in New Issue