Search code examples
pythonxmlodooodoo-13

Odoo how to display many2one inside of order form


I starting to learn odoo framework.

I am trying to display carrier_id which lives inside of sale.order model diplay inside of the "sale.view_order_form"

Error I get "carrier_id doesnt exist"

Here its my code, I hope someone can help me to understand.

PYTHON

from odoo import fields, models

    class carrierId(models.Model):
        _inherit = 'delivery.carrier'
    
        #add incoming carrier information
        carrier_id = fields.Many2one('delivery.carrier', 'Carrier',)

XML:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record model="ir.ui.view" id="product_form_add_carrier">   
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form" />      
        <field name="arch" type="xml">      
                <field name="pricelist_id" position="after">
                    <field name="carrier_id"/>
                </field>    
        </field>    
    </record>   
</odoo>

  

Solution

  • The XML adds the carrier_id field to the sale.ordermodel.

    But the model change is adding the carrier_id field to the delivery_carrier model, not sale.order.

    You probably want o add the fields to the sale.ordermodel instead.

    By the way, the module delivery already does that, so you should consider installing it instead.