继承我的自定义模块中的现有视图(view_partner_form)

时间:2017-07-28 10:20:46

标签: inheritance openerp odoo-9

我必须从base模块中的res.partner模型继承view_partner_form,我需要在自定义模块中的联系表单(view_partner_form)中添加一些额外的字段,但我试过这个影响是我的额外字段添加正确但UI完全崩溃

这是我的python代码:

class Residents(models.Model):
    _inherit = "res.partner"
    _name = "residents.details"

    f_no = fields.Char()
    id_proof = fields.Selection([('aadhar_card','Aadhar Card')],string = "Id Proof")
    id_no = fields.Char(string = "Id no")

xml代码:

 <record id = "add_field_view_partner_form" model = "ir.ui.view">
        <field name = "name">add.fields</field>
        <field name = "model">residents.details</field>
        <field name = "inherit_id" ref = "base.view_partner_form"/>
        <field name = "arch" type = "xml">
            <field name = "city" position="before">
               <field name = "f_no" placeholder = "Flat No"/>
            </field>
            <field name = "lang" position="after">
               <field name = "id_proof" />
            </field>
            <field name = "id_proof" position="after">
                <field name = "id_no" />
            </field>
        </field>
    </record>

更新

请找ScreenShot

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

首先,屏幕截图是odoo生成的一个表单,它包含 两列布局中的所有字段。当你的模特没有时,odoo会这样做 任何形式的视图。聪明的odoo ^^。

如果您继承了更改了模型名称的视图,那么您处于相同的情况!!

    <record id = "add_field_view_partner_form" model = "ir.ui.view">
            <field name = "name">add.fields</field>
            <!-- you should keep the same name res.partners -->
            <!-- in this code you removed the model name and most 
            lickly this is why you lost the the view and this is why
            odoo is showing you the generated form view -->
            <field name = "model">residents.details</field>
            <field name = "inherit_id" ref = "base.view_partner_form"/>
            <field name = "arch" type = "xml">