summaryrefslogtreecommitdiff
path: root/addons/snailmail/static/src/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/snailmail/static/src/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/snailmail/static/src/models')
-rw-r--r--addons/snailmail/static/src/models/message/message.js69
-rw-r--r--addons/snailmail/static/src/models/messaging/messaging.js38
-rw-r--r--addons/snailmail/static/src/models/notification_group/notification_group.js62
3 files changed, 169 insertions, 0 deletions
diff --git a/addons/snailmail/static/src/models/message/message.js b/addons/snailmail/static/src/models/message/message.js
new file mode 100644
index 00000000..f685e48a
--- /dev/null
+++ b/addons/snailmail/static/src/models/message/message.js
@@ -0,0 +1,69 @@
+odoo.define('snailmail/static/src/models/message.message.js', function (require) {
+'use strict';
+
+const { registerInstancePatchModel } = require('mail/static/src/model/model_core.js');
+
+registerInstancePatchModel('mail.message', 'snailmail/static/src/models/message.message.js', {
+
+ //----------------------------------------------------------------------
+ // Public
+ //----------------------------------------------------------------------
+
+ /**
+ * Cancels the 'snailmail.letter' corresponding to this message.
+ *
+ * @returns {Deferred}
+ */
+ async cancelLetter() {
+ // the result will come from longpolling: message_notification_update
+ await this.async(() => this.env.services.rpc({
+ model: 'mail.message',
+ method: 'cancel_letter',
+ args: [[this.id]],
+ }));
+ },
+ /**
+ * Opens the action about 'snailmail.letter' format error.
+ */
+ openFormatLetterAction() {
+ this.env.bus.trigger('do-action', {
+ action: 'snailmail.snailmail_letter_format_error_action',
+ options: {
+ additional_context: {
+ message_id: this.id,
+ },
+ },
+ });
+ },
+ /**
+ * Opens the action about 'snailmail.letter' missing fields.
+ */
+ async openMissingFieldsLetterAction() {
+ const letterIds = await this.async(() => this.env.services.rpc({
+ model: 'snailmail.letter',
+ method: 'search',
+ args: [[['message_id', '=', this.id]]],
+ }));
+ this.env.bus.trigger('do-action', {
+ action: 'snailmail.snailmail_letter_missing_required_fields_action',
+ options: {
+ additional_context: {
+ default_letter_id: letterIds[0],
+ },
+ },
+ });
+ },
+ /**
+ * Retries to send the 'snailmail.letter' corresponding to this message.
+ */
+ async resendLetter() {
+ // the result will come from longpolling: message_notification_update
+ await this.async(() => this.env.services.rpc({
+ model: 'mail.message',
+ method: 'send_letter',
+ args: [[this.id]],
+ }));
+ },
+});
+
+});
diff --git a/addons/snailmail/static/src/models/messaging/messaging.js b/addons/snailmail/static/src/models/messaging/messaging.js
new file mode 100644
index 00000000..f00d0544
--- /dev/null
+++ b/addons/snailmail/static/src/models/messaging/messaging.js
@@ -0,0 +1,38 @@
+odoo.define('snailmail/static/src/models/messaging/messaging.js', function (require) {
+'use strict';
+
+const {
+ registerInstancePatchModel,
+ registerFieldPatchModel,
+} = require('mail/static/src/model/model_core.js');
+const { attr } = require('mail/static/src/model/model_field.js');
+
+registerInstancePatchModel('mail.messaging', 'snailmail/static/src/models/messaging/messaging.js', {
+ async fetchSnailmailCreditsUrl() {
+ const snailmail_credits_url = await this.async(() => this.env.services.rpc({
+ model: 'iap.account',
+ method: 'get_credits_url',
+ args: ['snailmail'],
+ }));
+ this.update({
+ snailmail_credits_url,
+ });
+ },
+ async fetchSnailmailCreditsUrlTrial() {
+ const snailmail_credits_url_trial = await this.async(() => this.env.services.rpc({
+ model: 'iap.account',
+ method: 'get_credits_url',
+ args: ['snailmail', '', 0, true],
+ }));
+ this.update({
+ snailmail_credits_url_trial,
+ });
+ },
+});
+
+registerFieldPatchModel('mail.messaging', 'snailmail/static/src/models/messaging/messaging.js', {
+ snailmail_credits_url: attr(),
+ snailmail_credits_url_trial: attr(),
+});
+
+});
diff --git a/addons/snailmail/static/src/models/notification_group/notification_group.js b/addons/snailmail/static/src/models/notification_group/notification_group.js
new file mode 100644
index 00000000..3fff33cb
--- /dev/null
+++ b/addons/snailmail/static/src/models/notification_group/notification_group.js
@@ -0,0 +1,62 @@
+odoo.define('snailmail/static/src/models/notification_group/notification_group.js', function (require) {
+'use strict';
+
+const {
+ registerInstancePatchModel,
+} = require('mail/static/src/model/model_core.js');
+
+registerInstancePatchModel('mail.notification_group', 'snailmail/static/src/models/notification_group/notification_group.js', {
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ openCancelAction() {
+ if (this.notification_type !== 'snail') {
+ return this._super(...arguments);
+ }
+ this.env.bus.trigger('do-action', {
+ action: 'snailmail.snailmail_letter_cancel_action',
+ options: {
+ additional_context: {
+ default_model: this.res_model,
+ unread_counter: this.notifications.length,
+ },
+ },
+ });
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ _openDocuments() {
+ if (this.notification_type !== 'snail') {
+ return this._super(...arguments);
+ }
+ this.env.bus.trigger('do-action', {
+ action: {
+ name: this.env._t("Snailmail Failures"),
+ type: 'ir.actions.act_window',
+ view_mode: 'kanban,list,form',
+ views: [[false, 'kanban'], [false, 'list'], [false, 'form']],
+ target: 'current',
+ res_model: this.res_model,
+ domain: [['message_ids.snailmail_error', '=', true]],
+ },
+ });
+ if (this.env.messaging.device.isMobile) {
+ // messaging menu has a higher z-index than views so it must
+ // be closed to ensure the visibility of the view
+ this.env.messaging.messagingMenu.close();
+ }
+ },
+});
+
+});