تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
4481 أدوات العرض

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?  

الصورة الرمزية
إهمال
أفضل إجابة

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.

what function?

الكاتب

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

الكاتب أفضل إجابة

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)
الكاتب

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

الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أبريل 15
8388
2
مارس 15
17374
1
مارس 15
5394
1
مارس 15
3312
3
أغسطس 23
6894