diff --git a/addons/mail/static/src/model/model_manager.js b/addons/mail/static/src/model/model_manager.js index 183e0d27e27..003e4fd8067 100644 --- a/addons/mail/static/src/model/model_manager.js +++ b/addons/mail/static/src/model/model_manager.js @@ -171,6 +171,20 @@ class ModelManager { return this.all(Model).find(findFunc); } + /** + * Gets the unique record of provided model that matches the given + * identifying data, if it exists. + * @see `_createRecordLocalId` for criteria of identification. + * + * @param {mail.model} Model class + * @param {Object} data + * @returns {mail.model|undefined} + */ + findFromIdentifyingData(Model, data) { + const localId = Model._createRecordLocalId(data); + return Model.get(localId); + } + /** * This method returns the record of provided model that matches provided * local id. Useful to convert a local id to a record. @@ -785,8 +799,7 @@ class ModelManager { const dataList = isMulti ? data : [data]; const records = []; for (const data of dataList) { - const localId = Model._createRecordLocalId(data); - let record = Model.get(localId); + let record = Model.findFromIdentifyingData(data); if (!record) { record = this._create(Model, data); } else { diff --git a/addons/mail/static/src/models/model/model.js b/addons/mail/static/src/models/model/model.js index f700b330a93..3696332ae85 100644 --- a/addons/mail/static/src/models/model/model.js +++ b/addons/mail/static/src/models/model/model.js @@ -110,6 +110,19 @@ function factory() { return this.env.modelManager.find(this, findFunc); } + /** + * Gets the unique record that matches the given identifying data, if it + * exists. + * @see `_createRecordLocalId` for criteria of identification. + * + * @static + * @param {Object} data + * @returns {mail.model|undefined} + */ + static findFromIdentifyingData(data) { + return this.env.modelManager.findFromIdentifyingData(this, data); + } + /** * This method returns the record of this model that matches provided * local id. Useful to convert a local id to a record. Note that even