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

override name_get() works until clicking out of cell

By
tim diamond
on 9/20/13, 7:09 PM 1,784 views

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

1

Acespritech

--Acespritech--
839
| 3 2 6
India
--Acespritech--

Having 8+ years of OpenERP Experience. We are Specialized in OpenERP/CRM Solutions, software development, Web development, E commerce solutions & other open source solutions.


Skype : acespritech

Email : info@acespritech.com

Acespritech
On 9/21/13, 11:04 AM

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

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

tim diamond
on 9/21/13, 4:20 PM

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.

Acespritech
on 9/23/13, 5:06 AM

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

Silviaa
on 11/4/16, 8:20 AM

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: 9/20/13, 7:09 PM
Seen: 1784 times
Last updated: 3/16/15, 8:10 AM