Feat: Attachment, ParentDocumentLine
This commit is contained in:
parent
9b33b4486c
commit
3a385c63e3
@ -5,11 +5,12 @@ __all__ = ['AttachedDocument']
|
||||
|
||||
class AttachedDocument():
|
||||
|
||||
def __init__(self, invoice, id):
|
||||
def __init__(self, invoice, DIANInvoiceXML, id):
|
||||
self.schema =\
|
||||
'urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2'
|
||||
self.id = id
|
||||
self.invoice = invoice
|
||||
self.DIANInvoiceXML = DIANInvoiceXML
|
||||
self.attached_document_invoice = self.attached_document_invoice()
|
||||
|
||||
# self.fexml.placeholder_for(
|
||||
@ -43,7 +44,8 @@ class AttachedDocument():
|
||||
|
||||
# DIAN 1.9.-2023: AE05
|
||||
self.fexml.set_element(
|
||||
'./cbc:IssueDate', self.invoice.invoice_issue.strftime('%Y-%m-%d'))
|
||||
'./cbc:IssueDate',
|
||||
self.invoice.invoice_issue.strftime('%Y-%m-%d'))
|
||||
|
||||
# DIAN 1.9.-2023: AE06
|
||||
self.fexml.set_element(
|
||||
@ -163,11 +165,63 @@ class AttachedDocument():
|
||||
# DIAN 1.9.-2023: AE37
|
||||
self.fexml.set_element(
|
||||
'./cac:Attachment/cac:ExternalReference/cbc:Description',
|
||||
' ')
|
||||
self._build_attachment(self.DIANInvoiceXML)
|
||||
)
|
||||
|
||||
def _build_attachment(self, DIANInvoiceXML):
|
||||
document = (
|
||||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
|
||||
) + DIANInvoiceXML.tostring()
|
||||
attachment = "<![CDATA[{}]]>".format(
|
||||
document)
|
||||
|
||||
return attachment
|
||||
|
||||
def set_parent_document_line_reference(self):
|
||||
self.fexml.placeholder_for(
|
||||
'./cac:ParentDocumentLineReference')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cbc:LineID', 1)
|
||||
self.fexml.placeholder_for(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cbc:ID',
|
||||
'1234')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cbc:UUID',
|
||||
'1234',
|
||||
schemeName="CUFE-SHA384")
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cbc:IssueDate',
|
||||
'2024-11-28')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cbc:DocumentType',
|
||||
'ApplicationResponse')
|
||||
self.fexml.placeholder_for(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:MimeCode',
|
||||
'text/xml')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:EncodingCode',
|
||||
'UTF-8')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:Description',
|
||||
' ')
|
||||
self.fexml.placeholder_for(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:ResultOfVerification')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:ResultOfVerification/cbc:ValidatorID',
|
||||
'Unidad Especial Dirección de Impuestos y Aduanas Nacionales')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:ResultOfVerification/cbc:ValidationResultCode',
|
||||
'02')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:ResultOfVerification/cbc:ValidationDate',
|
||||
'2024-11-28')
|
||||
self.fexml.set_element(
|
||||
'./cac:ParentDocumentLineReference/cac:DocumentReference/cac:ResultOfVerification/cbc:ValidationTime',
|
||||
'10:35:11-05:00')
|
||||
|
||||
def toFachoXML(self):
|
||||
return self.fexml
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,13 +8,29 @@ import pytest
|
||||
from facho.fe import form_xml
|
||||
from datetime import datetime
|
||||
import helpers
|
||||
|
||||
from fixtures import simple_invoice
|
||||
|
||||
simple_invoice = simple_invoice
|
||||
|
||||
def test_xml_with_required_elements(simple_invoice):
|
||||
|
||||
DIANInvoiceXML = form_xml.DIANInvoiceXML(
|
||||
simple_invoice)
|
||||
|
||||
doc = form_xml.AttachedDocument(
|
||||
simple_invoice,
|
||||
DIANInvoiceXML,
|
||||
id='123')
|
||||
|
||||
def test_xml_with_required_elements():
|
||||
doc = form_xml.AttachedDocument(simple_invoice, id='123')
|
||||
xml = doc.toFachoXML()
|
||||
|
||||
DIANInvoiceXML = form_xml.DIANInvoiceXML(
|
||||
simple_invoice, 'Invoice').attach_invoice
|
||||
|
||||
attached_document = (
|
||||
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
|
||||
) + DIANInvoiceXML.tostring()
|
||||
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cbc:UBLVersionID') == 'UBL 2.1'
|
||||
assert xml.get_element_text(
|
||||
@ -70,5 +86,41 @@ def test_xml_with_required_elements():
|
||||
'/atd:AttachedDocument/cac:ReceiverParty/cac:PartyTaxScheme/cac:TaxScheme/cbc:Name'
|
||||
) == 'IVA'
|
||||
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:MimeCode'
|
||||
) == "text/xml"
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:EncodingCode'
|
||||
) == "UTF-8"
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:Attachment/cac:ExternalReference/cbc:Description'
|
||||
) == "<![CDATA[{}]]>".format(attached_document)
|
||||
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cbc:LineID'
|
||||
) == '1'
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:ID'
|
||||
) == '1234'
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:UUID'
|
||||
) == '1234'
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:IssueDate'
|
||||
) == '2024-11-28'
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cbc:DocumentType'
|
||||
) == 'ApplicationResponse'
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:MimeCode'
|
||||
) == 'text/xml'
|
||||
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:EncodingCode'
|
||||
) == "UTF-8"
|
||||
assert xml.get_element_text(
|
||||
'/atd:AttachedDocument/cac:ParentDocumentLineReference/cac:DocumentReference/cac:Attachment/cac:ExternalReference/cbc:Description'
|
||||
) == " "
|
||||
|
||||
with open("output.xml", "w") as fh:
|
||||
fh.write(xml.tostring())
|
||||
|
Loading…
Reference in New Issue
Block a user