Skip to Content
Menu
This question has been flagged
1 Reply
2222 Views

Based on my products I am not getting the attribute in odoo12 community

When I select the product I want to get the attribute  which is my field.

But I am getting the attribute value based on the attribute when only this condition is given in onchange

  res['domain'] = {'attribute_value':[('attribute_id', '=', self.product_attribute.id)]

here is my code...

# -*- coding: utf-8 -*-


from odoo import models, fields, api

#Model of Sale-Order product variant
class SaleVariant(models.Model):
    _inherit = 'sale.order.line'

    product_attribute = fields.Many2one('product.attribute', string='Product Attributes')
    attribute_value=fields.Many2many('product.attribute.value',string="Attribute Value")

    # onchange handler
    @api.onchange('product_attribute','product_id')
    def _product_attribute_onchange(self):
        res = {}
        res['domain'] = {'attribute_value':[('attribute_id', '=', self.product_attribute.id)],
                        'product_attribute':[('attribute_line_ids.product_tmpl_id', '=',     self.product_id.id)]}
        return res
       

Please help...

Thanks in Advance..


Avatar
Discard
Author Best Answer

I got it...

from odoo import models, fields, api

#Model of Sale-Order Product Variant
class SaleVariant(models.Model):
    _inherit = 'sale.order.line'
   
    product = fields.Many2one('product.template',string='Product')
    product_attribute = fields.Many2one('product.attribute', string='Product Attributes')
    attribute_value=fields.Many2many('product.attribute.value',string="Attribute Value")

    # onchange handler for dynamic dropdown
    @api.onchange('product_attribute','product')
    def _product_attribute_onchange(self):
        res = {}
        res['domain'] = {'attribute_value':[('attribute_id', '=', self.product_attribute.id)],
                        'product_attribute':[('attribute_line_ids.product_tmpl_id', '=',             self.product.id)]}
        return res
       

Avatar
Discard