Skip to Content
Menu
This question has been flagged
2 Replies
9311 Views

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?

Avatar
Discard
Best Answer

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.


Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
4
Mar 24
1663
1
Mar 24
831
1
Oct 23
3658
1
Jun 23
10727
0
Jan 23
1557