[IMP] l10n_ch

Add a new button to generate the ISR and remove the "double generation" of reports on 'Print invoice' button. This modification brings the code back to its original version and hence fixes the javascript bugs that occured with less than 3 workers running on the server and with Google Chrome when triggering multiple downloads simultaneously.

[ADD] account

Add a identifier to the 'register payment' button in order to reference it more easily and add the 'Print ISR' next to it.

[FIX] l10n_ch

The module did not install itself anymore, an import was missing.

Report generation was crashing due to a function's suppression.
This commit is contained in:
Olivier Colson
2017-03-06 16:43:26 +01:00
parent cb00be643a
commit 5169b50efe
7 changed files with 107 additions and 22 deletions
@@ -352,7 +352,7 @@
<button name="invoice_print" string="Print Invoice" type="object" attrs="{'invisible':['|',('sent','=',True), ('state', '!=', 'open')]}" class="oe_highlight" groups="base.group_user"/>
<button name="action_invoice_sent" type="object" string="Send by Email" attrs="{'invisible':['|',('sent','=',False), ('state', '!=', 'open')]}" groups="base.group_user"/>
<button name="invoice_print" string="Print Invoice" type="object" attrs="{'invisible':['|',('sent','=',False), ('state', '!=', 'open')]}" groups="base.group_user"/>
<button name="%(action_account_invoice_payment)d" type="action" states="open" string="Register Payment" groups="account.group_account_invoice" class="oe_highlight"/>
<button name="%(action_account_invoice_payment)d" id="account_invoice_payment_btn" type="action" states="open" string="Register Payment" groups="account.group_account_invoice" class="oe_highlight"/>
<button name="action_invoice_open" type="object" states="draft" string="Validate" class="oe_highlight" groups="account.group_account_invoice"/>
<button name="%(action_account_invoice_refund)d" type='action' string='Refund Invoice' groups="account.group_account_invoice" attrs="{'invisible': ['|',('type', '=', 'out_refund'), ('state', 'not in', ('open','paid'))]}"/>
<button name="action_invoice_cancel" type="object" states="draft,open" string="Cancel Invoice" groups="base.group_no_one"/>
+2
View File
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import models
from odoo import api, SUPERUSER_ID
def load_translations(cr, registry):
+1
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import account_invoice
import mail_compose_message
import mail_template
import res_bank
import res_company
+38 -9
View File
@@ -3,7 +3,8 @@
import re
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_split_str
from odoo.tools.misc import mod10r
@@ -24,6 +25,9 @@ class AccountInvoice(models.Model):
l10n_ch_isr_valid = fields.Boolean(compute='_compute_l10n_ch_isr_valid', help='Boolean value. True iff all the data required to generate the ISR are present')
l10n_ch_isr_sent = fields.Boolean(defaut=False, help="Boolean value telling whether or not the ISR corresponding to this invoice has already been printed or sent by mail.")
l10n_ch_currency_name = fields.Char(related='currency_id.name', help="The name of this invoice's currency") #This field is used in the "invisible" condition field of the 'Print ISR' button.
@api.depends('partner_bank_id.bank_id.l10n_ch_postal_eur', 'partner_bank_id.bank_id.l10n_ch_postal_chf')
def _compute_l10n_ch_isr_postal(self):
""" Computes the postal reference identifying the bank managing this ISR and formats it accordingly"""
@@ -125,15 +129,40 @@ class AccountInvoice(models.Model):
record.l10n_ch_isr_postal and \
record.partner_bank_id and \
record.partner_bank_id.l10n_ch_postal and \
record.currency_id.name in ['EUR', 'CHF']
record.l10n_ch_currency_name in ['EUR', 'CHF']
def invoice_print(self):
""" Triggered by the 'print invoice' button. When printing the invoice, also print
the ISR if the invoice is compatible.
def split_total_amount(self):
""" Splits the total amount of this invoice in two parts, using the dot as
a separator, and taking two precision digits (always displayed).
These two parts are returned as the two elements of a tuple, as strings
to print in the report.
This function is needed on the model, as it must be called in the report
template, which cannot reference static functions
"""
return float_split_str(self.amount_total, 2)
def isr_print(self):
""" Triggered by the 'Print ISR' button.
"""
self.ensure_one()
invoice_report = super(AccountInvoice, self).invoice_print()
if self.l10n_ch_isr_valid:
isr_report = self.env['report'].get_action(self, 'l10n_ch.isr_report_main')
invoice_report['next_report_to_generate'] = isr_report
return invoice_report
self.l10n_ch_isr_sent = True
return self.env['report'].get_action(self, 'l10n_ch.isr_report_main')
else:
raise ValidationError(_("""You cannot generate an ISR yet.\n
For this, you need to :\n
- set a valid postal account number (or an IBAN referencing one) for your company\n
- define its bank\n
- associate this bank with a postal reference for the currency used in this invoice\n
- fill the 'bank account' field of the invoice with the postal to be used to receive the related payment. A default account will be automatically set for all invoices created after you defined a postal account for your company."""))
def action_invoice_sent(self):
""" Overridden. Triggered by the 'send by mail' button.
"""
rslt = super(AccountInvoice, self).action_invoice_sent()
if self.l10n_ch_isr_valid:
rslt['context']['l10n_ch_mark_isr_as_sent'] = True
return rslt
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
class MailComposer(models.TransientModel):
_inherit = 'mail.compose.message'
@api.multi
def send_mail(self, auto_commit=False):
""" Method overriden to mark ISR as sent once a mail containing
it in attachment has been sent.
"""
context = self._context
if context.get('default_model') == 'account.invoice' and \
context.get('default_res_id') and \
context.get('l10n_ch_mark_isr_as_sent', False):
invoice = self.env['account.invoice'].browse(context['default_res_id'])
invoice = invoice.with_context(mail_post_autofollow=True)
invoice.l10n_ch_isr_sent = True
invoice.message_post(body=_("ISR sent"))
return super(MailComposer, self).send_mail(auto_commit=auto_commit)
+10 -12
View File
@@ -4,6 +4,7 @@
import time
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.exceptions import ValidationError
class ISRTest(AccountingTestCase):
@@ -45,23 +46,20 @@ class ISRTest(AccountingTestCase):
'acc_number': number
})
def print_isr(self, invoice):
try:
invoice.isr_print()
return True
except ValidationError:
return False
def isr_not_generated(self, invoice):
""" Prints the given invoice and tests that no ISR generation is triggered. """
next_action = invoice.invoice_print()
iterated_actions = []
while next_action and next_action not in iterated_actions:
self.assertNotEqual(next_action['report_name'], 'l10n_ch.isr_report_main', 'No ISR should be generated for this invoice')
next_action = next_action.get('next_report_to_generate', None)
self.assertFalse(self.print_isr(invoice), 'No ISR should be generated for this invoice')
def isr_generated(self, invoice):
""" Prints the given invoice and tests that an ISR generation is triggered. """
next_action = invoice.invoice_print()
iterated_actions = []
isr_found = False
while next_action and next_action not in iterated_actions and not isr_found:
isr_found = next_action['report_name'] == 'l10n_ch.isr_report_main'
next_action = next_action.get('next_report_to_generate', None)
self.assertTrue(isr_found, 'An ISR should have been generated')
self.assertTrue(self.print_isr(invoice), 'An ISR should have been generated')
def test_l10n_ch_postals(self):
#An account whose number is set to a valid postal number becomes a 'postal'
@@ -9,6 +9,36 @@
<xpath expr="//field[@name='partner_bank_id']" position="attributes">
<attribute name="invisible">0</attribute>
</xpath>
<xpath expr="//field[@name='sent']" position="after">
<field name="l10n_ch_isr_sent" invisible="1"/>
<field name="l10n_ch_currency_name" invisible="1"/>
</xpath>
<xpath expr="//button[@id='account_invoice_payment_btn']" position="before">
<button id="l10n_ch_btn_isr_print_highlight"
name="isr_print"
string="Print ISR"
type="object"
attrs="{'invisible':['|', ('l10n_ch_isr_sent', '=', True),
'|', ('state', '!=', 'open'),
('l10n_ch_currency_name', 'not in', ['EUR', 'CHF'])]}"
class="oe_highlight"
groups="base.group_user"
/>
</xpath>
<xpath expr="//button[@id='account_invoice_payment_btn']" position="before">
<button id="btn_isr_print_normal"
name="isr_print"
string="Print ISR"
type="object"
attrs="{'invisible':['|', ('l10n_ch_isr_sent', '=', False),
'|', ('state', '!=', 'open'),
('l10n_ch_currency_name', 'not in', ['EUR', 'CHF'])]}"
groups="base.group_user"
/>
</xpath>
</field>
</record>