Odoo 8:onchange many2one不工作

时间:2022-07-14 20:23:32

under accounting->invoice I'm trying to trigger the onchange uppon selecting a customer(field: partner_id: many2one) from the list , but it fails, whereas adding the onchange decorator on the field "origin" (type: char) works normally. can anybody help?

在accounting-> invoice下我试图触发onchange uppon从列表中选择一个客户(字段:partner_id:many2one),但它失败了,而在字段“origin”(type:char)上添加onchange装饰器正常工作。有人可以帮忙吗?

NB: in Odoo debugging mode the help message shown upon dragging the mouse on customer field that it's binded to an onchange function called: onchange_partner_id(type,...), I wonder if this is the cause of the issue

注意:在Odoo调试模式下,在客户字段上拖动鼠标时显示的帮助消息是绑定到onchange函数的onchange函数:onchange_partner_id(type,...),我想知道这是否是问题的原因

Here is the code: I inherit from the original invoice model than adding the onchange functions

这是代码:我继承原始发票模型而不是添加onchange功能

class stock_picking(models.Model):
_inherit = "account.invoice"

#NOT triggered
@api.onchange('partner_id')
def _onchange_customer(self):
    print("debug:y_account_invoice: _onchange_customer:selected")

#triggered successfully    
@api.onchange('origin')
def _onchange_origin(self):
    print("debug:y_account_invoice: _onchange_origin")

2 个解决方案

#1


2  

You just need to override this method in py.

你只需要在py中覆盖这个方法。

@api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
    res = super(classname, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice,payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
    #### Update your code 
    # If you want to set any fields value then just simply update it in res and return res
    res['value'].update({'account_id': new_value,})
    return res

onchange_partner_id is already there you need to override it don't define it again. And _onchange_origin working in your case because it's not there already.

onchange_partner_id已经存在,您需要覆盖它,不要再次定义它。 _onchange_origin在你的情况下工作,因为它已经没有了。

#2


1  

I have found an alternative solution to my issue(not ideal). I have overwride the whole function from account_invoice core to my custom module that inherit from it and then added my custom code on it. So that the partner on change function is triggered normally.(omitting the super call)

我找到了一个替代解决方案(不理想)。我已经将整个函数从account_invoice核心覆盖到我继承自它的自定义模块,然后在其上添加了我的自定义代码。这样就可以正常触发更改功能的伙伴。(省略超级呼叫)

  #overwritten function
  @api.multi
  def onchange_partner_id(self, type, partner_id, date_invoice=False,
        payment_term=False, partner_bank_id=False, company_id=False): 
     #KEEP the Core Code
     #custom code
     #add the sales person to the result in case it was not False
     if user_id_sales_per != False:
        print("Debug:account.invoice.onchange_partner_id(): my custom code")

#1


2  

You just need to override this method in py.

你只需要在py中覆盖这个方法。

@api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
    res = super(classname, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice,payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
    #### Update your code 
    # If you want to set any fields value then just simply update it in res and return res
    res['value'].update({'account_id': new_value,})
    return res

onchange_partner_id is already there you need to override it don't define it again. And _onchange_origin working in your case because it's not there already.

onchange_partner_id已经存在,您需要覆盖它,不要再次定义它。 _onchange_origin在你的情况下工作,因为它已经没有了。

#2


1  

I have found an alternative solution to my issue(not ideal). I have overwride the whole function from account_invoice core to my custom module that inherit from it and then added my custom code on it. So that the partner on change function is triggered normally.(omitting the super call)

我找到了一个替代解决方案(不理想)。我已经将整个函数从account_invoice核心覆盖到我继承自它的自定义模块,然后在其上添加了我的自定义代码。这样就可以正常触发更改功能的伙伴。(省略超级呼叫)

  #overwritten function
  @api.multi
  def onchange_partner_id(self, type, partner_id, date_invoice=False,
        payment_term=False, partner_bank_id=False, company_id=False): 
     #KEEP the Core Code
     #custom code
     #add the sales person to the result in case it was not False
     if user_id_sales_per != False:
        print("Debug:account.invoice.onchange_partner_id(): my custom code")