summaryrefslogtreecommitdiff
path: root/addons/snailmail/static/src/js/thread_widget.js
diff options
context:
space:
mode:
authorAntoine Prieels (ANP) <anp@odoo.com>2018-12-17 08:27:11 +0000
committerPierre Masereel <pim@odoo.com>2019-01-24 13:36:51 +0000
commit8f486db52da052ae6f6b979a83f85d5d2c0ed269 (patch)
treeab0b12feb0b0f3618b5c2174dd585259587340de /addons/snailmail/static/src/js/thread_widget.js
parent7274c0aa74cbbd221b5bbb941314e4b12af956ee (diff)
[IMP] mail, snailmail, snailmail_account: improve error management
When a letter is sent through snailmail and encounter an error, it used to create an activity to the user to notify him that there was an error with its letter. When a user had this activity, he didn't have any clues of what was the error and how to manage it. So we decided to better handle snailmail errors and give the possibility to the user to easily fix the source of the snailmail errors. First to give a better feedback on the letters in errors, we've made features similar to ones existing for emails: - We add a mail message on the document that sent the letter, and put a small paper plane icon, which is red when an error occurs (like the envelope for email) - As letters can be sent in batch, we've also added an entry in the systray to easily manage the different documents having snailmail errors like for emails. Then we identified, the most common errors encountered with the snailmail letters and give proper way to let the user fix them: - Missing Required Field: - The address is not complete, some of the fields are empty. - We open a wizard allowing the user to modify the partner address and we try to resend all letters having this error on the modified partner. - We also try to avoid this error, by opening the wizard before sending the letter, but it only works for single documents, not for batch. - Trial/Credit Error: - The user has not enough credits to send letters anymore. - We open a wizard that give a redirection lnk to add credits on its iap account. - No Price Available: - The destination country is not supported by any of our providers, and we cannot do anything to send this letter. - Format Error: - The format of the pdf report send by the user is refused by our providers, because some visual stuffs are not respected, for example blank zone to print barcode or margins. - We show a wizard to the user letting him check a setting option that add a cover page in the envelope and the documents will be send with this extra page containing the address. - Unknown Error: - This is not one of the listed error above. - A wizard suggesting the user to contact support is displayed. The cron that try to resend letters on error, has been addapted to only try to send the error of type Trial/No Credit, because the account might have been reloaded, and other errors, won't change if they have not been fixed locally. closes odoo/odoo#29685
Diffstat (limited to 'addons/snailmail/static/src/js/thread_widget.js')
-rw-r--r--addons/snailmail/static/src/js/thread_widget.js227
1 files changed, 227 insertions, 0 deletions
diff --git a/addons/snailmail/static/src/js/thread_widget.js b/addons/snailmail/static/src/js/thread_widget.js
new file mode 100644
index 00000000000..4fd2521b4c7
--- /dev/null
+++ b/addons/snailmail/static/src/js/thread_widget.js
@@ -0,0 +1,227 @@
+odoo.define('snailmail.widget.Thread', function (require) {
+"use strict";
+
+var ThreadWidget = require('mail.widget.Thread');
+var Dialog = require('web.Dialog');
+
+var core = require('web.core');
+var QWeb = core.qweb;
+var _t = core._t;
+
+ThreadWidget.include({
+ dependencies: ['bus_service'],
+ events: _.extend({}, ThreadWidget.prototype.events, {
+ 'click .o_thread_message_snailmail_missing_required_fields': '_onClickMissingRequiredFields',
+ 'click .o_thread_message_snailmail_credit_error': '_onClickCreditError',
+ 'click .o_thread_message_snailmail_trial_error': '_onClickTrialError',
+ 'click .o_thread_message_snailmail_no_price_available': '_onClickNoPriceAvailable',
+ 'click .o_thread_message_snailmail_format_error': '_onClickFormatError',
+ 'click .o_thread_message_snailmail_unknown_error': '_onClickUnknownError',
+ }),
+ /**
+ * @override
+ */
+ init: function () {
+ this._super.apply(this, arguments);
+ this._enabledOptions = _.defaults(this._enabledOptions, {
+ displaySnailmailIcons: true,
+ });
+ this._disabledOptions = _.defaults(this._disabledOptions, {
+ displaySnailmailIcons: false,
+ });
+ },
+ /**
+ * @override
+ */
+ render: function (thread, options) {
+ this._super.apply(this, arguments);
+ var messages = _.clone(thread.getMessages({ domain: options.domain || [] }));
+ this._messages = messages;
+ this._renderMessageSnailmailPopover();
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {integer} messageID
+ * @param {string} content
+ */
+ _openCreditErrorDialog: function (messageID, content) {
+ var message = _.find(this._messages, function (message) {
+ return message.getID() === messageID;
+ });
+ new Dialog(this, {
+ size: 'medium',
+ title: _t("Failed letter"),
+ $content: $('<div>').html(content),
+ buttons: [
+ {text: _t("Re-send letter"), classes: 'btn-primary', close: true, click: _.bind(message.resendLetter, message)},
+ {text: _t("Cancel letter"), close: true, click: _.bind(message.cancelLetter, message)},
+ {text: _t("Close"), close: true},
+ ],
+ }).open();
+ },
+ /**
+ * @private
+ * @param {integer} messageID
+ * @param {string} content
+ */
+ _openGenericErrorDialog: function (messageID, content) {
+ var message = _.find(this._messages, function (message) {
+ return message.getID() === messageID;
+ });
+ new Dialog(this, {
+ size: 'medium',
+ title: _t("Failed letter"),
+ $content: $('<div>').html(content),
+ buttons: [
+ {text: _t("Cancel letter"), classes: 'btn-primary', close: true, click: _.bind(message.cancelLetter, message)},
+ {text: _t("Close"), close: true},
+ ],
+ }).open();
+ },
+ /**
+ * Render the popover when mouse-hovering on the mail icon of a message
+ * in the thread. There is at most one such popover at any given time.
+ *
+ * @private
+ * @param {mail.model.AbstractMessage[]} messages list of messages in the
+ * rendered thread, for which popover on mouseover interaction is
+ * permitted.
+ */
+ _renderMessageSnailmailPopover: function () {
+ var self = this;
+ if (this._messageSnailmailPopover) {
+ this._messageSnailmailPopover.popover('hide');
+ }
+ if (!this.$('.o_thread_snailmail_tooltip').length) {
+ return;
+ }
+ this._messageSnailmailPopover = this.$('.o_thread_snailmail_tooltip').popover({
+ html: true,
+ boundary: 'viewport',
+ placement: 'auto',
+ trigger: 'hover',
+ offset: '0, 1',
+ content: function () {
+ var messageID = $(this).data('message-id');
+ var message = _.find(self._messages, function (message) {
+ return message.getID() === messageID;
+ });
+ return QWeb.render('snailmail.widget.Thread.Message.SnailmailTooltip', {
+ status: message.getSnailmailStatus()
+ });
+ },
+ });
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickCreditError: function (ev) {
+ var self = this;
+ var messageID = $(ev.currentTarget).data('message-id');
+ this._rpc({
+ model: 'iap.account',
+ method: 'get_credits_url',
+ args: ['snailmail'],
+ }).then(function (link) {
+ var content = _.str.sprintf(_t(
+ '<p>The letter could not be sent due to insufficient credits on your IAP account.</p>' +
+ '<div class= "text-right">' +
+ '<a class="btn btn-link buy_credits" href=%s>' +
+ '<i class= "fa fa-arrow-right"/> Buy credits' +
+ '</a>' +
+ '</div>'
+ ), link);
+ self._openCreditErrorDialog(messageID, content);
+ });
+ },
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickFormatError: function (ev) {
+ var messageID = $(ev.currentTarget).data('message-id');
+ this.do_action('snailmail.snailmail_letter_format_error_action', {
+ additional_context: {
+ message_id: messageID,
+ }
+ });
+ },
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickMissingRequiredFields: function (ev) {
+ var self = this;
+
+ var messageID = $(ev.currentTarget).data('message-id');
+ var domain = [['message_id', '=', messageID]];
+ this._rpc({
+ model: 'snailmail.letter',
+ method: 'search',
+ args: [domain],
+ }).then(function (letterIds) {
+ self.do_action('snailmail.snailmail_letter_missing_required_fields_action', {
+ additional_context: {
+ letter_id: letterIds[0]
+ },
+ on_close: function () {
+ self.trigger_up('reload');
+ }
+ });
+ });
+ },
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickNoPriceAvailable: function (ev) {
+ var messageID = $(ev.currentTarget).data('message-id');
+ var content = _t('<p>The country to which you want to send the letter is not supported by our service.</p>');
+ this._openGenericErrorDialog(messageID, content);
+ },
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickTrialError: function (ev) {
+ var self = this;
+ var messageID = $(ev.currentTarget).data('message-id');
+ this._rpc({
+ model: 'iap.account',
+ method: 'get_credits_url',
+ args: ['snailmail', '', 0, true],
+ }).then(function (link) {
+ var content = _.str.sprintf(_t(
+ '<p>You need credits on your IAP account to send a letter.</p>' +
+ '<div class= "text-right">' +
+ '<a class="btn btn-link buy_credits" href=%s>' +
+ '<i class= "fa fa-arrow-right"/> Buy credits' +
+ '</a>' +
+ '</div>'
+ ), link);
+ self._openCreditErrorDialog(messageID, content);
+ });
+ },
+ /**
+ * @private
+ * @param {MouseEvent} event
+ */
+ _onClickUnknownError: function (ev) {
+ var messageID = $(ev.currentTarget).data('message-id');
+ var content = _t('<p>An unknown error occured. Please contact our <a href="https://www.odoo.com/help" target="new">support</a> for further assistance.</p>');
+ this._openGenericErrorDialog(messageID, content);
+ },
+});
+
+});