diff --git a/addons/point_of_sale/models/product.py b/addons/point_of_sale/models/product.py index 1caded3870e..7c9b4c954fb 100644 --- a/addons/point_of_sale/models/product.py +++ b/addons/point_of_sale/models/product.py @@ -27,6 +27,18 @@ class ProductTemplate(models.Model): self.available_in_pos = False +class ProductProduct(models.Model): + _inherit = 'product.product' + + @api.multi + def unlink(self): + product_ctx = dict(self.env.context or {}, active_test=False) + if self.env['pos.session'].search_count([('state', '!=', 'closed')]): + if self.with_context(product_ctx).search_count([('id', 'in', self.ids), ('product_tmpl_id.available_in_pos', '=', True)]): + raise UserError(_('You cannot delete a product saleable in point of sale while a session is still opened.')) + return super(ProductProduct, self).unlink() + + class ProductUomCateg(models.Model): _inherit = 'product.uom.categ'