Search code examples
odooodoo-15

I am trying to inherit and add one2many fields in res.partner model . It shows errror : Invalid field 'same_vat_partner_id' on model 'vehicle.brand'


inherited " res.partner " and added a page (editable tree) in notebook section, but when clicking on "Add a line" it is showing below error:

Invalid field 'same_vat_partner_id' on model 'vehicle.brand'

My code to inherit res.partner and add One2many fields in it :

from odoo import api, fields, models


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


x_brand_ids = fields.Many2many('res.partner.line', 'x_brand_id', string="Brand Name")
x_model_ids = fields.One2many('res.partner.line', 'x_model_id', string="Model Name")


class CustomContactsPage(models.Model):
_name = "res.partner.line"

x_brand_id = fields.Many2one('vehicle.brand', string="Brand Name")
x_model_id = fields.Many2one('vehicle.model', string="Model Name")

My code of vehicle.brand model :

from odoo import api, fields, models


class BrandCreate(models.Model):
_name = "vehicle.brand"
_description = "Customer"

name = fields.Char(string='Brand Name', required=True)

My code of vehicle.model model :

from odoo import api, fields, models


class ModelName(models.Model):
_name = "vehicle.model"
_description = "Models"


name = fields.Char(string='Model Name', required=True)

My code of view :

<?xml version="1.0" encoding="utf-8"?>
<record id="view_partner_form_inherited" model="ir.ui.view">
    <field name="name">res.partner.inherited</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//page[@name='internal_notes']" position="after">
            <page string="Vehicle Details">
                    <field name="x_brand_ids"></field>
                    <field name="x_model_ids"></field>
            </page>
        </xpath>
    </field>
</record>

Getting view inside view as mentioned in below images :

view 1

view 2


Solution

  • You needs to understand the Many2many and One2many fields. For many2many you check the required argument is the model name only. and other are optional. (Filling Many2many field (odoo 8))

    x_brand_ids = fields.Many2many('res.partner.line', string="Brand Name")
    

    For adding One2many we need many2one with that same model.

    x_model_ids = fields.One2many('res.partner.line', 'x_model_id', string="Model Name")
    

    For this you need x_model_id Many2one of res.partner field under res.partner.line

    You need to like below:

    class CustomContacts(models.Model):
    _inherit = "res.partner"
    
    
    x_brand_ids = fields.Many2many('res.partner.line', string="Brand Name")
    x_model_ids = fields.One2many('res.partner.line', 'x_model_id', string="Model Name")
    
    
    class CustomContactsPage(models.Model):
    _name = "res.partner.line"
    
    x_brand_id = fields.Many2one('vehicle.brand', string="Brand Name")
    x_model_id = fields.Many2one('res.partner', string="Model Name")