[FIX] account_edi_facturx: fix upload with inactive currency

Retroactive fix for an issue in 15.0+
In 15.0+, importing an invoice with an inactive currency will raise
a traceback. Before this it was handled by not setting the correct
currency on the invoice if not active.

With this change, we'll raise an error instead of creating an invoice
with the wrong currency.

closes odoo/odoo#85678

X-original-commit: 14c61c2563efeed1ca14294da32e2eb6d1855c5b
Signed-off-by: Quentin De Paoli <qdp@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
Nicolas (vin)
2022-03-03 16:17:46 +00:00
parent cf03174af6
commit 0e601b8b0a
2 changed files with 33 additions and 2 deletions
+14
View File
@@ -112,6 +112,12 @@ msgstr ""
msgid "Display Name"
msgstr ""
#. module: account_edi
#: code:addons/account_edi/models/account_edi_format.py:0
#, python-format
msgid "Display the currency"
msgstr ""
#. module: account_edi
#: model_terms:ir.ui.view,arch_db:account_edi.view_move_form_inherit
#: model_terms:ir.ui.view,arch_db:account_edi.view_payment_form_inherit
@@ -377,6 +383,14 @@ msgstr ""
msgid "The aggregated state of all the EDIs with web-service of this move"
msgstr ""
#. module: account_edi
#: code:addons/account_edi/models/account_edi_format.py:0
#, python-format
msgid ""
"The currency (%s) of the document you are uploading is not active in this database.\n"
"Please activate it and update the currency rate if needed before trying again to import."
msgstr ""
#. module: account_edi
#: model:ir.model.fields,help:account_edi.field_account_edi_document__attachment_id
msgid ""
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.tools.pdf import OdooPdfFileReader
from odoo.osv import expression
from odoo.tools import html_escape
from odoo.exceptions import RedirectWarning
from lxml import etree
import base64
@@ -410,6 +411,8 @@ class AccountEdiFormat(models.Model):
file_data['pdf_reader'].stream.close()
else:
res = edi_format._create_invoice_from_binary(file_data['filename'], file_data['content'], file_data['extension'])
except RedirectWarning as rw:
raise rw
except Exception as e:
_logger.exception("Error importing attachment \"%s\" as invoice with format \"%s\"", file_data['filename'], edi_format.name, str(e))
if res:
@@ -584,7 +587,21 @@ class AccountEdiFormat(models.Model):
:param code: The code of the currency.
:returns: A currency or an empty recordset if not found.
'''
return self.env['res.currency'].search([('name', '=', code.upper())], limit=1)
currency = self.env['res.currency'].with_context(active_test=False).search([('name', '=', code.upper())], limit=1)
if currency and not currency.active:
error_msg = _('The currency (%s) of the document you are uploading is not active in this database.\n'
'Please activate it and update the currency rate if needed before trying again to import.',
currency.name)
error_action = {
'view_mode': 'form',
'res_model': 'res.currency',
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': currency.id,
'views': [[False, 'form']]
}
raise RedirectWarning(error_msg, error_action, _('Display the currency'))
return currency
####################################################
# Other helpers