[英]create inherit override odoo
我正在嘗試使用odoo 10進行覆蓋,事實是我想向odoo的現有方法添加功能,但我不知道該怎么做,我已經添加了高級功能,但是行為不適當
驗證odoo底部的原始方法:
@api.multi
def action_invoice_open(self):
# lots of duplicate calls to action_invoice_open, so we remove those already open
to_open_invoices = self.filtered(lambda inv: inv.state != 'open')
if to_open_invoices.filtered(lambda inv: inv.state not in ['proforma2', 'draft']):
raise UserError(_("Invoice must be in draft or Pro-forma state in order to validate it."))
to_open_invoices.action_date_assign()
to_open_invoices.action_move_create()
return to_open_invoices.invoice_validate()
我想將此代碼添加到此函數:
print('enter')
Replique = self.env['dues.replique']
new = Replique.create({
're_customer': self.partner_id.id,
'amount_invoice':self.amount_total,
'amount_total':self.t_invoice_amount,
'n_invoice' : self.number,
})
而且我這樣做是這樣的:
class AddFields(models.Model):
_inherit = "account.invoice"
@api.model
def action_invoice_open(self):
print('enter')
Replique = self.env['dues.replique']
new = Replique.create({
're_customer': self.partner_id.id,
'amount_invoice':self.amount_total,
'amount_total':self.t_invoice_amount,
'n_invoice' : self.number,
})
campus_write = super(AddFields,self).action_invoice_open()
return campus_write
但是錯誤是,現在僅執行我添加的新代碼,並且不執行原始方法的代碼,我不知道如何編輯該方法而不是完全取消該方法。
您的方法還不錯;-)
origin方法使用api.multi
作為裝飾器,請勿在擴展名中進行更改。 api.model
將使其成為非實例/記錄集方法,因此超級調用將使用空記錄集完成,這將導致未進行任何驗證。
另外:您的擴展程序僅在將驗證一張發票的情況下起作用。 但是,一張以上的發票會怎樣? 這將引發“預期的單例”錯誤,因為self
不會是Singleton
。
因此,只需將其更改為循環:
@api.multi # don't change it to another decorator
def action_invoice_open(self):
Replique = self.env['dues.replique']
for invoice in self:
Replique.create({
're_customer': invoice.partner_id.id,
'amount_invoice':invoice.amount_total,
'amount_total':invoice.t_invoice_amount,
'n_invoice' : invoice.number,
})
result = super(AddFields, self).action_invoice_open()
return result
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.