Hi ,
To add a new field to the Customer (i.e., res.partner) form view, you're on the right track by inheriting the model and extending the existing view. Here’s how you can do it:
1. Python Model
You've already done this part correctly. Your model should look like:
python
from odoo import api, fields, models
class Buyer(models.Model):
_inherit = "res.partner"
buyer_name = fields.Char(string='Buyer Name', required=True)
2. XML View Inheritance
Now, to show this field on the customer form, you can inherit the standard res.partner form view like this:
xml
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.inherit.buyer.name</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='barcode']" position="after">
<field name="buyer_name"/>
</xpath>
</field>
</record>
Here, we’re adding the buyer_name field right after the existing barcode field. You can adjust the position depending on where you'd like it to appear.
3. Manifest File
To ensure your module loads the correct dependencies, add the following to your __manifest__.py:
python
'depends': ['contacts'],
This is important because the customer view (res.partner) is defined in the contacts module.
Hope it helps
Inheritance in model and views: https://goo.gl/4Zyc9d