'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 :
Solution 1:[1]
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")
Solution 2:[2]
When using a One2many field the inverse_name
(x_model_id in your example) is equal to the current record and Odoo tries to recompute the partner vat using vehicle.model
record in place of a res.partner
record and this is why you are getting that error.
To fix it just define the inverse name in vehicle.brand
model and use it in x_model_ids
field instead of x_model_id
.
Example:
class CustomContacts(models.Model):
_inherit = "res.partner"
x_model_ids = fields.One2many('res.partner.line', 'model_id', string="Model Name")
class CustomContactsPage(models.Model):
_name = "res.partner.line"
model_id = fields.Many2one('res.partner')
Edit:
If you want to edit the One2many
field in place, define it inside the form view like following:
<field name="x_model_ids">
<tree editable="bottom">
</tree>
</field>
For the Many2many
fields, Odoo will open a dialog to select or create vehicle brands.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Synodica Solutions Pvt. Ltd. |
Solution 2 |