Skip to Content
Menu
This question has been flagged
2 Replies
2791 Views

so i'm trying to add new fields to show up when you create a new contact, with the name, adress, tax ID ...

so i created a custom module called custom_contact this is my models/contacto.py
 and i changed the contacts_view.xml in the odoo contacts module to use my custom module 


   

        Contacts

        ir.actions.act_window

        custom_contact.contacto

        kanban,tree,form,activity

       

        {'default_is_company': True}

       

         

            Create a Contact in your address book

         

            Odoo helps you track all activities related to your contacts.

         

       

   



when i go to create a new contact and i hover on one of the fields i see that Model is : custom_contact.contacto

now how i can add those fields and make them visible

	​
from odoo import models, fields

class Contacto(models.Model):   
_name = 'custom_contact.contacto'   
_inherits = {'res.partner': 'partner_id'}   
_description = 'Contacto'   
   
# Custom fields   
nis = fields.Char(string='NIS')   
nif = fields.Char(string='NIF')   
ai = fields.Char(string='AI')   
rc = fields.Char(string='RC')
partner_id = fields.Many2one('res.partner', required=True, ondelete='restrict', auto_join=True, index=True,        string='Related Partner', help='Partner-related data of the user')

# Inherit existing Many2many fields   
channel_ids = fields.Many2many(comodel_name='res.partner',        relation='res_partner_channel_rel',column1='partner_id', column2='channel_id',        string='Channels')
meeting_ids = fields.Many2many(comodel_name='res.partner',        relation='res_partner_meeting_rel', column1='partner_id', column2='meeting_id',        string='Meetings')

Avatar
Discard
Best Answer

Hi,

If you need to add new fields in the contacts module , you need to inherit the model "res.partner" model instead of "res.users"

example:

class ResPartner(model.Models):

    _inherit ="res.partner"


nis = fields.Char(string='NIS')

    nif = fields.Char(string='NIF')  

    ai = fields.Char(string='AI')  

    rc = fields.Char(string='RC')


And inherit the form of the "res.partner" to add the fields in the form view


<record id="view_partner_form" model="ir.ui.view">
        <field name="name">
view.partner.form.inherit.res.partner
        </field>
<field name="model">helpdesk.ticket</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <field name="name" position="after">
                <field name="nis" i" />
                <field name="nif" "/>

                 <field name="ai" "/>

                <field name="rc" "/>
            </field>
        </field>
    </record>

Hope it helps

Avatar
Discard
Best Answer

I have so advice on your code like this:

1. If you only need to add field and display in for a partner, you should use _inherit instead of _inherits.

2. To add your new fields in the formview of contact, you just need to do exactly like this https://github.com/odoo/odoo/blob/128475bf2ac966f98f488833e5ff781312055b76/addons/base_address_extended/views/base_address_extended.xml#L61

Then remember to load in manifest sir and to make it invisible, add this invisible="1" for the fields you want it to be invisible.

Hope this help sir.

Avatar
Discard