I want to create a sales order where selecting a checkbox will allow me to choose specific products (in this case, products with available_for_cashback = True). I've tried many things, but I haven't been successful. Below is my code with one of the many approaches I've attempted:
class ProductTemplate(models.Model):
_inherit = 'product.template'
available_for_cashback = fields.Boolean(string="Redeemable with cashback")
class SaleOrder(models.Model):
_inherit = 'sale.order'
sale_order_cashback = fields.Boolean(string="Cashback order")
@api.onchange('sale_order_cashback')
def _onchange_sale_order_cashback(self):
if self.sale_order_cashback:
domain = [('available_for_cashback', '=', True)]
else:
domain = [('sale_ok', '=', True)]
return {'domain': {'order_line.product_template_id': domain}}