Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
361 Zobrazení

Hello,

In odoo 11, I have a model with a field:

partner_id = fields.Many2one(string='Contact', comodel_name='res.partner')

Some of these contacts have a parent (also a 'res.partner'), e.g. 'A Company'

In the form view, the contact is shown as 'A Company, My Partner'.

How it is possible to show only the partner name without the parent name. In my case, it should be 'My Partner'.

I try :

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

But it doesn't work.


Best regards,


Boris

Avatar
Zrušit
Nejlepší odpověď

Hello , 

Try : 


.py

from odoo import models, fields


class ResPartner(models.Model):

    _inherit = 'res.partner'


    display_name_without_parent = fields.Char(

        string="Contact Name", compute="_compute_display_name_without_parent", store=True

    )

    def _compute_display_name_without_parent(self):

        for rec in self:

            rec.display_name_without_parent = rec.name


.xml


<field name="partner_id" context="{'show_address': 0}" />

<field name="display_name_without_parent" />


Best regards

Avatar
Zrušit