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

Hi. How can i add a new field in contact form? I have already this py file but is not working.

from odoo import models, fields, api


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

document_nit = fields.Char(string="NIT", required=True)


Avatar
Zrušit
Autor

Thank you both! I just upgraded the module through CLI , now I have the new field. 

Regards

Nejlepší odpověď

Hi,

This is how we can add fields to any model by inheriting. I think, here you may be facing field does not exist error right ?

 If this is the case and if this happens on adding new field to partner model in an installed module, you should upgrade the module from command line by passing -u module_name

See: https://www.youtube.com/watch?v=c7QL1X3-Zlc

Thanks

Avatar
Zrušit
Nejlepší odpověď

Hi kevin,

For adding a new field in the contact form first inherit the model and add corresponding field to it in python.After that add its view. find its external id of the corresponding view and add it on xml.

For example:

In python:

from odoo import models, fields, api

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

    document_nit = fields.Char(string="NIT", required=True)

In xml:

<?xml version="1.0"?>


<odoo>


    <record id="partner_form" model="ir.ui.view">


         <field name="name">res.partner.form.inherit</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='category_id']" position="after">


              <field name="document_nit"/>


             </xpath>


         </field>


    </record>


</odoo>


Regards

Avatar
Zrušit