Skip to content

Commit eabaa4b

Browse files
committed
[FIX] l10n_ro_eFactura: Invoice content error detection
--Before-- -When the eFactura status was fetched and there was an invoice content error it was not displayed. This issue was due to both the overlooking of: (1)the 'nok' status (sent back by the Romanian authorities regarding the presence of errors in the invoice content)  (2)the file provided in the zip that would contain the errors -The error message shown would also only contain the first error even if many were present. --Now-- -If the status fetched contains 'nok' and is therefore signaling the presence of invoice content errors, then the apposite error file is chosen instead of the file with the electronic signature. This allows for following logic to account for errors, to retrieve the error message and to provide the error file as the downloadable document.  -The pop up shows all the errors with an increased width to account for more content. task-4306506 closes odoo#190618 Signed-off-by: Quentin De Paoli (qdp) <[email protected]>
1 parent 41fdb02 commit eabaa4b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

addons/account/static/src/components/document_state/document_state_field.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.account_document_state_popover {
2-
width: 360px;
2+
width: 500px;
33
}
44

55
.account_document_state_popover_clone {

addons/l10n_ro_efactura/models/account_move.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,14 @@ def _l10n_ro_edi_fetch_invoice_sending_documents(self):
250250
company=invoice.company_id,
251251
key_download=result['key_download'],
252252
session=session,
253+
status=result['state_status'],
253254
)
254255
to_delete_documents |= invoice._l10n_ro_edi_get_sending_and_failed_documents()
255256
final_result['key_loading'] = active_sending_document.key_loading
256-
if 'error' in final_result:
257+
if final_result.get('error'):
257258
final_result['attachment_raw'] = previous_raw
258259
invoice._l10n_ro_edi_create_document_invoice_sending_failed(
259-
message=final_result['error'],
260+
message=final_result['error'].replace('\t', ''),
260261
attachment_raw=final_result['attachment_raw'],
261262
key_loading=final_result['key_loading'],
262263
)

addons/l10n_ro_efactura/models/ciusro_document.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ def _request_ciusro_fetch_status(self, company, key_loading, session):
134134

135135
state_status = root.get('stare')
136136
if state_status in ('nok', 'ok'):
137-
return {'key_download': root.get('id_descarcare')}
137+
return {'key_download': root.get('id_descarcare'), 'state_status': state_status}
138138
else:
139139
return {}
140140

141141
@api.model
142-
def _request_ciusro_download_answer(self, company, key_download, session):
142+
def _request_ciusro_download_answer(self, company, key_download, session, status=None):
143143
"""
144144
This method makes a "Download Answer" (GET/descarcare) request to the Romanian SPV. It then processes the
145145
response by opening the received zip file and returns either:
@@ -150,7 +150,7 @@ def _request_ciusro_download_answer(self, company, key_download, session):
150150
:param company: ``res.company`` object
151151
:param key_download: Content of `key_download` received from `_request_ciusro_send_invoice`
152152
:param session: ``requests.Session()`` object
153-
:return: {'error': <str>} | {'attachment_raw': <str>, 'key_signature': <str>, 'key_certificate': <str>}
153+
:return: {'attachment_raw': <str>, 'key_signature': <str>, 'key_certificate': <str>, 'error': <str>}
154154
"""
155155
result = make_efactura_request(
156156
session=session,
@@ -164,19 +164,26 @@ def _request_ciusro_download_answer(self, company, key_download, session):
164164

165165
# E-Factura gives download response in ZIP format
166166
zip_ref = zipfile.ZipFile(io.BytesIO(result['content']))
167-
signature_file = next(file for file in zip_ref.namelist() if 'semnatura' in file)
167+
# The ZIP will contain two files, one with the original invoice or with the identified errors (as the case may be)
168+
# and the other with the electronic signature (containing 'semnatura').
169+
# If there is an error (status == 'nok') we want to provide the file with the errors.
170+
if status == 'nok':
171+
signature_file = next(file for file in zip_ref.namelist() if 'semnatura' not in file)
172+
else:
173+
signature_file = next(file for file in zip_ref.namelist() if 'semnatura' in file)
168174
xml_bytes = zip_ref.open(signature_file)
169175
root = etree.parse(xml_bytes)
170-
error_element = root.find('.//ns:Error', namespaces=NS_HEADER)
171-
if error_element is not None:
172-
return {'error': error_element.get('errorMessage')}
176+
error_elements = root.findall('.//ns:Error', namespaces=NS_HEADER)
177+
if error_elements:
178+
error_message = ('\n\n').join(error.get('errorMessage') for error in error_elements)
173179

174180
# Pretty-print the XML content of the signature file to be saved as attachment
175181
attachment_raw = etree.tostring(root, pretty_print=True, xml_declaration=True, encoding='UTF-8')
176182
return {
177183
'attachment_raw': attachment_raw,
178184
'key_signature': root.findtext('.//ns:SignatureValue', namespaces=NS_SIGNATURE),
179185
'key_certificate': root.findtext('.//ns:X509Certificate', namespaces=NS_SIGNATURE),
186+
'error': error_message if error_elements else False,
180187
}
181188

182189
def action_l10n_ro_edi_fetch_status(self):

0 commit comments

Comments
 (0)