*: hr, hr_holidays, im_livechat, website_livechat This commit turns some `link`/`unlink`/`unlinkAll` to `replace`/`clear`. The commands `replace`/`clear` are easier to understand, and also clearly tells what’s the expected resulting value of this field. This change will help turning big and imperative code into smaller declarative code. Task-2834598 closes odoo/odoo#89852 Related: odoo/enterprise#26673 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
34 lines
862 B
JavaScript
34 lines
862 B
JavaScript
/** @odoo-module **/
|
|
|
|
import { addFields, patchModelMethods } from '@mail/model/model_core';
|
|
import { one } from '@mail/model/model_field';
|
|
import { clear, insert } from '@mail/model/model_field_command';
|
|
// ensure that the model definition is loaded before the patch
|
|
import '@mail/models/thread';
|
|
|
|
patchModelMethods('Thread', {
|
|
/**
|
|
* @override
|
|
*/
|
|
convertData(data) {
|
|
const data2 = this._super(data);
|
|
if ('visitor' in data) {
|
|
if (data.visitor) {
|
|
data2.visitor = insert(this.messaging.models['Visitor'].convertData(data.visitor));
|
|
} else {
|
|
data2.visitor = clear();
|
|
}
|
|
}
|
|
return data2;
|
|
},
|
|
});
|
|
|
|
addFields('Thread', {
|
|
/**
|
|
* Visitor connected to the livechat.
|
|
*/
|
|
visitor: one('Visitor', {
|
|
inverse: 'threads',
|
|
}),
|
|
});
|