*: calendar, hr_holidays, im_livechat, note, website_livechat. This PR helps reducing the noise in the discuss new env PR. Indeed, the new mockServer has the same method except that they are not prefixed by any underscore. All calls have been changed, and the corresponding methods created. They will be deleted later. task-2582313 closes odoo/odoo#89659 Related: odoo/enterprise#26603 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
78 lines
3.2 KiB
JavaScript
78 lines
3.2 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
import '@im_livechat/../tests/helpers/mock_server'; // ensure mail overrides are applied first
|
|
|
|
import MockServer from 'web.MockServer';
|
|
|
|
MockServer.include({
|
|
/**
|
|
* Simulate a 'call_button' operation from a view.
|
|
*
|
|
* @override
|
|
*/
|
|
_mockCallButton({ args, kwargs, method, model }) {
|
|
if (model === 'website.visitor' && method === 'action_send_chat_request') {
|
|
return this._mockWebsiteVisitorActionSendChatRequest(args[0]);
|
|
}
|
|
return this._super(...arguments);
|
|
},
|
|
/**
|
|
* Overrides to add visitor information to livechat channels.
|
|
*
|
|
* @override
|
|
*/
|
|
_mockMailChannelChannelInfo(ids) {
|
|
const channelInfos = this._super(...arguments);
|
|
for (const channelInfo of channelInfos) {
|
|
const channel = this.getRecords('mail.channel', [['id', '=', channelInfo.id]])[0];
|
|
if (channel.channel_type === 'livechat' && channelInfo.livechat_visitor_id) {
|
|
const visitor = this.getRecords('website.visitor', [['id', '=', channelInfo.livechat_visitor_id]])[0];
|
|
const country = this.getRecords('res.country', [['id', '=', visitor.country_id]])[0];
|
|
channelInfo.visitor = {
|
|
country_code: country && country.code,
|
|
country_id: country && country.id,
|
|
display_name: visitor.display_name,
|
|
history: visitor.history, // TODO should be computed
|
|
id: visitor.id,
|
|
is_connected: visitor.is_connected,
|
|
lang_name: visitor.lang_name,
|
|
partner_id: visitor.partner_id,
|
|
website_name: visitor.website_name,
|
|
};
|
|
}
|
|
}
|
|
return channelInfos;
|
|
},
|
|
/**
|
|
* @private
|
|
* @param {integer[]} ids
|
|
*/
|
|
_mockWebsiteVisitorActionSendChatRequest(ids) {
|
|
const visitors = this.getRecords('website.visitor', [['id', 'in', ids]]);
|
|
for (const visitor of visitors) {
|
|
const country = visitor.country_id
|
|
? this.getRecords('res.country', [['id', '=', visitor.country_id]])
|
|
: undefined;
|
|
const visitor_name = `${visitor.display_name}${country ? `(${country.name})` : ''}`;
|
|
const membersToAdd = [[0, 0, { partner_id: this.currentPartnerId }]];
|
|
if (visitor.partner_id) {
|
|
membersToAdd.push([0, 0, { partner_id: visitor.partner_id }]);
|
|
} else {
|
|
membersToAdd.push([0, 0, { partner_id: this.publicPartnerId }]);
|
|
}
|
|
const livechatId = this.mockCreate('mail.channel', {
|
|
anonymous_name: visitor_name,
|
|
channel_last_seen_partner_ids: membersToAdd,
|
|
channel_type: 'livechat',
|
|
livechat_operator_id: this.currentPartnerId,
|
|
public: 'private',
|
|
});
|
|
// notify operator
|
|
this._widget.call('bus_service', 'trigger', 'notification', [{
|
|
type: 'website_livechat.send_chat_request',
|
|
payload: this._mockMailChannelChannelInfo([livechatId])[0],
|
|
}]);
|
|
}
|
|
},
|
|
});
|