Odoo Help


How to inherit existing purchase module and PO field info for the new module? can you give any simple example?

on 11/13/15, 5:03 AM 1,444 views

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

on 11/13/15, 5:06 AM
Jerome Guerriat
On 11/13/15, 7:12 AM

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"?>
<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"/>

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

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

on 11/13/15, 7:56 AM

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

Niboo SPRL, Jerome Guerriat
on 11/13/15, 10:17 AM

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

on 11/14/15, 12:36 AM

Hi am able to view UI,Thanks!

on 11/16/15, 8:32 AM

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/13/15, 5:03 AM
Seen: 1444 times
Last updated: 12/28/16, 2:35 AM