Search code examples
pythonxmlodooodoo-8odoo-15

How to display value of another fields of related field in Odoo form views


is that possible to display value of another fields of related field? For example, by default, in Sale Order, the displayed value of partner_id is the value of partner_id.name .. how if I want to display value of partner_id.mobile instead of their default?

I've tried explicitly declare "partner_id.{FIELD}" like this one below, but the SO model always detects that those fields are not available in the model :

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="sale_order_form_inherit" model="ir.ui.view">
        <field name="name">sale.order.form.inherit</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.sale_order_form"/>
        <field name="arch" type="xml">
            <notebook position="inside">
                <page string="BSP Prinsipal" name="bsp_prinsipal_page">
                    <group>
                        <field name="partner_id.cp_logistik"/>
                        <field name="partner_id.cp_finance"/>
                        <field name="partner_id.cp_marketing"/>
                    </group>
                </page>
            </notebook>
        </field>
    </record>
</odoo>

Thanks in advance, by the way!


Solution

  • You can't use dotted field names in the form view. You can use a related field and remove partner_id from the field name

    Example:

    • Inherit sale order model:

      class SaleOrder(models.Model):
          _inherit = 'sale.order'
      
          cp_logistik = fields.Float(related="partner_id.cp_logistik")
          cp_finance = fields.Float(related="partner_id.cp_finance")
          cp_marketing = fields.Float(related="partner_id.cp_marketing")
      
    • Use related field names in form view:

      <record id="sale_order_form_inherit" model="ir.ui.view">
          <field name="name">sale.order.form.inherit</field>
          <field name="model">sale.order</field>
          <field name="inherit_id" ref="sale.sale_order_form"/>
          <field name="arch" type="xml">
              <notebook position="inside">
                  <page string="BSP Prinsipal" name="bsp_prinsipal_page">
                      <group>
                          <field name="cp_logistik"/>
                          <field name="cp_finance"/>
                          <field name="cp_marketing"/>
                      </group>
                  </page>
              </notebook>
          </field>
      </record>
      

    . You may need to modify the field types