Odoo Help


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.


Howto add custom product attribute to purchase.order.form view

Thomas Klosinsky
on 5/7/15, 4:30 AM 1,364 views

I am trying to add a new column of product data (product.template model) to purchase.order.form view.

The column should contain a custom attribute like x_bla.

When using just the "usual way" by adding: <field name="x_bla"/> I am getting an error:

Field(s) `arch` failed against a constraint: Ungültige Ansichtendefinition

Error details:

The field `x_bla` doesn't exist.

Fehler Kontext:

Ansicht `purchase.order.form`

[view_id: 789, xml_id: purchase.purchase_order_form, model: purchase.order, parent_id: k. A.]

So I need to add a field into purchase.order model and connect it to my custom attribute... but how does that work?

Any hints in the right direction?

@Frederico. The attribute is from product.template model. I assume you added the attribute to purchase.order model? So my next question would be how to link an attribute from purchase.order to product.template...?

Thomas Klosinsky
on 5/9/15, 6:17 PM

Then you create a field just using the Odoo GUI. I'm afraid, but you need a little bit of python to inherit the fields list, using fields.related on product.py and/ or on purchase.py. What kind of field is your "x_bla"? Is already populated or can be substitute with a field created on model .py? I'm not the best expert around here but tomorrow I'll test the code on my dev-server.

on 5/10/15, 9:39 AM

Unfortunately yes. I looked into the purchase.py and found the product_id field with related info to product.product and tried to do the same for my custom attribute but it didn't work. I also think that a custom module for adding an attribute and relations to the models there would be more promising... I'm looking forward to any help with this. Would be my first module to write "by myself"... so any help appreciated...

Thomas Klosinsky
on 5/10/15, 10:10 AM

Thomas, if the field is already populated you can easily resolve with a simple export and a batch input. I'm not a big fan of creation of fields inside odoo, it's better to create a new module for inherit the models and views you need. If you don't know, you could create an empty module ready to be filled with your information with the command [code] python odoo.py scaffold addons [/code]. In that way you will have a correct layout. I'll have a look on server and then I'll update my post.

on 5/10/15, 5:32 PM

thank you akhil, I just tried to do so. check out here: https://github.com/thomasklosinsky/product_kunstler But still having errors. I think the related field in .py is not correctly set and the view in .xml also... Help appreciated!

Thomas Klosinsky
on 5/11/15, 4:11 AM

Akhil P Sivan

--Akhil P Sivan--
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 5/11/15, 2:30 AM

Hi Thomas,

You can inherit product.template model and the field "x_bla". And you want that field in purchase order means, it should appear as a column in the product lines, right?

So you need to add one more field in "purchase.order.line" model.And you have to override the onchange_product_id function in that model. That means when you are adding a product in purchase order, along with product description, qty, unit price etc, our "x_bla" field value will also get filled.

In view file, you need to inherit the tree view of purchase.order.line and add your "x_bla" field also.

If you are working with odoo v8 new api, one more easier way is to define a related field in "purchase.order.line" model.

Eg:  field_name = field.Char(related="product_id.x_bla", string="New field") #if your x_bla is a char field.

And then add this field to the tree view of purchase.order.line, by inheriting and using xpath.

But prefer the first method ;)

If you have any doubts in code or something related to this, I can help you to understand the things better.

I found the new API a little complicated to manage when you are working on "stock" py, better create a new module just for inherit models. On point_of_sale.py for example using the new api format always give me errors.

on 5/12/15, 10:38 AM
On 5/9/15, 5:38 PM

Please verify if the field "x_bla" was correctly created. I tested it right now on purchase.order.form (purchase.order) and is working fine.

For my test I've created a char(255) field named "x_bla" on purchase.order model always searchable and I've successfully added it under <field name="date_order"/> on purchase.order.form view .

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)


Asked: 5/7/15, 4:30 AM
Seen: 1364 times
Last updated: 5/11/15, 4:11 AM