[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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user