Odoo Help


How to add a new field in a class from another which is already inherited ?

Maurice Agée
on 9/25/15, 5:47 AM 618 views

First, I created the class 'product_template' inherit to add the field 'new_field'

class product_template(osv.osv):

_name = 'product.template'
_inherit = 'product.template'

_columns = {
'new_field': fields.many2one('product.uom','Unité de Stockage',required=True, ondelete='cascade'),

After, the xml

    <record id="purchase_order_form" model="ir.ui.view">

<field name="name">purchase_order_form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field eval="90" name="priority"/>
<field name="arch" type="xml">
		<xpath expr="/form[@string='Purchase Order']/sheet/notebook/page[@string='Products']/field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='price_unit']" position="before">

<field name="new_field_po" string="U Stock"/>

And the new py

class purchase_order_line(osv.osv):

_name = 'purchase.order.line'
_inherit = 'purchase.order.line'
_columns = {
'new_field_po': fields.related('product','new_field',type='many2one',relation='product.product',string='Title',store=True),

The creation of new_field is correct in the product_template.

But when I create a PO, this does not work, the line does not take the value of the field, it remains empty

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: 9/25/15, 5:47 AM
Seen: 618 times
Last updated: 9/25/15, 5:47 AM