Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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
The field `x_bla` doesn't exist.
[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?
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.
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 .
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/7/15, 4:30 AM|
|Seen: 2309 times|
|Last updated: 5/11/15, 4:11 AM|