summaryrefslogtreecommitdiff
path: root/addons/snailmail/wizard
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/wizard
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/snailmail/wizard')
-rw-r--r--addons/snailmail/wizard/__init__.py4
-rw-r--r--addons/snailmail/wizard/snailmail_confirm.py50
-rw-r--r--addons/snailmail/wizard/snailmail_confirm_views.xml16
-rw-r--r--addons/snailmail/wizard/snailmail_letter_cancel.py26
-rw-r--r--addons/snailmail/wizard/snailmail_letter_cancel_views.xml27
-rw-r--r--addons/snailmail/wizard/snailmail_letter_format_error.py28
-rw-r--r--addons/snailmail/wizard/snailmail_letter_format_error_views.xml30
-rw-r--r--addons/snailmail/wizard/snailmail_letter_missing_required_fields.py52
-rw-r--r--addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml39
9 files changed, 272 insertions, 0 deletions
diff --git a/addons/snailmail/wizard/__init__.py b/addons/snailmail/wizard/__init__.py
new file mode 100644
index 00000000..de2f4be2
--- /dev/null
+++ b/addons/snailmail/wizard/__init__.py
@@ -0,0 +1,4 @@
+from . import snailmail_confirm
+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_confirm.py b/addons/snailmail/wizard/snailmail_confirm.py
new file mode 100644
index 00000000..42fe4e0c
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_confirm.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models, _
+
+
+class SnailmailConfirm(models.AbstractModel):
+ _name = 'snailmail.confirm'
+ _description = 'Snailmail Confirm'
+
+ model_name = fields.Char()
+
+ @api.model
+ def show_warning(self):
+ return not self.env['ir.config_parameter'].sudo().get_param('%s.warning_shown' % self._name, False)
+
+ def action_open(self):
+ view = self.env.ref('snailmail.snailmail_confirm_view')
+ return {
+ 'name': _('Snailmail'),
+ 'type': 'ir.actions.act_window',
+ 'view_mode': 'form',
+ 'res_model': self._name,
+ 'views': [(view.id, 'form')],
+ 'view_id': view.id,
+ 'target': 'new',
+ 'res_id': self.id,
+ 'context': self.env.context
+ }
+
+ def action_confirm(self):
+ self.env['ir.config_parameter'].sudo().set_param('%s.warning_shown' % self._name, True)
+ self._confirm()
+ return self._continue()
+
+ def action_cancel(self):
+ self.env['ir.config_parameter'].sudo().set_param('%s.warning_shown' % self._name, True)
+ return self._continue()
+
+ """
+ Called whether the user confirms or cancels posting the letter, e.g. to continue the action
+ """
+ def _continue(self):
+ pass
+
+ """
+ Called only when the user confirms sending the letter
+ """
+ def _confirm(self):
+ pass
diff --git a/addons/snailmail/wizard/snailmail_confirm_views.xml b/addons/snailmail/wizard/snailmail_confirm_views.xml
new file mode 100644
index 00000000..4df4d9de
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_confirm_views.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="snailmail_confirm_view" model="ir.ui.view">
+ <field name="name">snailmail.confirm.view</field>
+ <field name="model">snailmail.confirm</field>
+ <field name="arch" type="xml">
+ <form string="Snailmail Confirmation">
+ <p>You are about to send this <field name="model_name" readonly="1" class="oe_inline" /> by post. Are you sure you want to continue?</p>
+ <footer>
+ <button string="Confirm" name="action_confirm" type="object" class="btn-primary" />
+ <button string="Cancel" name="action_cancel" type="object" class="btn-secondary" />
+ </footer>
+ </form>
+ </field>
+ </record>
+</odoo>
diff --git a/addons/snailmail/wizard/snailmail_letter_cancel.py b/addons/snailmail/wizard/snailmail_letter_cancel.py
new file mode 100644
index 00000000..59d55325
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_cancel.py
@@ -0,0 +1,26 @@
+
+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.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'))
+
+ 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 00000000..1729c105
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_cancel_views.xml
@@ -0,0 +1,27 @@
+<?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_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 00000000..38168101
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_format_error.py
@@ -0,0 +1,28 @@
+
+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',
+ default=lambda self: self.env.context.get('message_id', None),
+ )
+ snailmail_cover = fields.Boolean(
+ string='Add a Cover Page',
+ default=lambda self: self.env.company.snailmail_cover,
+ )
+
+ def update_resend_action(self):
+ self.env.company.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()
+
+ 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 00000000..8277cf95
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_format_error_views.xml
@@ -0,0 +1,30 @@
+<?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_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 00000000..4216f3f8
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_missing_required_fields.py
@@ -0,0 +1,52 @@
+
+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):
+ defaults = super(SnailmailLetterMissingRequiredFields, self).default_get(fields)
+ if defaults.get('letter_id'):
+ letter = self.env['snailmail.letter'].browse(defaults.get('letter_id'))
+ defaults.update({
+ 'partner_id': letter.partner_id.id,
+ 'street': letter.street,
+ 'street2': letter.street2,
+ 'zip': letter.zip,
+ 'city': letter.city,
+ 'state_id': letter.state_id.id,
+ 'country_id': letter.country_id.id,
+ })
+ return defaults
+
+ def update_address_cancel(self):
+ self.letter_id.cancel()
+
+ 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 00000000..dccd802e
--- /dev/null
+++ b/addons/snailmail/wizard/snailmail_letter_missing_required_fields_views.xml
@@ -0,0 +1,39 @@
+<?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>
+ <!-- Field present for correct default_get behavior -->
+ <field name="letter_id" invisible="1"/>
+ <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_mode">form</field>
+ <field name="target">new</field>
+ </record>
+</odoo>