[IMP] snailmail: Show the price in terms of stamps

- The price of sending a letter was displayed in the currency of the company, now we express the price in terms of stamps
- Show a different message in the modal depending on the validity of the address
This commit is contained in:
Antoine Prieels (ANP)
2018-11-22 15:38:42 +00:00
committed by Rémi Rahir
parent d5ca268438
commit f68df47ddf
3 changed files with 45 additions and 17 deletions
+2 -2
View File
@@ -211,7 +211,7 @@ class SnailmailLetter(models.Model):
'options': {
'color': self and self[0].color,
'duplex': self and self[0].duplex,
'currency_name': self and self[0].company_id.currency_id.name,
'currency_name': 'EUR',
},
# this will not raise the InsufficientCreditError which is the behaviour we want for now
'batch': True,
@@ -307,7 +307,7 @@ class SnailmailLetter(models.Model):
@api.multi
def unlink(self):
self.mapped('activity_id').unlink()
super(SnailmailLetter, self).unlink()
return super(SnailmailLetter, self).unlink()
@api.multi
def _snailmail_estimate(self):
@@ -12,8 +12,13 @@ class AccountInvoiceSend(models.TransientModel):
partner_id = fields.Many2one('res.partner', compute='_get_partner', string='Partner')
snailmail_is_letter = fields.Boolean('Send by Post', help='Allows to send the document by snail mail (coventional posting delivery service)', default=lambda self: self.env.user.company_id.invoice_is_snailmail)
snailmail_cost = fields.Float(string='Stamp(s)', compute='_snailmail_estimate', store=True, readonly=True)
currency_id = fields.Many2one('res.currency', compute='_get_invoice_currency', string="Currency")
letter_ids = fields.Many2many('snailmail.letter', 'snailmail_letter_account_invoice_send_rel', ondelete='cascade')
invalid_addresses = fields.Integer('Invalid Addresses', compute='_compute_invalid_addresses')
@api.depends('snailmail_cost', 'letter_ids')
def _compute_invalid_addresses(self):
for wizard in self:
wizard.invalid_addresses = len(wizard.letter_ids) - wizard.snailmail_cost
@api.multi
@api.onchange('invoice_ids')
@@ -9,25 +9,48 @@
<xpath expr="//div[@name='option_email']" position='before'>
<div name="option_letter">
<field name="letter_ids" invisible="1"/>
<field name="invalid_addresses" invisible="1"/>
<div name="option" class="text-left d-inline-block">
<field name="snailmail_is_letter" />
<b><label for="snailmail_is_letter"/></b>
</div>
<div class="text-left d-inline-block mr8" name='cost' attrs="{'invisible': [('snailmail_is_letter','=', False)]}">
<b>(
<span>
<field name="snailmail_cost" options="{'digits':[0,0]}" class="mr4"/>
<label for="snailmail_cost" class="mr4"/>
<span attrs="{'invisible': [('snailmail_is_letter','=', False)]}">
<span class="mr4" attrs="{'invisible': [('snailmail_cost', '=', 0)]}">
<b>(
<span>
<field name="snailmail_cost" options="{'digits':[0,0]}" class="mr4"/>
<label for="snailmail_cost" class="mr4"/>
</span>
<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': not invalid_addresses, 'address_inline': 1}" options="{'always_reload': True, 'no_quick_create': True}"/>
</div>
</span>
<i class="fa fa-info-circle" role="img" aria-label="Warning" title="
The letter will be sent using the IAP service from Odoo.&#10;Make sure you have enough credits on your account or proceed to a recharge.&#10;The price is estimated based on 1 page per document.
"/>
)</b>
</div>
<div class="text-right text-muted d-inline-block" name="address" attrs="{'invisible': ['|', ('composition_mode', '=', 'mass_mail'), ('snailmail_is_letter','=', False)]}">
<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 attrs="{'invisible': [('invalid_addresses', '=', 0)]}">
<div class="text-right d-inline-block" attrs="{'invisible': [('composition_mode', '=', 'mass_mail')]}">
<span class="text-muted">
Incomplete address for
<field name="partner_id" readonly="1" force_save="1" context="{'show_address': not invalid_addresses, 'address_inline': 1}" options="{'always_reload': True, 'no_quick_create': True}"/>
</span>
</div>
</span>
</span>
<span attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}">
<span attrs="{'invisible': [('snailmail_cost', '=', 0)]}">
<span class="text-muted" attrs="{'invisible': [('invalid_addresses', '=', 0)]}">
Only <field name="snailmail_cost" readonly="1" options="{'digits':[0,0]}"/> of the selected invoices have a valid address.
</span>
</span>
<span class="text-muted" attrs="{'invisible': [('snailmail_cost', '!=', 0)]}">
None of the selected invoices have a valid address
</span>
</span>
</span>
</div>
</xpath>
<xpath expr="//footer/button[hasclass('send_and_print')]" position='attributes'>