From 9133186edafb73e0cabf95f1bde0da3a0762c5b9 Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Fri, 8 Apr 2011 15:00:10 +0530 Subject: [PATCH 1/2] [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 --- addons/hr_payroll/hr_payroll.py | 24 ++++++++++++++++++++---- addons/hr_payroll/hr_payroll_view.xml | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/addons/hr_payroll/hr_payroll.py b/addons/hr_payroll/hr_payroll.py index 5d261a89d9e..c7fdd1cbfd2 100644 --- a/addons/hr_payroll/hr_payroll.py +++ b/addons/hr_payroll/hr_payroll.py @@ -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') diff --git a/addons/hr_payroll/hr_payroll_view.xml b/addons/hr_payroll/hr_payroll_view.xml index e37abd74a0e..9d2a55eef3a 100644 --- a/addons/hr_payroll/hr_payroll_view.xml +++ b/addons/hr_payroll/hr_payroll_view.xml @@ -263,6 +263,7 @@ +