Skip to Content
Menu
This question has been flagged
2 Replies
1699 Views

I've been trying to override the default payslip confirm action but it's not showing any changes but Overriding the compute_sheet() function works fine.
I'm I making a mistake that i can't see?? 

class JengaPayslip(models.Model):
    # inherit base payslip model    
    _inherit = "hr.payslip"        
    _description = "Payslip"        

    @api.multi    
    def action_payslip_done(self):        
        month = self.date_from.strftime('%B')        
        year = self.date_from.strftime('%Y')
if self.env['hr.payslip.tracker'].search([('employee_id', '=', self.employee_id.id), ('contract_id', '=', self.contract_id.id), ('month', '=', month), ('year', '=', year)]):
            raise UserError(                
                "The payslip you're trying to confirm has already been confirmed.")

        # Register the payslip in the tracker        
        self.env['hr.payslip.tracker'].create({            
            'slip_id': self.id,            
            'employee_id': self.employee_id.id,            
            'contract_id': self.contract_id.id,            
            'month': month,            
            'year': year,        
        })        
        self.env.cr.commit()

        # Set repaid loan to paid        
        employee_loan = self.env['jenga_hr.employee_loan'].search(            
            [('employee_id', '=', self.employee_id.id), ('state', '=', 'approve')])        
        repayment = self.env['jenga_hr.employee_loan.repayment'].search([('loan_id', 'in', employee_loan.ids), (            
            'state', '=', 'pending'), ('repayment_month', '=', self.date_from.strftime('%B/%Y'))])        
        if repayment:            
            repayment.write({'state': 'paid'})                
        
        self.compute_sheet()        
        return self.write({'state': 'done'})
Avatar
Discard
Best Answer

To know if your overriding is working use logging, for more info:

https://www.odoo.yenthevg.com/logging-in-odoo/

BTW:  action_payslip_done method already override in hr_payroll_account modules 

Avatar
Discard
Author Best Answer

Overriding the action did not produce any result. So i hacked the problem by renaming the confirm action and calling the original function using super.


@api.multi    
def action_jenga_payslip_done(self):
    res = super(HrPayslip, self).action_payslip_done()
    
    # Code you wish to add
    return res
Avatar
Discard