From 84d199b6ed36492b8fc2ba8d63fd9c7537b7fb8b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 24 Jul 2023 09:25:42 +0000 Subject: [PATCH] [REF] web: RelationalModel: move _askChanges from record to model _askChanges doesn't apply on a single record, it asks all fields of all records of the current model to send their changes, so it makes more sense to have this function on the model instead. Part of task~3179751 Part-of: odoo/odoo#114024 --- .../web/static/src/model/relational_model/record.js | 13 +++---------- .../src/model/relational_model/relational_model.js | 6 ++++++ .../src/model/relational_model/static_list.js | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/model/relational_model/record.js b/addons/web/static/src/model/relational_model/record.js index 60541ac85b4..62a417861b0 100644 --- a/addons/web/static/src/model/relational_model/record.js +++ b/addons/web/static/src/model/relational_model/record.js @@ -135,7 +135,7 @@ export class Record extends DataPoint { async checkValidity() { if (!this._urgentSave) { - await this._askChanges(); + await this.model._askChanges(); } return this._checkValidity(); } @@ -190,7 +190,7 @@ export class Record extends DataPoint { } async isDirty() { - await this._askChanges(); + await this.model._askChanges(); return this.dirty; } @@ -224,7 +224,7 @@ export class Record extends DataPoint { } async save(options) { - await this._askChanges(); + await this.model._askChanges(); return this.model.mutex.exec(() => this._save(options)); } @@ -317,13 +317,6 @@ export class Record extends DataPoint { this._setEvalContext(); } - // FIXME: move to model? - _askChanges() { - const proms = []; - this.model.bus.trigger("NEED_LOCAL_CHANGES", { proms }); - return Promise.all([...proms, this.model.mutex.getUnlockedDef()]); - } - _checkValidity({ silent } = {}) { const unsetRequiredFields = []; for (const fieldName in this.activeFields) { diff --git a/addons/web/static/src/model/relational_model/relational_model.js b/addons/web/static/src/model/relational_model/relational_model.js index 0c09c49662b..0bd767e91ac 100644 --- a/addons/web/static/src/model/relational_model/relational_model.js +++ b/addons/web/static/src/model/relational_model/relational_model.js @@ -223,6 +223,12 @@ export class RelationalModel extends Model { } } + _askChanges() { + const proms = []; + this.bus.trigger("NEED_LOCAL_CHANGES", { proms }); + return Promise.all([...proms, this.mutex.getUnlockedDef()]); + } + /** * * @param {Config} config diff --git a/addons/web/static/src/model/relational_model/static_list.js b/addons/web/static/src/model/relational_model/static_list.js index 3e9cf0dbc1d..0cf8be6ef40 100644 --- a/addons/web/static/src/model/relational_model/static_list.js +++ b/addons/web/static/src/model/relational_model/static_list.js @@ -295,7 +295,7 @@ export class StaticList extends DataPoint { async leaveEditMode({ discard, canAbandon, validate } = {}) { if (this.editedRecord) { - await this.editedRecord._askChanges(false); + await this.model._askChanges(false); } return this.model.mutex.exec(async () => { if (this.editedRecord) {