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.
我正在尝试在Invoice中创建按钮来更新inovoice行中的某些字段。我已经找到了如何更新account.invoice中的字段,但我很想找到如何在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.
我确信如何获得与此发票相关的invoice.lines有一些正确的方法?我已经尝试了_inherit account.invoice.line,但后来我无法在那里定义按钮。
Second question - what is best way to call some function every time invoice is created ?
第二个问题 - 每次创建发票时,调用某些功能的最佳方法是什么?
1 个解决方案
#1
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:
如果要添加按钮来更改线条。你需要循环发票中的one2many字段,并将@ api.one更改为@ api.multi,例如:
@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:
如果要调用此函数,每个发票都是创建的,则需要修改create函数:
@api.multi
def create_project(self,values):
res = super(SaleOrder, self).create(values)
res.my_button()
return res
#1
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:
如果要添加按钮来更改线条。你需要循环发票中的one2many字段,并将@ api.one更改为@ api.multi,例如:
@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:
如果要调用此函数,每个发票都是创建的,则需要修改create函数:
@api.multi
def create_project(self,values):
res = super(SaleOrder, self).create(values)
res.my_button()
return res