Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
587 Vistas

Hi everyone,

I'm trying to set up different fields in Odoo contacts depending on whether a contact is a company or an individual.

Specifically, if the contact is a company, I would like to display additional fields such as founding date, industry, etc. These fields should not appear at all when the contact is an individual.

Thanks in advance!

Avatar
Descartar

This app - https://apps.odoo.com/apps/modules/18.0/partner_custom_fields - lets you add different fields for different custom types. These custom fields are not restricted by the individuals/companies, but you may use your own typology. So, the app might be helpful to your goals.

Mejor respuesta


Correct approach:

  • For fields visible only for companies: [('is_company', '=', False)] in the invisible attribute
  • For fields visible only for individuals: [('is_company', '=', True)] in the invisible attribute

The invisible attribute hides fields when the condition is TRUE. So:

  • [('is_company', '=', False)] means "hide when NOT a company" = "show only for companies"
  • [('is_company', '=', True)] means "hide when IS a company" = "show only for individuals"
  • Hope it helps you.


Avatar
Descartar
Mejor respuesta

Hi,

You can achieve this in Odoo by using field visibility conditions based on the is_company boolean field in the res.partner model.


Sample Code:

Python:

from odoo import fields, models

class ResPartner(models.Model):
_inherit = 'res.partner'

founding_date = fields.Date(string="Founding date")
industry = fields.Char(string="Industry")

XML:

<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.view.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='vat']" position="after">
<field name="founding_date" invisible="not is_company"/>
<field name="industry" invisible="not is_company"/>
</xpath>
</field>
</record>

Result:

In Company:

In Individual:


Hope it helps.

Avatar
Descartar
Mejor respuesta

Hi Elvira,

You can set this up either through Odoo Studio or through Code Customization by using invisible attribute on the fields So, for the fields you want to be visible only if the contact is a company ,set "[('is_company', '=', False)]" in invisible attributes and for fields you want to be visible only if the contact is individual, set "[('is_company', '=', True)]".

We hope this helps! In case you need further assistance, you can reach out to us!

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
abr 25
384
1
jun 25
1072
1
may 25
1294
3
mar 25
1966
1
mar 25
1490