Skip to Content
Menu
This question has been flagged
2 Replies
4645 Views
I have written Model class for Customer in custom_addon/medicine/models directory 
for add new field in customer view

buyer.py
from odoo import api, fields, models
class Buyer(models.Model):
_inherit = "res.partner"
buyer_name = fields.Char(string='Buyer Name', required=True)

And In __manifest__.py I want to add depends modules for customer however I am not able

to find what should I add in following attribute depends to inherit Customer View and add new fields.

'depends': [''],

I have tried following ref: https://www.youtube.com/watch?v=3iY3ea-wvjw




Avatar
Discard

Inheritance in model and views: https://goo.gl/4Zyc9d

Best Answer

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

Avatar
Discard
Best Answer

find the module in which the res.partner model is created. In this case: 'depends': ['contacts']

Avatar
Discard
Related Posts Replies Views Activity
5
Aug 23
5433
0
Jul 15
7949
0
Apr 24
1160
0
Jan 24
1085
0
Sep 22
3293