[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)
This commit is contained in:
Josse Colpaert 2016-01-13 21:34:01 +01:00
parent bd4e6ff3bf
commit 4bd64dc91b
2 changed files with 11 additions and 2 deletions

View File

@ -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
#----------------------------------------------------------

View File

@ -1666,7 +1666,7 @@
<field name="model">stock.quant</field>
<field eval="10" name="priority"/>
<field name="arch" type="xml">
<form string="Quants" create="false" edit="false">
<form string="Quants" create="false" edit="false" delete="false">
<div class="oe_right oe_button_box">
<button name="action_view_quant_history" type="object" string="Quant History"/>
</div>
@ -1692,7 +1692,7 @@
<field name="model">stock.quant</field>
<field eval="10" name="priority"/>
<field name="arch" type="xml">
<tree string="Quants" create="0">
<tree string="Quants" create="0" delete="0">
<field name="product_id"/>
<field name="qty"/>
<field name="location_id"/>