Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
4504 Visualizzazioni

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?  

Avatar
Abbandona
Risposta migliore

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

 


Avatar
Abbandona
Autore

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?

Autore

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

Autore Risposta migliore

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

Avatar
Abbandona

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)
Autore

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

Autore

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

Post correlati Risposte Visualizzazioni Attività
1
apr 15
8411
2
mar 15
17389
1
mar 15
5414
1
mar 15
3317
3
ago 23
6899