[IMP] snailmail_account: Incomplete address improvements
If 'send by post' is enabled and the address is incomplete when we send one invoice, display: "The customer's address is incomplete:" followed by a link to the corresponding partner If 'send by post' is enabled and some addresses are incomplete when we send invoices in batch, display: "Some customer addresses are incomplete. [number of incompete addresses] Contacts" and if we click the Contacts, we will be redirected to the corresponding Contacts Purpose: When the user tries to send an invoice by post, the system warns him that the customer's address is incomplete. But then, it's a dead end. The user doesn't have any tool to rectify the situation. closes odoo/odoo#69469 Taskid: 2502597 Related: odoo/upgrade#2445 Signed-off-by: Arnaud Joset <arj-odoo@users.noreply.github.com>
This commit is contained in:
committed by
Arnaud Joset
parent
e43c424fd9
commit
b31e11bba3
@@ -1,8 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo import api, fields, models, Command, _
|
||||
|
||||
|
||||
class AccountInvoiceSend(models.TransientModel):
|
||||
@@ -16,14 +15,17 @@ class AccountInvoiceSend(models.TransientModel):
|
||||
default=lambda self: self.env.company.invoice_is_snailmail)
|
||||
snailmail_cost = fields.Float(string='Stamp(s)', compute='_compute_snailmail_cost', readonly=True)
|
||||
invalid_addresses = fields.Integer('Invalid Addresses Count', compute='_compute_invalid_addresses')
|
||||
invalid_invoice_ids = fields.Many2many('account.move', string='Invalid Addresses', compute='_compute_invalid_addresses')
|
||||
invalid_invoices = fields.Integer('Invalid Invoices Count', compute='_compute_invalid_addresses')
|
||||
invalid_partner_ids = fields.Many2many('res.partner', string='Invalid Addresses', compute='_compute_invalid_addresses')
|
||||
|
||||
@api.depends('invoice_ids')
|
||||
def _compute_invalid_addresses(self):
|
||||
for wizard in self:
|
||||
invalid_invoices = wizard.invoice_ids.filtered(lambda i: not i.partner_id or not self.env['snailmail.letter']._is_valid_address(i.partner_id))
|
||||
wizard.invalid_invoice_ids = invalid_invoices
|
||||
wizard.invalid_addresses = len(invalid_invoices)
|
||||
invalid_invoices = wizard.invoice_ids.filtered(lambda i: not self.env['snailmail.letter']._is_valid_address(i.partner_id))
|
||||
wizard.invalid_invoices = len(invalid_invoices)
|
||||
invalid_partner_ids = invalid_invoices.partner_id.ids
|
||||
wizard.invalid_addresses = len(invalid_partner_ids)
|
||||
wizard.invalid_partner_ids = [Command.set(invalid_partner_ids)]
|
||||
|
||||
@api.depends('invoice_ids')
|
||||
def _get_partner(self):
|
||||
@@ -82,7 +84,7 @@ class AccountInvoiceSend(models.TransientModel):
|
||||
self.env['bus.bus'].sendone(
|
||||
(self._cr.dbname, 'res.partner', self.env.user.partner_id.id),
|
||||
{'type': 'snailmail_invalid_address', 'title': _("Invalid Addresses"),
|
||||
'message': _("%s of the selected invoice(s) had an invalid address and were not sent", self.invalid_addresses)}
|
||||
'message': _("%s of the selected invoice(s) had an invalid address and were not sent", self.invalid_invoices)}
|
||||
)
|
||||
|
||||
def invalid_addresses_action(self):
|
||||
@@ -90,6 +92,6 @@ class AccountInvoiceSend(models.TransientModel):
|
||||
'name': _('Invalid Addresses'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'kanban,tree,form',
|
||||
'res_model': 'account.move',
|
||||
'domain': [('id', 'in', self.mapped('invalid_invoice_ids').ids)],
|
||||
'res_model': 'res.partner',
|
||||
'domain': [('id', 'in', self.invalid_partner_ids.ids)],
|
||||
}
|
||||
|
||||
@@ -23,28 +23,16 @@
|
||||
<i class="fa fa-info-circle" role="img" aria-label="Warning" title="Make sure you have enough Stamps on your account."/>
|
||||
)</b>
|
||||
</span>
|
||||
<span attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}">
|
||||
<span attrs="{'invisible': [('invalid_addresses', '!=', 0)]}">
|
||||
<div class="text-right text-muted d-inline-block" name="address">
|
||||
<span> to: </span>
|
||||
<field name="partner_id" readonly="1" force_save="1" context="{'show_address': 1, 'address_inline': 1}" options="{'always_reload': True, 'no_quick_create': True}"/>
|
||||
</div>
|
||||
</span>
|
||||
<span attrs="{'invisible': [('invalid_addresses', '=', 0)]}">
|
||||
<div class="text-right d-inline-block" attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}">
|
||||
<span class="text-danger">
|
||||
The customer address is not complete.
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
<span class="text-right d-inline-block " attrs="{'invisible': ['|', ('composition_mode', '=', 'mass_mail'), ('partner_id', '=', False)]}" name="address">
|
||||
<span class="text-muted" attrs="{'invisible': [('invalid_addresses', '!=', 0)]}"> to: </span>
|
||||
<span class="text-danger" attrs="{'invisible': [('invalid_addresses', '=', 0)]}"> The customer's address is incomplete: </span>
|
||||
<field name="partner_id" readonly="1" force_save="1" context="{'show_address': 1, 'address_inline': 1}" options="{'always_reload': True, 'no_quick_create': True}"/>
|
||||
</span>
|
||||
<span attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}">
|
||||
<span attrs="{'invisible': [('invalid_addresses', '=', 0)]}">
|
||||
<span class="text-danger">
|
||||
Some customer addresses are not complete.
|
||||
</span>
|
||||
<button type="object" name="invalid_addresses_action" class="btn btn-link" role="button"><field name="invalid_addresses" readonly="1" options="{'digits':[0,0]}"/> invoices</button>
|
||||
<span attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('invalid_addresses', '=', 0)]}">
|
||||
<span class="text-danger">
|
||||
Some customer addresses are incomplete.
|
||||
</span>
|
||||
<button type="object" name="invalid_addresses_action" class="btn btn-link" role="button"><field name="invalid_addresses" readonly="1" options="{'digits':[0,0]}"/> Contacts</button>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user