[FIX] stock: allow unlinking records in uninstall mode

Business cases should not prevent the unlink of module-related records
during an uninstall.

This commit allows the reinstallation of sale_stock with demo data and
also allows the proper removal of tables and records if a db has any
non-draft inventory adjustments.

closes odoo/odoo#39776

X-original-commit: cedafe00941b869d284cd511633d7da15868fc0a
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
This commit is contained in:
Adrian Torres
2019-11-04 17:16:38 +00:00
committed by fw-bot
parent 02e0a31665
commit 13ee8a0373
+3 -1
View File
@@ -5,6 +5,7 @@ from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
from odoo.osv import expression
from odoo.tools import float_compare, float_is_zero
from odoo.addons.base.models.ir_model import MODULE_UNINSTALL_FLAG
class Inventory(models.Model):
@@ -74,7 +75,8 @@ class Inventory(models.Model):
def unlink(self):
for inventory in self:
if inventory.state not in ('draft', 'cancel'):
if (inventory.state not in ('draft', 'cancel')
and not self.env.context.get(MODULE_UNINSTALL_FLAG, False)):
raise UserError(_('You can only delete a draft inventory adjustment. If the inventory adjustment is not done, you can cancel it.'))
return super(Inventory, self).unlink()