【发布时间】:2018-07-27 19:16:35
【问题描述】:
我正在尝试使用 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
但是错误是现在只执行了我添加的新代码而没有执行原方法的代码,我不知道如何编辑方法而不是完全取消它。
【问题讨论】:
-
使用 super(ClassName,self).function_name()。如果你想在主代码之后添加你的代码,那么将“super”放在顶部