Vaibhav Bhavsar
Vaibhav Bhavsar

Reputation: 503

Update Last Invoice number in Customer View(res.partner)

I have created a custom module in Odoo. I want to display a read only field in customer view(res.partner form view) where the last invoice id must be updated as soon as a new invoice of that customer is created and validated.

Which method should I refer in account.invoice?

Upvotes: 1

Views: 108

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

In your case, you should override ORM create() method of account.invoice object.

Try with this code.

class AccountInvoice(models.Model):
    _inherit = 'account.invoice'

    @api.model
    def create(self, vals):


        #call super method
        invoice = super(AccountInvoice,self).create(vals)

        #update partner field with lastest created invoice
        invoice.partner_id.your_field_name = invoice.number

        return invoice

For more Odoo technical reference

Upvotes: 1

Related Questions