This question has been flagged

Hi community, I want to thank you in advance for taking the time to read my question.

I currently overriding the product name_get(), so that when I'm selecting a product, I can do so by a custom 'part number' defined by me. I don't want this override to affect EVERY view, so I'm using the context in my xml file.

My name_get() looks like this:

def name_get(self, cr, uid, ids, context=None): result = []

if 'my_trigger' in context:
    product_ids = self.pool.get('product.product').browse(cr,uid,ids,context)
    for prod in product_ids:
        result.append((prod.id,str(prod.part_number)))
    return result
else:
    return super(product_product, self).name_get(cr, uid, ids, context=context)

On my purchase order, I have the following xml field, that updates the contex to let my name_get() know that this is a 'special' box:

<field name="product_id" context="{'my_trigger':'1'}"/>

Everything works when I click the dropdown and type through my search. I can select and search by part number. But when I click off the cell, and/or hit the save button, the field reverts to the default name_get value! After doing some research, it looks like something is calling the name_get() function both (1) when I click off a cell, and (2) when I click the save button. Is there a way I can update the context when this happens so that my overriden name_get() knows that it should return the part_number field? Anyone have any suggestions?

Thanks so much,

Tim

Avatar
Discard
Best Answer

Hi,

In you case name_get method of product will call when you selecting any product on the form or list view.

But it will also call when you just refresh your page or change anything in any field where product id is and save that record. So at that time my_trigger will not be there in your context because you are just refreshing page or change in other field not selecting any product. So at that time the super method of product is called.

Thanks,
Acespritech Solutions Pvt. Ltd.
www.acespritech.com
Mail: info@acespritech.com
Skype: acespritech
Blogs: http://acespritechblog.wordpress.com

Avatar
Discard
Author

So is there a way to send a global context in this situation? How can I achieve what I'm trying to do?

The name_get method is generalized. Applying context to the field will not work. I am not sure maybe overriding read() method will solve your problem.

Im in the same situation is read() method solve this problem if solved can you post your answer / idea