From 0d35f569f421e5f7ec1fb964c8560aaf078db0cc Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 8 Jun 2018 14:58:53 +0200 Subject: [PATCH] [FIX] point_of_sale: prevent product unlink - Create a product with variants which can be sold in the POS - Open a POS session - Delete a variant (e.g. change the attributes) - Sell the product in the POS, validate The POS order cannot be created because the product ID doesn't exist anymore. We extend the existing constain on `product.template` on `product.product`. opw-1850598 --- addons/point_of_sale/models/product.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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'