コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
4489 ビュー

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
4月 15
8397
2
3月 15
17380
1
3月 15
5397
1
3月 15
3316
3
8月 23
6897