[FIX] {l10n_}account_edi_ubl_cii/dk_oioubl/ro_edi{_tests}: remove DocumentTypeCode from standard

The aim of this commit to fix our bis3 e-invoice by setting the
DocumentTypeCode node only for the EDIs that fills its values otherwise
not setting that nodes.

Currently, we only set it for Denmark as it is mandatory, for Romania
because it was developped with it on the standard and we don't
set it for the others to be defensive. (Because it's not mandatory)

Before this commit:
All e-invoice based on BIS3 gets rejected.

After this commit:
BIS3 e-invoice pass the validation again.

Additional information:
Bis3 DocumentTypeCode node: https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-invoice/cac-AdditionalDocumentReference/cbc-DocumentTypeCode/
UBL 2.0 DocumentTypeCode node: http://www.datypic.com/sc/ubl20/e-cbc_DocumentTypeCode.html
UBL 2.2 DocumentTypeCode node: http://www.datypic.com/sc/ubl22/e-cbc_DocumentTypeCode.html

closes odoo/odoo#139468

Task-id: 3563754
X-original-commit: 1da22571c43fceedb4ab8c13aa9d0d6a78372595
Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
Brice bib Bartoletti
2023-10-24 13:55:23 +00:00
parent 54ae8f96cc
commit d97a52cd1b
20 changed files with 14 additions and 23 deletions
@@ -595,9 +595,7 @@ class AccountEdiXmlUBL20(models.AbstractModel):
def _get_document_type_code_vals(self, invoice, invoice_data):
"""Returns the values used for the `DocumentTypeCode` node"""
# To be overriden by custom format if required
# http://www.datypic.com/sc/ubl20/e-cbc_DocumentTypeCode.html
document_type_code = 380 if invoice.move_type == 'out_invoice' else 381
return {'attrs': {}, 'value': document_type_code}
return {'attrs': {}, 'value': None}
# -------------------------------------------------------------------------
# IMPORT
@@ -191,18 +191,19 @@ class AccountMoveSend(models.TransientModel):
filename = pdf_values['name']
content = pdf_values['raw']
doc_type_node = ""
edi_model = invoice_data["ubl_cii_xml_options"]["builder"]
doc_type_code_vals = edi_model._get_document_type_code_vals(invoice, invoice_data)
document_type_code_attributes = " ".join(f'{name}="{value}"' for name, value in doc_type_code_vals['attrs'].items())
document_type_code_value = doc_type_code_vals.get('value', '')
if doc_type_code_vals['value']:
doc_type_code_attrs = " ".join(f'{name}="{value}"' for name, value in doc_type_code_vals['attrs'].items())
doc_type_node = f"<cbc:DocumentTypeCode {doc_type_code_attrs}>{doc_type_code_vals['value']}</cbc:DocumentTypeCode>"
to_inject = f'''
<cac:AdditionalDocumentReference
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2">
<cbc:ID>{escape(filename)}</cbc:ID>
<cbc:DocumentTypeCode {document_type_code_attributes}>{document_type_code_value}</cbc:DocumentTypeCode>
{doc_type_node}
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject
mimeCode="application/pdf"
@@ -14,7 +14,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -13,7 +13,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>381</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -14,7 +14,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -14,7 +14,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">
___ignore___
@@ -13,7 +13,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>381</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">
___ignore___
@@ -17,7 +17,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="___ignore___" filename="___ignore___">
___ignore___
@@ -14,7 +14,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -18,7 +18,6 @@
</cac:BillingReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>381</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -14,7 +14,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>380</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -13,7 +13,6 @@
</cac:OrderReference>
<cac:AdditionalDocumentReference>
<cbc:ID>___ignore___</cbc:ID>
<cbc:DocumentTypeCode>381</cbc:DocumentTypeCode>
<cbc:Attachment>
<cbc:EmbeddedDocumentBinaryObject>___ignore___</cbc:EmbeddedDocumentBinaryObject>
</cbc:Attachment>
@@ -23,7 +23,6 @@
</cac:ContractDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID schemeID="ABT">DR35141</cbc:ID>
<cbc:DocumentTypeCode>130</cbc:DocumentTypeCode>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>ts12345</cbc:ID>
@@ -240,6 +240,7 @@ class AccountEdiXmlOIOUBL201(models.AbstractModel):
# EXTENDS 'account_edi_ubl_cii
# http://www.datypic.com/sc/ubl20/e-cbc_DocumentTypeCode.html
vals = super()._get_document_type_code_vals(invoice, invoice_data)
vals['value'] = "380" if invoice.move_type == 'out_invoice' else "381"
vals['attrs']['listAgencyID'] = "6"
vals['attrs']['listID'] = "UN/ECE 1001"
return vals
@@ -72,6 +72,13 @@ class AccountEdiXmlUBLRO(models.AbstractModel):
return vals
def _get_document_type_code_vals(self, invoice, invoice_data):
# EXTENDS 'account_edi_ubl_cii
# http://www.datypic.com/sc/ubl20/e-cbc_DocumentTypeCode.html
vals = super()._get_document_type_code_vals(invoice, invoice_data)
vals['value'] = "380" if invoice.move_type == 'out_invoice' else "381"
return vals
def _export_invoice_constraints(self, invoice, vals):
# EXTENDS 'account_edi_ubl_cii'
constraints = super()._export_invoice_constraints(invoice, vals)