[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
This commit is contained in:
Nicolas Martinelli
2018-06-11 10:39:18 +02:00
committed by Nicolas Martinelli
parent 61c9921596
commit 0d35f569f4
+12
View File
@@ -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'