diff options
| author | Sébastien Theys <seb@odoo.com> | 2020-09-22 16:25:24 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-09-23 09:52:30 +0000 |
| commit | f6e67650e8cb1f8f0be9e90dbaccf45692816c3e (patch) | |
| tree | 1e08313ef69bfe827c321161e05ac44e27c8ca8b /addons/mail/static/src/model/model_field_command.js | |
| parent | bc00059bcd1c6475b00503e9242edd6547dbd93d (diff) | |
[FIX] mail: ignore `undefined` in JS fields create/write
Passing a field containing `undefined` should lead to the same result as not
passing the field.
Fields that relied on `undefined` as a value have been changed to use the newly
introduced `clear` command, that resets a field to its default value (often
that is equal to `undefined`).
task-2336491
closes odoo/odoo#58308
X-original-commit: b18824485483564d2ab80f41914a3548aa528ae0
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Diffstat (limited to 'addons/mail/static/src/model/model_field_command.js')
| -rw-r--r-- | addons/mail/static/src/model/model_field_command.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/mail/static/src/model/model_field_command.js b/addons/mail/static/src/model/model_field_command.js new file mode 100644 index 00000000000..89f42651ad9 --- /dev/null +++ b/addons/mail/static/src/model/model_field_command.js @@ -0,0 +1,45 @@ +odoo.define('mail/static/src/model/model_field_command.js', function (require) { +'use strict'; + +/** + * Allows field update to detect if the value it received is a command to + * execute (in which was it will be an instance of this class) or an actual + * value to set (in all other cases). + */ +class FieldCommand { + /** + * @constructor + * @param {function} func function to call when executing this command + */ + constructor(func) { + this.func = func; + } + + /** + * @param {ModelField} field + * @param {mail.model} record + * @param {options} [options] + * @returns {boolean} whether the value changed for the current field + */ + execute(field, record, options) { + return this.func(field, record, options); + } +} + +/** + * Returns a clear command to give to the model manager at create/update. + */ +function clear() { + return new FieldCommand((field, record, options) => + field.clear(record, options) + ); +} + +return { + // class + FieldCommand, + // shortcuts + clear, +}; + +}); |
