From c637a0ff1c51dfa243a04c09f5f4be5c1f0253c0 Mon Sep 17 00:00:00 2001
From: Martin Trigaux <mat@odoo.com>
Date: Mon, 19 Jan 2015 14:35:06 +0100
Subject: [PATCH] [IMP] point_of_sale: prevent deleting products that may be
 sold

When a pos.session is launched, all the products are loaded. If the product
was deleted in the backend, it was still possible to sell it in the pos.
---
 addons/point_of_sale/point_of_sale.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py
index 77974a7ee7b9..130c5b0d88ce 100644
--- a/addons/point_of_sale/point_of_sale.py
+++ b/addons/point_of_sale/point_of_sale.py
@@ -1426,6 +1426,13 @@ class product_template(osv.osv):
         'available_in_pos': True,
     }
 
+    def unlink(self, cr, uid, ids, context=None):
+        if self.search(cr, uid, [('id', 'in', ids), ('available_in_pos', '=', True)], context=context):
+            if self.pool['pos.session'].search(cr, uid, [('state', '!=', 'closed')], context=context):
+                raise osv.except_osv(_('Error!'),
+                    _('You cannot delete a product saleable in point of sale while a session is still opened.'))
+        return super(product_template, self).unlink(cr, uid, ids, context=context)
+
 class res_partner(osv.osv):
     _inherit = 'res.partner'
 
-- 
GitLab