[FIX] calendar: open calendar view from 'Reschedule' activity button

With recent commit[1], we now use the wowlEnv instead of the legacy one,
and use the service provided by env to call the rpc.

This was adapted in the activity model, but not on the patched method
under calendar.

This commit fixes the issues to adpat the change, and so the 'Reschedule'
button for the meeting activity now opens the calendar view as expected.

Apart from that, this commit also tries to align this button with other
activity buttons, for better UI.

commit[1] - https://github.com/odoo/odoo/commit/3573a7fef497d

taskID-2899402

closes odoo/odoo#95747

X-original-commit: b7efe2a80f9da175114cf1138565580981690001
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Dharmraj Jhala
2022-07-12 18:31:13 +02:00
parent 71abeef70d
commit d8d30829c6
5 changed files with 85 additions and 4 deletions
@@ -7,7 +7,7 @@
</xpath>
<xpath expr="//button[hasclass('o_Activity_editButton')]" position="after">
<t t-if="activityView.activity.calendar_event_id">
<button class="o_Activity_toolButton o_Activity_editButton btn btn-link" t-on-click="activityView.onClickEdit">
<button class="o_Activity_toolButton o_Activity_editButton btn btn-link pt-0" t-on-click="activityView.onClickEdit">
<i class="fa fa-calendar"/> Reschedule
</button>
</t>
@@ -55,9 +55,7 @@ patchRecordMethods('Activity', {
method: 'action_create_calendar_event',
args: [[this.id]],
});
this.env.bus.trigger('do-action', {
action
});
this.env.services.action.doAction(action);
}
},
});
@@ -0,0 +1,49 @@
/** @odoo-module **/
import { start, startServer } from '@mail/../tests/helpers/test_utils';
QUnit.module('calendar', () => {
QUnit.module('components', () => {
QUnit.module('activity_tests.js');
QUnit.test('activity click on Reschedule', async function (assert) {
assert.expect(1);
const pyEnv = await startServer();
const resPartnerId = pyEnv['res.partner'].create({});
const meetingActivityTypeId = pyEnv['mail.activity.type'].create({ icon: 'fa-calendar', name: "Meeting" });
const calendarAttendeeId = pyEnv['calendar.attendee'].create({ partner_id: resPartnerId });
const calendaMeetingId = pyEnv['calendar.event'].create({
res_model: "calendar.event",
name: "meeting1",
start: "2022-07-06 06:30:00",
attendee_ids: [calendarAttendeeId],
});
pyEnv['mail.activity'].create({
name: "Small Meeting",
activity_type_id: meetingActivityTypeId,
can_write: true,
res_id: resPartnerId,
res_model: 'res.partner',
calendar_event_id: calendaMeetingId,
});
const { click, openFormView } = await start();
await openFormView(
{
res_model: 'res.partner',
res_id: resPartnerId,
},
);
await click('.o_Activity_editButton');
assert.containsOnce(
document.body,
'.o_calendar_view',
"should have opened calendar view"
);
});
});
});
@@ -9,6 +9,32 @@ import { MockServer } from '@web/../tests/helpers/mock_server';
import { datetime_to_str } from 'web.time';
patch(MockServer.prototype, 'calendar', {
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
*/
async _performRPC(route, args) {
// mail.activity methods
if (args.model === 'mail.activity' && args.method === 'action_create_calendar_event') {
return {
type: 'ir.actions.act_window',
name: "Meetings",
res_model: 'calendar.event',
view_mode: 'calendar',
views: [[false, 'calendar']],
target: 'current',
};
}
// calendar.event methods
if (args.model === 'calendar.event' && args.method === 'check_access_rights') {
return true;
}
return this._super(...arguments);
},
//--------------------------------------------------------------------------
// Private Mocked Methods
//--------------------------------------------------------------------------
@@ -0,0 +1,8 @@
/** @odoo-module **/
import { registry } from '@web/core/registry';
const viewArchsRegistry = registry.category('mail.view.archs');
const calendarArchsRegistry = viewArchsRegistry.category('calendar');
calendarArchsRegistry.add('default', '<calendar date_start="start"/>');