This question has been flagged

Hello Friends,

I am new to Odoo and I really need your guidance.

In Purchase Order Lines I need the name of the product without the Internal Reference Number as currently it shows the (Internal Reference Number+Product Name).

I know that in the Model "product.template" there is a field name which is the Actual Name of the Product (minus -) the Internal Reference  so this is the field I want to Display On Purchase Order Lines.

So what I did was the following:
1. I created a new field in model "purchase.order.line"
​x_product_tmpl_id = fields.Many2one('product.template')

2.Then I created another field  Related Field in model "purchase.order.line" as follows:
x_name = fields.Char(string='Name', related='x_product_tmpl_id.name')​

Now the issue is that instead of showing the Product Name its showing Blank.

Can anyone please point out my mistake and suggest the correct way to do it.

Thanks

Sincerely,

Asad

Avatar
Discard

"Related Field | V11CE |" is not a question. I have edited your post to have a Question in the Title. Please consider posting a Question in the Title to increase your chances of visitors opening/answering your post. I moved V11CE to the TAG area of the post, as that is best practice.

Author

Thanks Ray, Next time I will be more careful.

Best Answer

Hi Asad:

You probably don't need to define x_product_tmpl_id as the model already has a field called product_id.

Change the definition of x_name to the following and it should work.

x_name = fields.Char(string='Name', related='product_id.name')​
Avatar
Discard
Author

Hello Paresh,

Thanks for your reply.

Its working now , but I have one question the way I created the related field is the method correct? Because with what I did its still showing blank data?

I am asking because in this model there was already an existing field product_id, but may be in any new custom model this field wont be there so if I need to copy the value to the new model how would I do it?

Please reply.

Thanks

Hi Asad: Your approach looks good to me. The only other attribute you may want to add to your field declaration is readonly=True, if you are interested in only displaying the name on the screen.

If this was to be done on a model without the product_id field, you would need to first figure out how to establish the relationship between the model and the Product Template or Product Variant model. It's difficult to provide a generic answer to this part of the question because it would depend on the requirements you are trying to address.

Hope that helps. Please click on the check mark next to the answer to mark it as resolved if it solved your issue, so that it helps others in the future too.

Author

Thanks, I tried to click corrected answer but it was already resolved.

Anyways thanks for taking out your precious time to help me.