我试着用odoo10执行覆盖,事实是我想给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()
我想将此代码添加到此函数:
^{pr2}$我是这样做的:
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
。在只需更改一个循环:
相关问题 更多 >
编程相关推荐