Skip to Content
Menu
This question has been flagged
1 Reply
4793 Views

I'm using v10 and I'm trying to add few fields to 'res.partner' and then add the same fields to other forms.

Here are my .py and .xml:

class add_vendor_ship_carrier(models.Model):
    _inherit = 'res.partner'
    ship_carrier = fields.Char('Ship Carrier')
    ship_carrier_account = fields.Char('Ship Carrier Account')

class add_to_sales_order(models.Model):
    _inherit = 'sale.order'
    ship_carrier = fields.Char(related='partner_id.ship_carrier')
    ship_carrier_account = fields.Char(related='partner_id.ship_carrier_account')

class add_to_purchase_order(models.Model):
    _inherit = 'purchase.order'
    ship_carrier = fields.Char(related='partner_id.ship_carrier')
    ship_carrier_account = fields.Char(related='partner_id.ship_carrier_account')
<record id="ship_carrier_supplier_form" model="ir.ui.view"> 
<field name="name">vendor.carrier.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="priority">36</field>
<field name="arch" type="xml">
<field name="property_stock_supplier" position="after">  
<field name="ship_carrier"/>
           <field name="ship_carrier_account"/>  
</field>
</field>
</record>

<record id="ship_carrier_sale_order_form" model="ir.ui.view">
    <field name="name">customer.carrier.sale.order.inherit</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="priority">36</field>
    <field name="arch" type="xml">
        <field name="fiscal_position_id" position="after">
            <field name="ship_carrier"/>
            <field name="ship_carrier_account"/>
        </field>
    </field>
</record>

<record id="supplier_carrier_purchase_order_form" model="ir.ui.view">
<field name="name">supplier.carrier.purchase.order.inherit</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="priority">36</field>
   <field name="arch" type="xml">
<field name="date_planned" position="after">
<field name="ship_carrier"/>
<field name="ship_carrier_account"/>
</field>
</field>
</record>

It added my 2 custom fields to 'res.partner' and to 'sale.order' forms, but not to 'purchase.order' form.

I'm getting the following error:

ValueError: Can't validate view:
Field `ship_carrier` does not exist

I'm trying to use related fields to add them to multiple forms, but it doesn't work for purchase order for some reason. 

What am I doing wrong and what is the easiest way to add a field to multiple forms?

Thanks for help in advance.

Avatar
Discard
Author Best Answer

So one smart man told me that I was getting that error because of this:

<field name="date_planned" position="after">

I was trying to add field in the tree view purchase.order.line \https://github.com/odoo/odoo/blob/10.0/addons/purchase/views/purchase_views.xml#L212

I tried to add them to an existing tabs by using <xpath> and following xml tags like expr="//form/sheet/notebook/page ...", but I failed. So I created a separate tab and put my fields in there. It's not exactly what I wanted, but good enough for now.


Avatar
Discard
Related Posts Replies Views Activity
3
Dec 16
7275
18
Dec 22
34553
1
Nov 19
3888
1
Jun 18
4274
6
Jun 18
4527