diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 7c504331891..731e33d0caa 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -737,3 +737,17 @@ class PosConfig(models.Model): """, [self.company_id.id, str(self.limited_partners_amount)]) result = self.env.cr.fetchall() return result + + @api.model + def are_there_uninstalled_modules(self, changed_fields): + modules_to_check = self._get_modules_to_check(changed_fields) + n_installed = self.env['ir.module.module'].search_count([('name', 'in', modules_to_check), ('state', '=', 'installed')]) + return n_installed != len(modules_to_check) + + @api.model + def _get_modules_to_check(self, changed_fields): + modules_to_check = [] + for field in changed_fields: + if field.startswith('module_'): + modules_to_check.append(field.replace('module_', '')) + return modules_to_check diff --git a/addons/point_of_sale/static/src/backend/web_overrides/pos_config_form.js b/addons/point_of_sale/static/src/backend/web_overrides/pos_config_form.js index 6c8542db740..e00d88e05cb 100644 --- a/addons/point_of_sale/static/src/backend/web_overrides/pos_config_form.js +++ b/addons/point_of_sale/static/src/backend/web_overrides/pos_config_form.js @@ -4,27 +4,30 @@ odoo.define('point_of_sale.pos_config_form', function (require) { var FormController = require('web.FormController'); var FormView = require('web.FormView'); var viewRegistry = require('web.view_registry'); + var rpc = require('web.rpc'); var PosConfigFormController = FormController.extend({ - _enableButtons: function (changedFields) { + saveRecord: async function (recordID) { + const _super = this._super; + const record = this.model.localData[recordID || this.handle]; + const fieldsToChange = Object.keys( + this.model._generateChanges(record, { viewType: undefined, changesOnly: true }) + ); let shouldReload = false; - if (Array.isArray(changedFields)) { - for (let field of (changedFields)) { - if ( - field.startsWith('module_') || - field.startsWith('group_') || - field === 'is_posbox' - ) { - shouldReload = true; - break; - } - } + if (fieldsToChange.length) { + shouldReload = await rpc.query( + rpc.buildQuery({ + model: 'pos.config', + method: 'are_there_uninstalled_modules', + args: [fieldsToChange], + }) + ); } + const result = await _super.apply(this, arguments); if (shouldReload) { window.location.reload(); - } else { - this._super.apply(this, arguments); } + return result; }, });