From 4bd64dc91b11726c154a53662b0de91c29b0d718 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 13 Jan 2016 21:34:01 +0100 Subject: [PATCH] [IMP] stock: avoid deletion of quants by user Quants should never be changed or deleted by a user. We make it not possible anymore in the views. And also in the code we avoid to unlink without passing a specific key in the context. (as we still need to be able to delete quants in case of negative quants reconciliation) --- addons/stock/stock.py | 9 +++++++++ addons/stock/stock_view.xml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ecf2b3998a7..1c610b1a79f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -563,6 +563,9 @@ class stock_quant(osv.osv): negative quants. If it's possible, apply the cost of the new quant to the conter-part of the negative quant. """ + context = context or {} + context = dict(context) + context.update({'force_unlink': True}) solving_quant = quant dom = [('qty', '<', 0)] if quant.lot_id: @@ -654,6 +657,12 @@ class stock_quant(osv.osv): raise osv.except_osv(_('Error'), _('You cannot move to a location of type view %s.') % (location.name)) return True + def unlink(self, cr, uid, ids, context=None): + context = context or {} + if not context.get('force_unlink'): + raise osv.except_osv(_('Error!'), _('Under no circumstances should you delete or change quants yourselves!')) + super(stock_quant, self).unlink(cr, uid, ids, context=context) + #---------------------------------------------------------- # Stock Picking #---------------------------------------------------------- diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index a9de687c688..4f752559b5b 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -1666,7 +1666,7 @@ stock.quant -
+
@@ -1692,7 +1692,7 @@ stock.quant - +