콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
4945 화면
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




아바타
취소

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

베스트 답변

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

아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
5
8월 23
5790
0
7월 15
8305
0
4월 24
1376
0
1월 24
1216
0
9월 22
3495