how to add a field in res.partner in open erp

五迷三道 提交于 2019-12-22 19:41:59

问题


I'm new to OpenErp. I want to Add a new field "mother_name" in res.partner.So i have added the following code to res.partner.py In column's i have add like this

_columns = {
    'name': fields.char('Name', size=128, required=True, select=True),
    'date': fields.date('Date', select=1),
    'title': fields.many2one('res.partner.title', 'Title'),
    'parent_id': fields.many2one('res.partner', 'Related Company'),
    'child_ids': fields.one2many('res.partner', 'parent_id', 'Contacts', domain=[('active','=',True)]), # force "active_test" domain to bypass _search() override    
    'ref': fields.char('Reference', size=64, select=1),
    'date_delivery': fields.date('Expected Delivery Date'),
    'mother_ln': fields.char('Mother', size=64),
     .
     .
     .
     }

Now in res_partner_view.xml . I'm using the following code

        <record id="view_partner_tree" model="ir.ui.view">
            <field name="name">res.partner.tree</field>
            <field name="model">res.partner</field>
            <field eval="8" name="priority"/>
            <field name="arch" type="xml">
                <tree string="Contacts">
                    <field name="name"/>
                    <field name="function" invisible="1"/>
                    <field name="phone"/>
                    <field name="email"/>
                    <field name="user_id" invisible="1"/>
                    <field name="is_company" invisible="1"/>
                    <field name="country" invisible="1"/>
                    <field name="country_id" invisible="1"/>
                    <field name="date_delivery"/>
                    <field name="mother_ln"/>
                    <field name="parent_id" invisible="1"/>
                </tree>
            </field>
        </record>


<record id="view_partner_form" model="ir.ui.view">
            <field name="name">res.partner.form</field>
            <field name="model">res.partner</field>
            <field eval="1" name="priority"/>
            <field name="arch" type="xml">
                <form string="Partners" version="7.0">
                <sheet>
                    <field name="image" widget='image' class="oe_left oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
                    <div class="oe_title">
                        <div class="oe_edit_only">
                            <label for="name"/> (
                            <field name="is_company" on_change="onchange_type(is_company)" class="oe_inline"/> <label for="is_company" string="Is a Company?"/>)
                        </div>
                        <h1>
                            <field name="name" default_focus="1" placeholder="Name" />
                        </h1>
                        <field name="parent_id"
                            placeholder="Company"
                            domain="[('is_company', '=', True)]" context="{'default_is_company': True, 'default_supplier': supplier}"
                            attrs="{'invisible': [('is_company','=', True),('parent_id', '=', False)]}"
                            on_change="onchange_address(use_parent_address, parent_id)"/>
                        <!-- <field name="category_id" widget="many2many_tags" placeholder="Tags..."/> -->
                    </div>
                    <div class="oe_right oe_button_box" name="buttons"> </div>

                    <group>
                        <group>
                            <label for="type" attrs="{'invisible': [('parent_id','=', False)]}"/>
                            <div attrs="{'invisible': [('parent_id','=', False)]}" name="div_type">
                                <field class="oe_inline"
                                    name="type"/>
                            </div>

                            <label for="street" string="Address"/>
                            <div>
                                <field name="use_parent_address" class="oe_edit_only oe_inline"
                                       on_change="onchange_address(use_parent_address, parent_id)"
                                       attrs="{'invisible': [('parent_id','=', False),('use_parent_address','=',False)]}"/>
                                <label for="use_parent_address" class="oe_edit_only" attrs="{'invisible': [('parent_id','=', False),('use_parent_address','=',False)]}"/>
                                <button name="open_parent" type="object" string="(edit company address)" class="oe_link oe_edit_only"
                                        attrs="{'invisible': ['|',('parent_id','=', False),('use_parent_address','=',False)]}"/>
                                <field name="street" placeholder="Street..."  attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                                <field name="street2"  attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                                <div class="address_format">
                                    <field name="city" placeholder="City" style="width: 40%%" attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                                    <field name="state_id" class="oe_no_button" placeholder="State" style="width: 37%%" options='{"no_open": True}' on_change="onchange_state(state_id)" attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                                    <field name="zip" placeholder="ZIP" style="width: 20%%" attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                                </div>
                                <field name="country_id" placeholder="Country" class="oe_no_button" options='{"no_open": True}' attrs="{'readonly': [('use_parent_address','=',True)]}"/>
                            </div>

                        </group>
                        <group>
                          <!-- We Don't require Job Position for Customer -->
                          <!--   <field name="function" placeholder="e.g. Sales Director"
                                attrs="{'invisible': [('is_company','=', True)]}"/> -->
                            <field name="phone" placeholder="e.g. +32.81.81.37.00"/>
                            <field name="mobile"/>
                            <field name="fax"/>
                            <field name="email" widget="email"/>
                            <!-- <field name="title" domain="[('domain', '=', 'contact')]"
                                options='{"no_open": True}' attrs="{'invisible': [('is_company','=', True)]}" /> -->
                        </group>
                        <field name="date_delivery"/>
                        <field name="mother_ln"/>
                        </group>
                        .
                        .
                        .
                 </record>

回答1:


Better is you inherit that code and add your field rather doing changes to main code.
for your py file 

class res_partner(osv.osv):

 _inherit= 'res.partner'

 _columns = {
     'mother_ln': fields.char('Mother', size=64),
     'father_name': fields.char('Father', size=64),
 # this is comment. -> you can add as many types of fields as you want - eg. char ,
    #                   boolean, float, integer, one2many, many2one etc. 
 }

res_partner()


for your xml file :-

<record id="view_res_partner_inherited" model="ir.ui.view">
  <field name="name">view.res.partner.inherited</field>
  <field name="model">res.partner</field>
  <field name="inherit_id" ref="base.view_partner_form" />
  <field name="arch" type="xml">
    <field name="date_delivery" position="after">
        <field name="mother_ln" />
        <field name="father_name" />
<!--comment- likewise this is your view, add all your fields here in view -->
    </field>
  </field>
</record>


来源:https://stackoverflow.com/questions/21325582/how-to-add-a-field-in-res-partner-in-open-erp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!