|
|
|
|
@@ -5,24 +5,49 @@
|
|
|
|
|
|
|
|
|
|
"""Tests for `facho` package."""
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
import io
|
|
|
|
|
import zipfile
|
|
|
|
|
|
|
|
|
|
import facho.fe.form as form
|
|
|
|
|
from facho import fe
|
|
|
|
|
from facho.fe.form_xml import DIANInvoiceXML, DIANCreditNoteXML, DIANDebitNoteXML
|
|
|
|
|
from facho.fe.form_xml import (
|
|
|
|
|
DIANInvoiceXML, DIANCreditNoteXML, DIANDebitNoteXML)
|
|
|
|
|
|
|
|
|
|
from fixtures import (
|
|
|
|
|
simple_invoice,
|
|
|
|
|
simple_invoice_without_lines,
|
|
|
|
|
simple_credit_note_without_lines,
|
|
|
|
|
simple_debit_note_without_lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CUDE_ = ('907e4444decc9e59'
|
|
|
|
|
'160a2fb3b6659b33d'
|
|
|
|
|
'c5b632a5008922b9a'
|
|
|
|
|
'62f83f757b1c448e4'
|
|
|
|
|
'7f5867f2b50dbdb96f48c7681168')
|
|
|
|
|
|
|
|
|
|
CUFE_ = (
|
|
|
|
|
'8bb918b19ba22a694f1da'
|
|
|
|
|
'11c643b5e9de39adf60311c'
|
|
|
|
|
'f179179e9b33381030bcd4c3c'
|
|
|
|
|
'3f156c506ed5908f9276f5bd9b4')
|
|
|
|
|
|
|
|
|
|
simple_invoice = simple_invoice
|
|
|
|
|
simple_invoice_without_lines = simple_invoice_without_lines
|
|
|
|
|
simple_credit_note_without_lines = simple_credit_note_without_lines
|
|
|
|
|
simple_debit_note_without_lines = simple_debit_note_without_lines
|
|
|
|
|
|
|
|
|
|
from fixtures import *
|
|
|
|
|
|
|
|
|
|
def test_invoicesimple_build(simple_invoice):
|
|
|
|
|
xml = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
|
|
|
|
|
supplier_name = xml.get_element_text('/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name')
|
|
|
|
|
supplier_name = xml.get_element_text(
|
|
|
|
|
'/fe:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name')
|
|
|
|
|
assert supplier_name == simple_invoice.invoice_supplier.name
|
|
|
|
|
|
|
|
|
|
customer_name = xml.get_element_text('/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyName/cbc:Name')
|
|
|
|
|
customer_name = xml.get_element_text(
|
|
|
|
|
'/fe:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyName/cbc:Name')
|
|
|
|
|
assert customer_name == simple_invoice.invoice_customer.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -42,9 +67,11 @@ def test_invoicesimple_xml_signed(monkeypatch, simple_invoice):
|
|
|
|
|
print(xml.tostring())
|
|
|
|
|
xml.add_extension(signer)
|
|
|
|
|
|
|
|
|
|
elem = xml.get_element('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent/ds:Signature')
|
|
|
|
|
elem = xml.get_element(
|
|
|
|
|
'/fe:Invoice/ext:UBLExtensions/ext:UBLExtension[2]/ext:ExtensionContent/ds:Signature')
|
|
|
|
|
assert elem.text is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invoicesimple_zip(simple_invoice):
|
|
|
|
|
xml_invoice = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
|
|
|
|
|
@@ -66,26 +93,33 @@ def test_invoicesimple_zip(simple_invoice):
|
|
|
|
|
|
|
|
|
|
def test_bug_cbcid_empty_on_invoice_line(simple_invoice):
|
|
|
|
|
xml_invoice = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
cbc_id = xml_invoice.get_element_text('/fe:Invoice/cac:InvoiceLine[1]/cbc:ID', format_=int)
|
|
|
|
|
cbc_id = xml_invoice.get_element_text(
|
|
|
|
|
'/fe:Invoice/cac:InvoiceLine[1]/cbc:ID', format_=int)
|
|
|
|
|
assert cbc_id == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invoice_line_count_numeric(simple_invoice):
|
|
|
|
|
xml_invoice = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
count = xml_invoice.get_element_text('/fe:Invoice/cbc:LineCountNumeric', format_=int)
|
|
|
|
|
count = xml_invoice.get_element_text(
|
|
|
|
|
'/fe:Invoice/cbc:LineCountNumeric', format_=int)
|
|
|
|
|
assert count == len(simple_invoice.invoice_lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invoice_profileexecutionid(simple_invoice):
|
|
|
|
|
xml_invoice = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
|
|
|
|
|
xml_invoice.add_extension(cufe_extension)
|
|
|
|
|
id_ = xml_invoice.get_element_text('/fe:Invoice/cbc:ProfileExecutionID', format_=int)
|
|
|
|
|
id_ = xml_invoice.get_element_text(
|
|
|
|
|
'/fe:Invoice/cbc:ProfileExecutionID', format_=int)
|
|
|
|
|
assert id_ == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invoice_invoice_type_code(simple_invoice):
|
|
|
|
|
xml_invoice = DIANInvoiceXML(simple_invoice)
|
|
|
|
|
id_ = xml_invoice.get_element_text('/fe:Invoice/cbc:InvoiceTypeCode', format_=int)
|
|
|
|
|
assert id_ == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invoice_totals(simple_invoice_without_lines):
|
|
|
|
|
simple_invoice = simple_invoice_without_lines
|
|
|
|
|
simple_invoice.invoice_ident = '323200000129'
|
|
|
|
|
@@ -171,21 +205,25 @@ def test_invoice_cufe(simple_invoice_without_lines):
|
|
|
|
|
xml_invoice.add_extension(cufe_extension)
|
|
|
|
|
cufe = xml_invoice.get_element_text('/fe:Invoice/cbc:UUID')
|
|
|
|
|
# RESOLUCION 004: pagina 689
|
|
|
|
|
assert cufe == '8bb918b19ba22a694f1da11c643b5e9de39adf60311cf179179e9b33381030bcd4c3c3f156c506ed5908f9276f5bd9b4'
|
|
|
|
|
|
|
|
|
|
assert cufe == CUFE_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_credit_note_cude(simple_credit_note_without_lines):
|
|
|
|
|
simple_invoice = simple_credit_note_without_lines
|
|
|
|
|
simple_invoice.invoice_ident = '8110007871'
|
|
|
|
|
simple_invoice.invoice_issue = datetime.strptime('2019-01-12 07:00:00-05:00', '%Y-%m-%d %H:%M:%S%z')
|
|
|
|
|
simple_invoice.invoice_supplier.ident = form.PartyIdentification('900373076', '5', '31')
|
|
|
|
|
simple_invoice.invoice_customer.ident = form.PartyIdentification('8355990', '5', '31')
|
|
|
|
|
simple_invoice.invoice_issue = datetime.strptime(
|
|
|
|
|
'2019-01-12 07:00:00-05:00', '%Y-%m-%d %H:%M:%S%z')
|
|
|
|
|
simple_invoice.invoice_supplier.ident = form.PartyIdentification(
|
|
|
|
|
'900373076', '5', '31')
|
|
|
|
|
simple_invoice.invoice_customer.ident = form.PartyIdentification(
|
|
|
|
|
'8355990', '5', '31')
|
|
|
|
|
simple_invoice.add_invoice_line(form.InvoiceLine(
|
|
|
|
|
quantity = form.Quantity(1, '94'),
|
|
|
|
|
quantity=form.Quantity(
|
|
|
|
|
1, '94'),
|
|
|
|
|
description='producto',
|
|
|
|
|
item=form.StandardItem(111),
|
|
|
|
|
price = form.Price(form.Amount(5_000), '01', ''),
|
|
|
|
|
price=form.Price(
|
|
|
|
|
form.Amount(5_000), '01', ''),
|
|
|
|
|
tax=form.TaxTotal(
|
|
|
|
|
subtotals=[
|
|
|
|
|
form.TaxSubTotal(
|
|
|
|
|
@@ -206,16 +244,19 @@ def test_credit_note_cude(simple_credit_note_without_lines):
|
|
|
|
|
xml_invoice.add_extension(cude_extension)
|
|
|
|
|
cude = xml_invoice.get_element_text('/fe:CreditNote/cbc:UUID')
|
|
|
|
|
# pag 612
|
|
|
|
|
assert cude == '907e4444decc9e59c160a2fb3b6659b33dc5b632a5008922b9a62f83f757b1c448e47f5867f2b50dbdb96f48c7681168'
|
|
|
|
|
assert cude == CUDE_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pag 614
|
|
|
|
|
def test_debit_note_cude(simple_debit_note_without_lines):
|
|
|
|
|
simple_invoice = simple_debit_note_without_lines
|
|
|
|
|
simple_invoice.invoice_ident = 'ND1001'
|
|
|
|
|
simple_invoice.invoice_issue = datetime.strptime('2019-01-18 10:58:00-05:00', '%Y-%m-%d %H:%M:%S%z')
|
|
|
|
|
simple_invoice.invoice_supplier.ident = form.PartyIdentification('900197264', '5', '31')
|
|
|
|
|
simple_invoice.invoice_customer.ident = form.PartyIdentification('10254102', '5', '31')
|
|
|
|
|
simple_invoice.invoice_issue = datetime.strptime(
|
|
|
|
|
'2019-01-18 10:58:00-05:00', '%Y-%m-%d %H:%M:%S%z')
|
|
|
|
|
simple_invoice.invoice_supplier.ident = form.PartyIdentification(
|
|
|
|
|
'900197264', '5', '31')
|
|
|
|
|
simple_invoice.invoice_customer.ident = form.PartyIdentification(
|
|
|
|
|
'10254102', '5', '31')
|
|
|
|
|
simple_invoice.add_invoice_line(form.InvoiceLine(
|
|
|
|
|
quantity=form.Quantity(1, '94'),
|
|
|
|
|
description='producto',
|
|
|
|
|
@@ -226,7 +267,9 @@ def test_debit_note_cude(simple_debit_note_without_lines):
|
|
|
|
|
form.TaxSubTotal(
|
|
|
|
|
scheme=form.TaxScheme('04'),
|
|
|
|
|
percent=8.0
|
|
|
|
|
)])
|
|
|
|
|
)]),
|
|
|
|
|
withholding=form.WithholdingTaxTotal(
|
|
|
|
|
subtotals=[])
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
simple_invoice.calculate()
|
|
|
|
|
@@ -251,7 +294,6 @@ def test_debit_note_cude(simple_debit_note_without_lines):
|
|
|
|
|
assert build_vars['Software-PIN'] == '10201'
|
|
|
|
|
assert build_vars['TipoAmb'] == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cude_composicion = "".join(cude_extension.formatVars())
|
|
|
|
|
assert cude_composicion == 'ND10012019-01-1810:58:00-05:0030000.00010.00042400.00030.0032400.0090019726410254102102012'
|
|
|
|
|
|
|
|
|
|
|