跳至内容
菜单
此问题已终结
2 回复
4813 查看

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)


形象
丢弃
编写者

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

Regards

最佳答案

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

形象
丢弃
最佳答案

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

形象
丢弃