Odoo Help

Welcome!

This community 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.

0

Call a v8 function from a v7 function

By
Mathieu Laflamme
on 2/26/16, 9:57 AM 449 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?  

1

Axel Mendoza

--Axel Mendoza--
10228
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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
0
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:

self.pool.get('other_model').get_domain_for_onchange_partner_id(sale_or_picking_id)
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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