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

How to add gender, birthdate and oder information to this page

BR

Ricardo Gross

形象
丢弃

if you want to add above fields in existing model than you need inheritance.

http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

最佳答案

Hi Recardo,

You can create custom field by Manually(From GUI) and Custom module(By the Python code).
GUI:

    Go under the Menu: (Settings > Technical > Database Structure > Models).

    Search res.partner model and add field which want you in res.partner form.

    After go under the menu (Settings > Technical > User Interface > Views).

    Search view_partner_form and then add those fields which you have have created manually after lang field.
    <field name="field_name1"/>

    <field name="field_name2"/>

    <field name="field_name3"/>

    After save the Form view and go under the Customer and refresh the page.

Custom Module(Technically):
    Create fields in python file (res_partner.py).

from odoo import api, fields, models, _

class Partner(models.Model):
_inherit = "res.partner"

birth_date = fields.Date('Birth Date')
    gender = fields.Selection([('male', 'Male'),('female', 'Female')], string='Gender')

    Create View File (res_partner_view.xml)

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Inherit partner form view -->
<record id="view_partner_form_inherit" 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">
<field name="lang" position="after">
<field name="birth_date"/>
                    <field name="gender"/>
</field>
</field>
</record>

 Hope this will help you.

Thanks.

形象
丢弃
编写者 最佳答案

Perfect, thank you very much for your answers !! :-)

BR

Ricardo

形象
丢弃
最佳答案

you can achieve this using inheritance:

model.py

class groups(models.Model):
 _inherit = 'res.groups'
 # we inherited res.groups model which is Odoo/OpenERP built in model and created two fields in that model.
 field_1 = fields.Char(required=True,string="Field One")
 field_2 = fields.Boolean(default=False,string="Field Two")  

xml

<openerp>
    <data>
        <record model="ir.ui.view" id="res_group_form_view_inherited">
            <field name="name">res.group.form.view.inherited</field>
            <field name="model">res.groups</field>
            <field name="inherit_id" ref="base.view_groups_form" />
            <!-- <field name="groups_id" eval="[(6, 0, [ref('obe_core.obe_coordinator')])]"/> -->
            <field name="priority" eval="15"/>
            <field name="arch" type="xml">

                <xpath expr="//field[@name='name']" position="after">
                    <field  name="field_1"/>
                </xpath>                
                
                <xpath expr="//field[@name='user_name']" position="after">
                    <field  name="field_2"/>
                </xpath>        

            </field>                               
        </record>
    </data>
</openerp> 


形象
丢弃
最佳答案

Hi Ricardo Gross,
Actually, I did not get your requirement correctly,
If you want to add extra information in contacts (res.partner) you just do one thing,
Just inherits the form [ base.view_partner_form]

add the new field that you need in res.partner. and don't forget to add the fields in python files too.
Thank you.

形象
丢弃
相关帖文 回复 查看 活动
1
10月 25
2092
2
7月 25
1364
1
9月 24
1813
2
4月 22
3637
2
3月 15
8133