[IMP] Payroll: define a new field.boolean on payslip: 'credit note'

on a 'done' payslip, add a button 'make a credite note' that will duplicate the current payslip with 'credit note' = True, confirm and done it.

bzr revid: mra@mra-laptop-20110408093010-qgkeiy7wud1exwgd
This commit is contained in:
Mustufa Rangwala 2011-04-08 15:00:10 +05:30
parent c9a30f97ae
commit 9133186eda
2 changed files with 22 additions and 4 deletions

View File

@ -68,10 +68,12 @@ class hr_payroll_structure(osv.osv):
@return: returns a id of newly created record
"""
default = {
if not default:
default = {}
default.update({
'code': self.browse(cr, uid, id, context=context).code + "(copy)",
'company_id': self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
}
})
return super(hr_payroll_structure, self).copy(cr, uid, id, default, context=context)
def get_all_rules(self, cr, uid, structure_ids, context=None):
@ -250,6 +252,7 @@ class hr_payslip(osv.osv):
'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}),
'note': fields.text('Description'),
'contract_id': fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}),
'credit_note': fields.boolean('Credit Note', help="It indicates that the payslip has been refunded", readonly=True),
#TODO put me back
# 'details_by_salary_head': fields.function(_get_salary_rules, method=True, type='one2many', relation='hr.salary.rule', string='Details by Salary Head', multi='details_by_salary_head'),
}
@ -257,14 +260,17 @@ class hr_payslip(osv.osv):
'date_from': lambda *a: time.strftime('%Y-%m-01'),
'date_to': lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],
'state': 'draft',
'credit_note': False,
'company_id': lambda self, cr, uid, context: \
self.pool.get('res.users').browse(cr, uid, uid,
context=context).company_id.id,
}
def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
default = {
default.update({
'line_ids': [],
'move_ids': [],
'move_line_ids': [],
@ -273,7 +279,7 @@ class hr_payslip(osv.osv):
'period_id': False,
'basic_before_leaves': 0.0,
'basic_amount': 0.0
}
})
return super(hr_payslip, self).copy(cr, uid, id, default, context=context)
def set_to_draft(self, cr, uid, ids, context=None):
@ -291,6 +297,16 @@ class hr_payslip(osv.osv):
def process_sheet(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'paid': True, 'state': 'done'}, context=context)
def refund_sheet(self, cr, uid, ids, context=None):
wf_service = netsvc.LocalService("workflow")
for id in ids:
id_copy = self.copy(cr, uid, id, {'credit_note': True}, context=context)
self.compute_sheet(cr, uid, [id_copy], context=context)
wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'verify_sheet', cr)
wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'final_verify_sheet', cr)
wf_service.trg_validate(uid, 'hr.payslip', id_copy, 'process_sheet', cr)
return True
def verify_sheet(self, cr, uid, ids, context=None):
#TODO clean me: this function should create the register lines accordingly to the rules computed (run the compute_sheet first)
# holiday_pool = self.pool.get('hr.holidays')

View File

@ -263,6 +263,7 @@
</page>
</notebook>
<field name='credit_note' />
<group col="10" colspan="4">
<field name="state"/>
<button string="Cancel" icon="terp-dialog-close" name="cancel_sheet" states="draft,hr_check,confirm"/>
@ -271,6 +272,7 @@
<button string="Approve Sheet" icon="terp-camera_test" name="final_verify_sheet" states="hr_check"/>
<button string="Pay Salary" icon="terp-dolar_ok!" name="process_sheet" states="confirm"/>
<button string="Set to Draft" icon="terp-stock_effects-object-colorize" name="set_to_draft" states="cancel"/>
<button string="Refund" icon="gtk-execute" name="refund_sheet" states="done" type='object'/>
</group>
</form>
</field>