This question has been flagged
2 Replies
6024 Views


Avatar
Discard
Author

Hi am new to odoo , am able to create new modules and workflow transition but i need clarification on customizing existing module using inheritance, can you please help me out......

Best Answer

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...)

class purchase_order_line(Model):
_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"?>
<openerp>
<data>
<record id="purchase_order_form_inherited" model="ir.ui.view">
<field name="name">purchase.order.form.inherited</field>
<field name="model">purchase.order</field>
<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">
<field name="new_field"/>
</xpath>
</field>
</record>
</data>
</openerp>

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

Avatar
Discard
Author

Hi,Thank you which is working....but am not able to see anything on my screen...which means it's not showing any ui

Did you import your models in your module? Did you install your module? Did you updated your module since last change?

Author

Yeah i did that,am able to view the top menu.but while click on that its not responding, and not showing any UI.

Author

Hi am able to view UI,Thanks!