mock_server.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /** @odoo-module **/
  2. // ensure mail override is applied first.
  3. import '@mail/../tests/helpers/mock_server';
  4. import { patch } from '@web/core/utils/patch';
  5. import { MockServer } from '@web/../tests/helpers/mock_server';
  6. import { datetime_to_str } from 'web.time';
  7. patch(MockServer.prototype, 'calendar', {
  8. //--------------------------------------------------------------------------
  9. // Private
  10. //--------------------------------------------------------------------------
  11. /**
  12. * @override
  13. */
  14. async _performRPC(route, args) {
  15. // mail.activity methods
  16. if (args.model === 'mail.activity' && args.method === 'action_create_calendar_event') {
  17. return {
  18. type: 'ir.actions.act_window',
  19. name: "Meetings",
  20. res_model: 'calendar.event',
  21. view_mode: 'calendar',
  22. views: [[false, 'calendar']],
  23. target: 'current',
  24. };
  25. }
  26. // calendar.event methods
  27. if (args.model === 'calendar.event' && args.method === 'check_access_rights') {
  28. return true;
  29. }
  30. return this._super(...arguments);
  31. },
  32. //--------------------------------------------------------------------------
  33. // Private Mocked Methods
  34. //--------------------------------------------------------------------------
  35. /**
  36. * Simulates `_systray_get_calendar_event_domain` on `res.users`.
  37. *
  38. * @private
  39. */
  40. _mockResUsers_SystrayGetCalendarEventDomain() {
  41. const startDate = new Date();
  42. startDate.setUTCHours(0, 0, 0, 0);
  43. const endDate = new Date();
  44. endDate.setUTCHours(23, 59, 59, 999);
  45. const currentPartnerAttendeeIds = this.pyEnv['calendar.attendee'].search([['partner_id', '=', this.currentPartnerId]]);
  46. return [
  47. '&',
  48. '|',
  49. '&',
  50. '|',
  51. ['start', '>=', datetime_to_str(startDate)],
  52. ['stop', '>=', datetime_to_str(startDate)],
  53. ['start', '<=', datetime_to_str(endDate)],
  54. '&',
  55. ['allday', '=', true],
  56. ['start_date', '=', datetime_to_str(startDate)],
  57. ['attendee_ids', 'in', currentPartnerAttendeeIds],
  58. ];
  59. },
  60. /**
  61. * Simulates `systray_get_activities` on `res.users`.
  62. *
  63. * @override
  64. */
  65. _mockResUsersSystrayGetActivities() {
  66. const activities = this._super(...arguments);
  67. const meetingsLines = this.pyEnv['calendar.event'].searchRead(
  68. this._mockResUsers_SystrayGetCalendarEventDomain(),
  69. {
  70. fields: ['id', 'start', 'name', 'allday', 'attendee_status'],
  71. order: 'start',
  72. }
  73. ).filter(meetingLine => meetingLine['attendee_status'] !== 'declined');
  74. if (meetingsLines.length) {
  75. activities.unshift({
  76. id: 'calendar.event', // for simplicity
  77. meetings: meetingsLines,
  78. model: 'calendar.event',
  79. name: 'Today\'s Meetings',
  80. type: 'meeting',
  81. });
  82. }
  83. return activities;
  84. },
  85. });