0
votes

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?

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

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

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

2 Answers

2
votes

You just need to override this method in 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.

1
votes

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)

  #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")