From 310e3c15fd34b0a5d38bc4bfe3eb3e013ce17948 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 21 Feb 2018 15:58:50 +0100 Subject: [PATCH] [FIX] pos_discount: default product Several issues: - If product `product_product_consumable` was deleted, an error is raised. - The default values are inconsistent with the fact that `module_pos_discount` is `False` at POS creation. - The domain should ensures that both `available_in_pos` and `sale_ok` are `True`, otherwise the product won't be loaded by the POS. opw-814426 --- addons/pos_discount/models/pos_config.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/pos_discount/models/pos_config.py b/addons/pos_discount/models/pos_config.py index 0c21d482f17..46272218f67 100644 --- a/addons/pos_discount/models/pos_config.py +++ b/addons/pos_discount/models/pos_config.py @@ -7,17 +7,18 @@ from odoo import api, fields, models class PosConfig(models.Model): _inherit = 'pos.config' - def _get_default_discount_product(self): - return self.env.ref('point_of_sale.product_product_consumable') - iface_discount = fields.Boolean(string='Order Discounts', help='Allow the cashier to give discounts on the whole order.') - discount_pc = fields.Float(string='Discount Percentage', default=10, help='The default discount percentage') - discount_product_id = fields.Many2one('product.product', string='Discount Product', domain="[('available_in_pos', '=', True)]", help='The product used to model the discount.', default=_get_default_discount_product) + discount_pc = fields.Float(string='Discount Percentage', help='The default discount percentage') + discount_product_id = fields.Many2one('product.product', string='Discount Product', + domain="[('available_in_pos', '=', True), ('sale_ok', '=', True)]", help='The product used to model the discount.') @api.onchange('module_pos_discount') def _onchange_module_pos_discount(self): if self.module_pos_discount: - self.discount_product_id = self.env['product.product'].search([('available_in_pos', '=', True)], limit=1) + self.discount_product_id = self.env.ref('point_of_sale.product_product_consumable', raise_if_not_found=False) + if not self.discount_product_id or not self.discount_product_id.available_in_pos or not self.discount_product_id.sale_ok: + domain = [('available_in_pos', '=', True), ('sale_ok', '=', True)] + self.discount_product_id = self.env['product.product'].search(domain, limit=1) self.discount_pc = 10.0 else: self.discount_product_id = False