Odoo Help

Welcome!

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.

0

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

By
praba
on 11/13/15, 5:03 AM 519 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......

praba
on 11/13/15, 5:06 AM
0
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"?>
<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

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

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

praba
on 11/14/15, 12:36 AM

Hi am able to view UI,Thanks!

praba
on 11/16/15, 8:32 AM

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)

Stats

Asked: 11/13/15, 5:03 AM
Seen: 519 times
Last updated: 11/13/15, 7:21 AM