[IMP] point_of_sale: do not reload when module is installed

When a module corresponding to a pos.config field is already
installed, do not reload the page.

Part-of: odoo/odoo#84719
This commit is contained in:
Joseph Caburnay
2022-06-03 16:39:51 +02:00
parent b0ea01ff1e
commit b0b75575a0
2 changed files with 31 additions and 14 deletions
+14
View File
@@ -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
@@ -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;
},
});