Hello everyone!
I want to set a custom domain on product_template_id field in sale.order.line model. When the quotation is created from CRM then I want to display specific products in the order lines. I have created a field called is_from_crm which will be true if the quotation is created through CRM.
This code is not working even if the boolean field is true when I added logs, even the order_id is false.
def _get_allowed_products_domain(self):
domain = [('sale_ok', '=', True)]
if self.order_id.is_from_crm:
allowed_products = self.env['crm.quotation.product'].search([]).product_ids
domain.append(('id', 'in', allowed_products.ids))
return domain
product_template_id = fields.Many2one(
string="Product Template",
comodel_name='product.template',
compute='_compute_product_template_id',
readonly=False,
search='_search_product_template_id',
domain = _get_allowed_products_domain)