From 13ee8a03733ed12e0fdb6a96f88c6448cc658b65 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 28 Oct 2019 10:50:57 +0000 Subject: [PATCH] [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) --- addons/stock/models/stock_inventory.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index bc71ae7bc72..affb45bccdc 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -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()