diff --git a/spp_base_common/__manifest__.py b/spp_base_common/__manifest__.py index b3ad50cb0..b3e63d668 100644 --- a/spp_base_common/__manifest__.py +++ b/spp_base_common/__manifest__.py @@ -33,6 +33,7 @@ "assets": { "web.assets_backend": [ "spp_base_common/static/src/scss/navbar.scss", + "spp_base_common/static/src/legacy/js/views/list/list_controller_fix.js", ], "web._assets_primary_variables": [ "spp_base_common/static/src/scss/colors.scss", diff --git a/spp_base_common/readme/BUGFIX_archive_notification.md b/spp_base_common/readme/BUGFIX_archive_notification.md new file mode 100644 index 000000000..029fa1034 --- /dev/null +++ b/spp_base_common/readme/BUGFIX_archive_notification.md @@ -0,0 +1,36 @@ +## Bugfix: Archive Notification Message + +### Issue +Odoo core has a bug in the archive notification where the parameters are swapped, showing an illogical message like: +> "Of the 20,000 records selected, only the first 50,000 have been archived/unarchived." + +This is impossible since you cannot archive more records than were selected. + +### Root Cause +**Location**: `odoo/addons/web/static/src/legacy/js/views/list/list_controller.js:658-659` + +**Bug**: The sprintf parameters are in the wrong order: +```javascript +const msg = _.str.sprintf( + _t("Of the %d records selected, only the first %d have been archived/unarchived."), + total, resIds.length // ← WRONG ORDER +); +``` + +### Fix +This module patches the `ListController._toggleArchiveState` method to swap the parameters: +```javascript +const msg = _.str.sprintf( + _t("Of the %d records selected, only the first %d have been archived/unarchived."), + resIds.length, total // ← CORRECT ORDER +); +``` + +### Result +After the fix, the notification correctly shows: +> "Of the 50,000 records selected, only the first 20,000 have been archived/unarchived." + +### References +- Odoo Repository: https://github.com/odoo/odoo/tree/17.0/odoo/addons/base +- Fixed in: `spp_base_common/static/src/legacy/js/views/list/list_controller_fix.js` + diff --git a/spp_base_common/static/src/legacy/js/views/list/list_controller_fix.js b/spp_base_common/static/src/legacy/js/views/list/list_controller_fix.js new file mode 100644 index 000000000..ce4d3c3f0 --- /dev/null +++ b/spp_base_common/static/src/legacy/js/views/list/list_controller_fix.js @@ -0,0 +1,47 @@ +/** @odoo-module **/ + +import {DynamicList} from "@web/model/relational_model/dynamic_list"; +import {patch} from "@web/core/utils/patch"; +import {_t} from "@web/core/l10n/translation"; + +/** + * Patch for Odoo 17 bug: swapped parameters in archive notification message. + * + * Bug location: addons/web/static/src/model/relational_model/dynamic_list.js + * GitHub: https://github.com/odoo/odoo/blob/17.0/addons/web/static/src/model/relational_model/dynamic_list.js + * + * Original bug shows: "Of the 20,000 records selected, only the first 50,000 have been archived" + * Fixed to show: "Of the 50,000 records selected, only the first 20,000 have been archived" + */ + +patch(DynamicList.prototype, { + async _toggleArchive(isSelected, state) { + const method = state ? "action_archive" : "action_unarchive"; + const context = this.context; + const resIds = await this.getResIds(isSelected); + const action = await this.model.orm.call(this.resModel, method, [resIds], {context}); + + // FIXED: Swapped parameters from (resIds.length, this.count) to (this.count, resIds.length) + if ( + this.isDomainSelected && + resIds.length === this.model.activeIdsLimit && + resIds.length < this.count + ) { + const msg = _t( + "Of the %s records selected, only the first %s have been archived/unarchived.", + this.count, // FIXED: Total records selected (larger number) + resIds.length // FIXED: Actually processed (smaller number, limited) + ); + this.model.notification.add(msg, {title: _t("Warning")}); + } + + const reload = () => this.model.load(); + if (action && Object.keys(action).length) { + this.model.action.doAction(action, { + onClose: reload, + }); + } else { + return reload(); + } + }, +});