Odoo Help


Call a v8 function from a v7 function

Mathieu Laflamme
on 2/26/16, 9:57 AM 755 views

Is there an easy way to do that?

In fact the deeper problem is that I want to put a damn onchange trigger on partner_id in stock.picking. I realized there is already an onchange on stock.view_picking_form (on_change="onchange_picking_type(picking_type_id,partner_id)"). And this on_change mute the v8 @api.onchange unfortunately. So now I will override the onchange_picking_type method but I don't want to rewrite all my code in v7. Any way to do that?  

Axel Mendoza
On 2/26/16, 11:02 AM

You can just call the override method with super(), This could work for you:

class my_picking_extension(models.Model):

_name = 'stock.picking'

def onchange_picking_type(self, cr, uid, ids, picking_type_id, partner_id, context=None):

values = super(my_picking_extension).onchange_picking_type(cr, uid, ids, picking_type_id, partner_id, context=context):

#change the values

values['value']['field_x'] = 'change value'

return values


I use the same code as you, but I need to call another function from another model that I coded in v8. I don't want to recode it in v7 :( That function is fairly complex and I don't want to have to maintain 2 versions of the same code... one for v7 and one for v8.

Mathieu Laflamme
on 2/26/16, 12:40 PM

what function?

Axel Mendoza
on 2/26/16, 12:42 PM

I put the code down there, for better formatting...

Mathieu Laflamme
on 2/26/16, 2:16 PM
Mathieu Laflamme
On 2/26/16, 2:14 PM

Here is the function I want to call. It is part of another model.

def get_domain_for_onchange_partner_id(self, sale_or_picking_id):

domain = {'carrier_id': [],

'delivery_service_id': []}

if sale_or_picking_id.partner_id.id or sale_or_picking_id.carrier_id.id:

result = self.get_delivery_option_default(sale_or_picking_id.carrier_id, sale_or_picking_id.partner_id)

if result and result["level"]:

default = result['delivery_option_default']

# ignore carrier related default values when defaults come from a carrier itself

if result["level"] != "carrier":

sale_or_picking_id.carrier_id = default.delivery_carrier_id

domain['carrier_id'].append(('id', 'in', default.allowed_carrier_ids.ids))

domain['delivery_service_id'].append(('id', 'in', default.allowed_service_ids.ids))

self.set_default_options(sale_or_picking_id, default)

if sale_or_picking_id.carrier_id.id:

domain['delivery_service_id'].append(('carrier_id', '=', sale_or_picking_id.carrier_id.id))

return domain

I don't get why you couldn't call it? always that you have the value of sale_or_picking_id argument you could simply do it, like:

Axel Mendoza
on 2/27/16, 3:34 AM

Ohhhhhh I tried to call with self.env[""].function_name I think! I'll try monday. Thanks.

Mathieu Laflamme
on 2/27/16, 4:10 AM

Ok I must have forget ", self" in the call to the super function. Now the function get_domain_for_onchange_partner_id gets called. But the dot notation doesn't work since the sale_or_picking_id was loaded as the old API. I need to make a copy of this function to work on V7... Very annoying to be in version 9 and still have to code in V7 :(

Mathieu Laflamme
on 2/29/16, 5:20 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/26/16, 9:57 AM
Seen: 755 times
Last updated: 2/26/16, 2:14 PM