コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
10497 ビュー

I'm using Odoo v10 and I'm trying to customize existing view (base.view_partner_form). Here are my model and view:

class add_supplier1099(models.Model):
    # _name = 'add.supplier1099'     
    _inherit = ['res.partner']     
    _description = "Add Checkbox and TaxID Field if Supplier Requires 1099"    
    supp_test_field = fields.Char(string="test field")
<odoo>      
    <data>
        <record id="add_supplier1099_view_inherit" model="ir.ui.view">
        <field name="name">res.partner.form</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='phone']" position="after">                
                <field name="supp_test_field"/>     
            </xpath>
        </field>        
        </record>    
    </data>
</odoo>

This code works and it adds "supp_test_field" to the form. But if you uncomment # _name = 'add.supplier1099' (I thinks it should add my new field to an existing table of "res.partner" model) it'll through an error:

ValueError: Can't validate view:
Field `supp_test_field` does not exist

I also tried to go with "_name = res.partner" (I thinks it should create a new table with my new field and fields from res.partner model), but I was getting the same error. Any ideas why i'm getting this error in the above cases and not getting an error when I comment out "_name" attribute?

アバター
破棄
最善の回答

When you declare '_name' attribute with '_inherit' you're creating a new model which gets all fields of the inherited one. in this case you have to use the new model name to call it from the view.

But when you use only '_inherit' attribute your model replace the original one 'res.partner', this is why you can call it with 'res.partner' model name from the view.

The error is because you created a new model ( add.supplier1099 = res.partner + supp_test_field) and you're calling supp_test_field from the 'res.partner' view, which doesn't exist.

So for you're purpose, if you'd like to use 'add.supplier1099' name instead of 'res.partner'. Just replace model name in the view :

<field name="model">add.supplier1099</field>

hope this helps.

regards.


アバター
破棄
最善の回答

View Inheritance and xpath locators (position attribute): Odoo Inheritance

アバター
破棄
関連投稿 返信 ビュー 活動
0
12月 24
1382
4
3月 24
3403
1
3月 24
2433
1
10月 23
5357
1
6月 23
12445