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'll use purchase_order_line as example, but it will work the same for any models.
In my_module/models/purchase_order_line.py (any name will work...)
_inherit = "purchase.order.line"
new_field = fields.Char('my new field')
_inherit = "model" tells us what model you want to inherit. You have to use the _name from the base model. For purchase_order_line, the _name field is set to "purchase.order.line", so i use that.
Then if you want to add the field to a view, you'll need to use view inheritance and xpath. For example, in /my_module/view/purchase.xml:
<?xml version="1.0" encoding="utf-8"?>
<record id="purchase_order_form_inherited" model="ir.ui.view">
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field/tree/field[@name='product_id']" position="before">
in this example, i add the field to the purchase_order_form because it is populated with multiple purchase_order_line that would need the field.
ecord_id can be whatever you want, just use something understandablemodel should be the model from which you want to modify the viewinherit_id should be the XML ID of the view you want to modify (you have to specify the source module)Then, with xpath expression, you "navigate" through your original xml and add, replace, or remove elements. Here, my code will add a field BEFORE the field "product_id" that is into a tree, that is into a field, that is into a page, that is into a notebook, that is into a sheet, that is into the original form :)
Xpath expression may look scary but once you understand how they work, they aren't as hard as it looks.
You can modify the form view or tree view from purchase_order_line in the same way
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: 11/13/15, 5:03 AM|
|Seen: 1071 times|
|Last updated: 12/28/16, 2:35 AM|