0

I am trying to create button in Invoice that will update certain field in inovoice lines. I've found how to update field in account.invoice but I am strugling to find right way how to update it in account.invoice.line.

class accountinvoiceext(models.Model):
    _inherit = ['account.invoice']
    @api.one
    def my_button(self,uid):
        invoice_id = self.id
        #lines = getinvoicelinesbyid(invoice_id)

I am sure there is some proper way how to get invoice.lines related to this invoice, or not ? I've tried _inherit account.invoice.line but then I cannot define button there.

Second question - what is best way to call some function every time invoice is created ?

1 Answers1

0

if you want to add button to change the line. you need to loops the one2many fields in the invoice, and change @api.one to @api.multi, example:

@api.multi
def my_button(self):
    for line in self.invoice_line:
         line.write({'your_field': 'your_values'})

and if you want to call this function every invoice is create, you need to modified the create function:

@api.multi
def create_project(self,values):
    res = super(SaleOrder, self).create(values)
    res.my_button()
    return res
Rinaldi
  • 260
  • 3
  • 9