[FIX] l10n_ke_edi_tremol: send proforma when missing legal info
With Kenya localization installed Create an invoice Send&Print Issue: The sytem will issue the final pdf before the invoice has been send to the fiscal device, so the legal information is actually missing Solution: 1. If the allow_fallback_pdf is True (in case of transaction from the e-commerce for example) we generate a proforma pdf invoice. 2. Else we raise an error to prevent the user to send invalid invoice. Also added a warning to let the user know that a proforma will be generated because the invoice was not sent to the Fiscal Device. opw-3599869 closes odoo/odoo#151751 Signed-off-by: Laurent Smet (las) <las@odoo.com> Signed-off-by: Andrea Grazioso (agr) <agr@odoo.com> Co-authored-by: Claire Bretton (clbr) <clbr@odoo.com>
This commit is contained in:
co-authored by
Claire Bretton
parent
5440bede82
commit
01532c2216
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
#
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -16,6 +16,7 @@ This module integrates with the Kenyan G03 Tremol control unit device to the KRA
|
||||
'views/report_invoice.xml',
|
||||
'views/res_config_settings_view.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'wizard/account_move_send_views.xml',
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
|
||||
@@ -258,6 +258,14 @@ msgid ""
|
||||
"The exemption number of the partner. Provided by the Kenyan government."
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ke_edi_tremol
|
||||
#. odoo-python
|
||||
#: code:addons/l10n_ke_edi_tremol/wizard/account_move_send.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"The following documents have no details related to the fiscal device."
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ke_edi_tremol
|
||||
#: model_terms:ir.ui.view,arch_db:l10n_ke_edi_tremol.res_config_settings_view_form
|
||||
msgid ""
|
||||
@@ -274,6 +282,16 @@ msgid ""
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ke_edi_tremol
|
||||
#. odoo-python
|
||||
#: code:addons/l10n_ke_edi_tremol/wizard/account_move_send.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"This document does not have details related to the fiscal device, a proforma"
|
||||
" invoice will be used."
|
||||
msgstr ""
|
||||
|
||||
#. module: l10n_ke_edi_tremol
|
||||
#. odoo-python
|
||||
#: code:addons/l10n_ke_edi_tremol/models/account_move.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
|
||||
@@ -80,6 +80,16 @@ class AccountMove(models.Model):
|
||||
|
||||
return errors
|
||||
|
||||
def _l10n_ke_fiscal_device_details_filled(self):
|
||||
self.ensure_one()
|
||||
return all([
|
||||
self.country_code == 'KE',
|
||||
self.l10n_ke_cu_invoice_number,
|
||||
self.l10n_ke_cu_serial_number,
|
||||
self.l10n_ke_cu_qrcode,
|
||||
self.l10n_ke_cu_datetime,
|
||||
])
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# SERIALISERS
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from .import test_move_export
|
||||
from . import test_account_move_send
|
||||
from . import test_move_export
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import tagged
|
||||
from odoo.addons.account.tests.test_account_move_send import TestAccountMoveSendCommon
|
||||
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install')
|
||||
class TestKEAccountMoveSend(TestAccountMoveSendCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref='ke'):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
|
||||
def test_sent_to_fiscal_device(self):
|
||||
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True, partner=self.partner_a)
|
||||
# Write data as if the invoice was successfully sent to fiscal device
|
||||
invoice.write({
|
||||
'l10n_ke_cu_invoice_number': 'test_ke_invoice_number',
|
||||
'l10n_ke_cu_serial_number': 'test_ke_serial_number',
|
||||
'l10n_ke_cu_qrcode': 'test_ke_qrcode',
|
||||
'l10n_ke_cu_datetime': fields.Datetime.now() - timedelta(days=1),
|
||||
})
|
||||
|
||||
wizard = self.create_send_and_print(invoice)
|
||||
self.assertFalse(wizard.l10n_ke_edi_warning_message)
|
||||
wizard.action_send_and_print()
|
||||
|
||||
self.assertTrue(invoice.invoice_pdf_report_id)
|
||||
|
||||
def test_not_sent_to_fiscal_device_but_allow_fallback(self):
|
||||
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True, partner=self.partner_a)
|
||||
wizard = self.create_send_and_print(invoice)
|
||||
self.assertTrue(wizard.l10n_ke_edi_warning_message)
|
||||
wizard.action_send_and_print(allow_fallback_pdf=True)
|
||||
|
||||
# The PDF is not generated but a proforma.
|
||||
self.assertFalse(invoice.invoice_pdf_report_id)
|
||||
self.assertTrue(self.env['ir.attachment'].search([
|
||||
('name', '=', invoice._get_invoice_proforma_pdf_report_filename()),
|
||||
]))
|
||||
|
||||
def test_not_sent_to_fiscal_device_raises(self):
|
||||
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True, partner=self.partner_a)
|
||||
wizard = self.create_send_and_print(invoice)
|
||||
self.assertTrue(wizard.l10n_ke_edi_warning_message)
|
||||
with self.assertRaisesRegex(UserError, wizard.l10n_ke_edi_warning_message):
|
||||
wizard.action_send_and_print()
|
||||
@@ -0,0 +1 @@
|
||||
from . import account_move_send
|
||||
@@ -0,0 +1,36 @@
|
||||
from odoo import _, models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountMoveSend(models.TransientModel):
|
||||
_inherit = 'account.move.send'
|
||||
|
||||
l10n_ke_edi_warning_message = fields.Text(compute='_compute_l10n_ke_edi_warning_message')
|
||||
|
||||
@api.depends('move_ids')
|
||||
def _compute_l10n_ke_edi_warning_message(self):
|
||||
for wizard in self:
|
||||
warning_moves = wizard.move_ids.filtered(lambda m: m.country_code == 'KE' and not m._l10n_ke_fiscal_device_details_filled())
|
||||
if warning_moves:
|
||||
wizard.l10n_ke_edi_warning_message = '\n'.join([
|
||||
_("The following documents have no details related to the fiscal device."),
|
||||
*(warning_moves.mapped('name'))
|
||||
])
|
||||
else:
|
||||
wizard.l10n_ke_edi_warning_message = False
|
||||
|
||||
def _hook_invoice_document_before_pdf_report_render(self, invoice, invoice_data):
|
||||
# EXTENDS account
|
||||
super()._hook_invoice_document_before_pdf_report_render(invoice, invoice_data)
|
||||
if invoice.country_code == 'KE' and not invoice._l10n_ke_fiscal_device_details_filled():
|
||||
invoice_data['error'] = _(
|
||||
"This document does not have details related to the fiscal device, a proforma invoice will be used."
|
||||
)
|
||||
|
||||
def action_send_and_print(self, force_synchronous=False, allow_fallback_pdf=False, **kwargs):
|
||||
# EXTENDS account - prevent Send & Print if KE invoices aren't validated and no fallback is allowed.
|
||||
self.ensure_one()
|
||||
if not allow_fallback_pdf \
|
||||
and any(move.country_code == 'KE' and not move._l10n_ke_fiscal_device_details_filled() for move in self.move_ids):
|
||||
raise UserError(self.l10n_ke_edi_warning_message)
|
||||
return super().action_send_and_print(force_synchronous=force_synchronous, allow_fallback_pdf=allow_fallback_pdf, **kwargs)
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="account_move_send_form_inherit_l10n_ke_edi_tremol" model="ir.ui.view">
|
||||
<field name="name">account.move.send.form.inherit.l10n_ke_edi_tremol</field>
|
||||
<field name="model">account.move.send</field>
|
||||
<field name="inherit_id" ref="account.account_move_send_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='warnings']" position="inside">
|
||||
<div class="alert alert-warning"
|
||||
role="alert"
|
||||
invisible="not l10n_ke_edi_warning_message">
|
||||
<field name="l10n_ke_edi_warning_message"/>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user