From 939d05b429af57e287d29af2a716ed0134a3d23f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 24 Mar 2022 17:12:55 +0000 Subject: [PATCH] [IMP] mail: introduce MailTemplateView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-2793280 closes odoo/odoo#87213 Signed-off-by: Alexandre Kühn (aku) --- .../src/components/activity/activity.xml | 7 +++--- .../components/mail_template/mail_template.js | 8 +++++++ .../mail_template/mail_template.xml | 2 +- .../mail/static/src/models/activity_view.js | 23 +++++++++++++++++-- .../static/src/models/mail_template_view.js | 20 ++++++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 addons/mail/static/src/models/mail_template_view.js diff --git a/addons/mail/static/src/components/activity/activity.xml b/addons/mail/static/src/components/activity/activity.xml index 23d23e60b3b..07e714d2890 100644 --- a/addons/mail/static/src/components/activity/activity.xml +++ b/addons/mail/static/src/components/activity/activity.xml @@ -106,13 +106,14 @@ - +
- +
diff --git a/addons/mail/static/src/components/mail_template/mail_template.js b/addons/mail/static/src/components/mail_template/mail_template.js index 1a2ac279af5..8941653883e 100644 --- a/addons/mail/static/src/components/mail_template/mail_template.js +++ b/addons/mail/static/src/components/mail_template/mail_template.js @@ -24,6 +24,13 @@ export class MailTemplate extends Component { return this.messaging && this.messaging.models['MailTemplate'].get(this.props.mailTemplateLocalId); } + /** + * @returns {MailTemplateView} + */ + get mailTemplateView() { + return this.messaging && this.messaging.models['MailTemplateView'].get(this.props.localId); + } + //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- @@ -53,6 +60,7 @@ export class MailTemplate extends Component { Object.assign(MailTemplate, { props: { activityLocalId: String, + localId: String, mailTemplateLocalId: String, }, template: 'mail.MailTemplate', diff --git a/addons/mail/static/src/components/mail_template/mail_template.xml b/addons/mail/static/src/components/mail_template/mail_template.xml index cc0d411fed6..bbb712a51d6 100644 --- a/addons/mail/static/src/components/mail_template/mail_template.xml +++ b/addons/mail/static/src/components/mail_template/mail_template.xml @@ -2,7 +2,7 @@ - +
diff --git a/addons/mail/static/src/models/activity_view.js b/addons/mail/static/src/models/activity_view.js index 110325ce217..b00965c9921 100644 --- a/addons/mail/static/src/models/activity_view.js +++ b/addons/mail/static/src/models/activity_view.js @@ -1,8 +1,8 @@ /** @odoo-module **/ import { registerModel } from '@mail/model/model_core'; -import { attr, one } from '@mail/model/model_field'; -import { clear, insertAndReplace } from '@mail/model/model_field_command'; +import { attr, many, one } from '@mail/model/model_field'; +import { clear, insertAndReplace, replace } from '@mail/model/model_field_command'; import { auto_str_to_date, getLangDateFormat, getLangDatetimeFormat } from 'web.time'; @@ -121,6 +121,20 @@ registerModel({ const datetimeFormat = getLangDateFormat(); return momentDeadlineDate.format(datetimeFormat); }, + /** + * @private + * @returns {FieldCommand} + */ + _computeMailTemplateViews() { + if (this.activity.mailTemplates.length === 0) { + return clear(); + } + return insertAndReplace( + this.activity.mailTemplates.map( + mailTemplate => ({ mailTemplate: replace(mailTemplate) }) + ), + ); + }, /** * @private * @returns {string} @@ -199,6 +213,11 @@ registerModel({ formattedDeadlineDate: attr({ compute: '_computeFormattedDeadlineDate', }), + mailTemplateViews: many('MailTemplateView', { + compute: '_computeMailTemplateViews', + inverse: 'activityViewOwner', + isCausal: true, + }), /** * Label for mark as done. This is just for translations purpose. */ diff --git a/addons/mail/static/src/models/mail_template_view.js b/addons/mail/static/src/models/mail_template_view.js new file mode 100644 index 00000000000..d1fdc0b63d5 --- /dev/null +++ b/addons/mail/static/src/models/mail_template_view.js @@ -0,0 +1,20 @@ +/** @odoo-module **/ + +import { registerModel } from '@mail/model/model_core'; +import { one } from '@mail/model/model_field'; + +registerModel({ + name: 'MailTemplateView', + identifyingFields: ['activityViewOwner', 'mailTemplate'], + fields: { + activityViewOwner: one('ActivityView', { + inverse: 'mailTemplateViews', + readonly: true, + required: true, + }), + mailTemplate: one('MailTemplate', { + readonly: true, + required: true, + }), + }, +});