summaryrefslogtreecommitdiff
path: root/addons/snailmail/wizard
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/wizard
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/wizard')
-rw-r--r--addons/snailmail/wizard/__init__.py3
-rw-r--r--addons/snailmail/wizard/snailmail_letter_cancel.py28
-rw-r--r--addons/snailmail/wizard/snailmail_letter_cancel_views.xml28
-rw-r--r--addons/snailmail/wizard/snailmail_letter_format_error.py34
-rw-r--r--addons/snailmail/wizard/snailmail_letter_format_error_views.xml31
-rw-r--r--addons/snailmail/wizard/snailmail_letter_missing_required_fields.py54
-rw-r--r--addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml38
7 files changed, 216 insertions, 0 deletions
diff --git a/addons/snailmail/wizard/__init__.py b/addons/snailmail/wizard/__init__.py
new file mode 100644
index 00000000000..86a507b287b
--- /dev/null
+++ b/addons/snailmail/wizard/__init__.py
@@ -0,0 +1,3 @@
+from . import snailmail_letter_cancel
+from . import snailmail_letter_format_error
+from . import snailmail_letter_missing_required_fields
diff --git a/addons/snailmail/wizard/snailmail_letter_cancel.py b/addons/snailmail/wizard/snailmail_letter_cancel.py
new file mode 100644
index 00000000000..3cb5aa1621c
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_cancel.py
@@ -0,0 +1,28 @@
+
+from odoo import _, api, fields, models
+
+class SnailmailLetterCancel(models.TransientModel):
+ _name = 'snailmail.letter.cancel'
+ _description = 'Dismiss notification for resend by model'
+
+ model = fields.Char(string='Model')
+ help_message = fields.Char(string='Help message', compute='_compute_help_message')
+
+ @api.multi
+ @api.depends('model')
+ def _compute_help_message(self):
+ for wizard in self:
+ wizard.help_message = _("Are you sure you want to discard %s snailmail delivery failures. You won't be able to re-send these letters later!") % (wizard._context.get('unread_counter'))
+
+ @api.multi
+ def cancel_resend_action(self):
+ author_id = self.env.user.id
+ for wizard in self:
+ letters = self.env['snailmail.letter'].search([
+ ('state', 'not in', ['sent', 'canceled', 'pending']),
+ ('user_id', '=', author_id),
+ ('model', '=', wizard.model)
+ ])
+ for letter in letters:
+ letter.cancel()
+ return {'type': 'ir.actions.act_window_close'}
diff --git a/addons/snailmail/wizard/snailmail_letter_cancel_views.xml b/addons/snailmail/wizard/snailmail_letter_cancel_views.xml
new file mode 100644
index 00000000000..d244985b147
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_cancel_views.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="snailmail_letter_cancel" model="ir.ui.view">
+ <field name="name">snailmail.letter.cancel.form</field>
+ <field name="model">snailmail.letter.cancel</field>
+ <field name="groups_id" eval="[(4,ref('base.group_user'))]"/>
+ <field name="arch" type="xml">
+ <form string="Cancel notification in failure">
+ <field name="model" invisible='1'/>
+ <field name="help_message"/>
+ <p>If you want to re-send them, click Cancel now, then click on the notification and review them one by one by clicking on the red paper-plane next to each message.</p>
+ <footer>
+ <button string="Discard delivery failures" name="cancel_resend_action" type="object" class="btn-primary" />
+ <button string="Cancel" class="btn-secondary" special="cancel" />
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="snailmail_letter_cancel_action" model="ir.actions.act_window">
+ <field name="name">Discard snailmail delivery failures</field>
+ <field name="res_model">snailmail.letter.cancel</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+</odoo>
diff --git a/addons/snailmail/wizard/snailmail_letter_format_error.py b/addons/snailmail/wizard/snailmail_letter_format_error.py
new file mode 100644
index 00000000000..1eb92654e42
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_format_error.py
@@ -0,0 +1,34 @@
+
+from odoo import api, fields, models
+
+class SnailmailLetterFormatError(models.TransientModel):
+ _name = 'snailmail.letter.format.error'
+ _description = 'Format Error Sending a Snailmail Letter'
+
+ message_id = fields.Many2one('mail.message')
+ snailmail_cover = fields.Boolean(string='Add a Cover Page')
+
+ @api.model
+ def default_get(self, fields):
+ res = super(SnailmailLetterFormatError, self).default_get(fields)
+ snailmail_cover = self.env.user.company_id.snailmail_cover
+ res.update({
+ 'message_id': self.env.context.get('message_id'),
+ 'snailmail_cover': snailmail_cover,
+ })
+ return res
+
+ @api.multi
+ def update_resend_action(self):
+ self.env.user.company_id.write({'snailmail_cover': self.snailmail_cover})
+ letters_to_resend = self.env['snailmail.letter'].search([
+ ('error_code', '=', 'FORMAT_ERROR'),
+ ])
+ for letter in letters_to_resend:
+ letter.attachment_id.unlink()
+ letter.write({'cover': self.snailmail_cover})
+ letter.snailmail_print()
+
+ @api.multi
+ def cancel_letter_action(self):
+ self.message_id.cancel_letter()
diff --git a/addons/snailmail/wizard/snailmail_letter_format_error_views.xml b/addons/snailmail/wizard/snailmail_letter_format_error_views.xml
new file mode 100644
index 00000000000..35ba55047fe
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_format_error_views.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="snailmail_letter_format_error" model="ir.ui.view">
+ <field name="name">snailmail.letter.format.error.form</field>
+ <field name="model">snailmail.letter.format.error</field>
+ <field name="groups_id" eval="[(4,ref('base.group_user'))]"/>
+ <field name="arch" type="xml">
+ <form string="Cancel notification in failure">
+ <p>Our service cannot read your letter due to its format.<br/>
+ Please modify the format of the template or update your settings
+ to automatically add a blank cover page to all letters.</p>
+ <field name="snailmail_cover"/>
+ <label string="Add a Cover Page" class="o_light_label" for="snailmail_cover"/>
+ <footer>
+ <button string="Update Config and Re-send" name="update_resend_action" type="object" class="btn-primary" />
+ <button string="Cancel Letter" name="cancel_letter_action" type="object" class="btn-primary" />
+ <button string="Close" class="btn-secondary" special="cancel" />
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="snailmail_letter_format_error_action" model="ir.actions.act_window">
+ <field name="name">Format Error</field>
+ <field name="res_model">snailmail.letter.format.error</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+</odoo>
diff --git a/addons/snailmail/wizard/snailmail_letter_missing_required_fields.py b/addons/snailmail/wizard/snailmail_letter_missing_required_fields.py
new file mode 100644
index 00000000000..a6b82807be9
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_missing_required_fields.py
@@ -0,0 +1,54 @@
+
+from odoo import _, api, fields, models
+
+class SnailmailLetterMissingRequiredFields(models.TransientModel):
+ _name = 'snailmail.letter.missing.required.fields'
+ _description = 'Update address of partner'
+
+ partner_id = fields.Many2one('res.partner')
+ letter_id = fields.Many2one('snailmail.letter')
+
+ street = fields.Char('Street')
+ street2 = fields.Char('Street2')
+ zip = fields.Char('Zip')
+ city = fields.Char('City')
+ state_id = fields.Many2one("res.country.state", string='State')
+ country_id = fields.Many2one('res.country', string='Country')
+
+ @api.model
+ def default_get(self, fields):
+ rec = super(SnailmailLetterMissingRequiredFields, self).default_get(fields)
+ letter_id = self.env['snailmail.letter'].browse(self.env.context.get('letter_id'))
+ rec.update({
+ 'partner_id': letter_id.partner_id.id,
+ 'letter_id': letter_id.id,
+ 'street': letter_id.street,
+ 'street2': letter_id.street2,
+ 'zip': letter_id.zip,
+ 'city': letter_id.city,
+ 'state_id': letter_id.state_id.id,
+ 'country_id': letter_id.country_id.id,
+ })
+ return rec
+
+ @api.multi
+ def update_address_cancel(self):
+ self.letter_id.cancel()
+
+ @api.multi
+ def update_address_save(self):
+ address_data = {
+ 'street': self.street,
+ 'street2': self.street2,
+ 'zip': self.zip,
+ 'city': self.city,
+ 'state_id': self.state_id.id,
+ 'country_id': self.country_id.id,
+ }
+ self.partner_id.write(address_data)
+ letters_to_resend = self.env['snailmail.letter'].search([
+ ('partner_id', '=', self.partner_id.id),
+ ('error_code', '=', 'MISSING_REQUIRED_FIELDS'),
+ ])
+ letters_to_resend.write(address_data)
+ letters_to_resend.snailmail_print()
diff --git a/addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml b/addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml
new file mode 100644
index 00000000000..b4be9c7d74a
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="snailmail_letter_missing_required_fields" model="ir.ui.view">
+ <field name="name">snailmail.letter.missing.required.fields.form</field>
+ <field name="model">snailmail.letter.missing.required.fields</field>
+ <field name="arch" type="xml">
+ <form>
+ <p>The customer address is not complete. Update the address here and re-send the letter.</p>
+ <group>
+ <label for="partner_id" string="Address"/>
+ <div class="o_address_format">
+ <field name="partner_id" readonly="1" options="{'no_open': True}"/>
+ <field name="street" placeholder="Street..." class="o_address_street"/>
+ <field name="street2" placeholder="Street 2..." class="o_address_street"/>
+ <field name="city" placeholder="City" class="o_address_city"/>
+ <field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}'/>
+ <field name="zip" placeholder="ZIP" class="o_address_zip"/>
+ <field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
+ </div>
+ </group>
+ <footer>
+ <button string="Update address and re-send" type="object" name="update_address_save" class="btn-primary"/>
+ <button string="Cancel letter" type="object" name="update_address_cancel" class="btn-secondary"/>
+ <button string="Close" special='cancel' class="btn-secondary"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="snailmail_letter_missing_required_fields_action" model="ir.actions.act_window">
+ <field name="name">Failed letter</field>
+ <field name="res_model">snailmail.letter.missing.required.fields</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+</odoo>