Skip to content
Permalink
Browse files

[FIX] mrp: avoid module warning when a group is removed

Due to a weird combination of dependencies and settings, the behaviour
of the workorder checkbox in the MRP configuration wizard is a bit
dangerous:
- if the group is enabled via another mechanism (e.g. a technical view)
before accessing the wizard, the default is set to True and an invisible
`module_mrp_workorder` field is enabled, promptly causing the
installation of the module upon saving (although the user did not modify
a single thing in the wizard)
- if the module was installed through another mechanism (e.g. the apps
menu) but the group was disabled, accessing the wizard will cause the
group to get unchecked, promptly causing the removal of your module and
all its data \o/

The second case is quite stressful for users, since accessing their
configuration wizard for the first time will immediately display a
warning that unchecking that option will uninstall a few modules (even
though they didn't actually uncheck anything).

This commit tries to mitigate this second case. The onchange behaviour
needs to adapt to the *actual* state of the module in database - we
cannot rely on the module_wrp_workorder field since there is no way to
know if it was modified by another onchange, for example. Based on the
actual module state, we split the onchange behaviour:
- if mrp_workorder *is not* installed, then triggering the group field
should be mirrored on the module field (enabling it should install the
module, disabling it should cancel the module installation since it must
have happened in the same transaction)
- if mrp_workorder *is* installed, then disabling the group should *not*
uninstall it and enabling the group should, well, enable the group and
leave the module selection as it found it
  • Loading branch information...
dbo-odoo committed Apr 23, 2019
1 parent 19aa7c4 commit 593cb77a87cf9c77e0b855464134c7ec7b6bc745
Showing with 8 additions and 1 deletion.
  1. +8 −1 addons/mrp/models/res_config_settings.py
@@ -24,4 +24,11 @@ def _onchange_use_manufacturing_lead(self):

@api.onchange('group_mrp_routings')
def _onchange_group_mrp_routings(self):
self.module_mrp_workorder = self.group_mrp_routings
# We cannot rely on cache as the onchange might have been called before in the same env
self.env.cr.execute("SELECT state='installed' FROM ir_module_module WHERE name='mrp_workorder'")
module_wo_installed = self.env.cr.fetchone()
# We want to avoid spontaneous uninstall of the mrp_workorder module, the onchange
# behaviour should adapt to the actual module state
# Read the commit message for these lines before removing this
if not module_wo_installed:
self.module_mrp_workorder = self.group_mrp_routings

0 comments on commit 593cb77

Please sign in to comment.
You can’t perform that action at this time.