I have inherited res.partner model and views and added one page named Vehicle Details as shown in below image :
Simillarly I have inherited sale.order model and views and added one field named vehicles in its form which is shown in below image :
Code for inheriting sale.order :
from odoo import api, fields, models
class CustomSaleOrder(models.Model):
_inherit = "sale.order"
x_model_ref_id = fields.Many2one('res.partner.line', string="Model Name")
vehicle_tags = fields.Many2one('res.partner.line', string="Vehicles", domain = [('name','=','partner_id')])
@api.onchange('partner_id')
def onchange_partner_id(self):
self.vehicle_tags = None
self.vehicle_tags = self.partner_id.id
The problem I am facing is that I want to fetch vehicles as per customers but it shows all vehicles in all customers. How can I fetch vehicles which specifically belongs to selected cusotmer only ??
I used the domain it shows empty as shown in below image :
res.partner.line code :
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")
x_customer_ids = fields.One2many('res.partner.line', 'x_customer_id', string="Vehicle Details")
color = fields.Integer(string="Color") # color_toggle
class CustomContactsPage(models.Model):
_name = "res.partner.line"
_rec_name = 'name'
x_customer_id = fields.Many2one('res.partner', string="Vehicle Details")
x_brand_id = fields.Many2one('vehicle.brand', string="Brand Name")
x_model_id = fields.Many2one('vehicle.model', string="Model Name")
name = fields.Many2one('vehicle.number',string="Vehicle Number")