[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
This commit is contained in:
Aaron Bohy
2023-07-24 20:17:57 +02:00
parent 3967dab0ce
commit 84d199b6ed
3 changed files with 10 additions and 11 deletions
@@ -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) {
@@ -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
@@ -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) {