Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
4834 Näkymät

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
Hylkää
Tekijä

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

Regards

Paras vastaus

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
Hylkää
Paras vastaus

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
Hylkää