se adicionan pruebas para CUFE y otros
FossilOrigin-Name: bac70bcbd3ad003d2df2d06b477914343f370982133f272dce05b75cc6f1da44
This commit is contained in:
parent
197f73491a
commit
48db52f7c2
@ -74,15 +74,16 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
|
|||||||
fachoxml.set_element('/fe:Invoice/cbc:ProfileExecutionID', self._tipo_ambiente())
|
fachoxml.set_element('/fe:Invoice/cbc:ProfileExecutionID', self._tipo_ambiente())
|
||||||
|
|
||||||
def issue_time(self, datetime_):
|
def issue_time(self, datetime_):
|
||||||
return datetime_.strftime('%H:%M:%S%z')
|
return datetime_.strftime('%H:%M:%S-05:00')
|
||||||
|
|
||||||
def issue_date(self, datetime_):
|
def issue_date(self, datetime_):
|
||||||
return datetime_.strftime('%Y-%m-%d')
|
return datetime_.strftime('%Y-%m-%d')
|
||||||
|
|
||||||
def _generate_cufe(self, invoice, fachoxml):
|
def formatVars(self, invoice):
|
||||||
NumFac = invoice.invoice_ident
|
NumFac = invoice.invoice_ident
|
||||||
FecFac = self.issue_date(invoice.invoice_issue)
|
FecFac = self.issue_date(invoice.invoice_issue)
|
||||||
HoraFac = self.issue_time(invoice.invoice_issue)
|
HoraFac = self.issue_time(invoice.invoice_issue)
|
||||||
ValorBruto = invoice.invoice_legal_monetary_total.line_extension_amount
|
ValorBruto = invoice.invoice_legal_monetary_total.tax_exclusive_amount
|
||||||
ValorTotalPagar = invoice.invoice_legal_monetary_total.payable_amount
|
ValorTotalPagar = invoice.invoice_legal_monetary_total.payable_amount
|
||||||
ValorImpuestoPara = {}
|
ValorImpuestoPara = {}
|
||||||
ValorImpuesto1 = 0.0
|
ValorImpuesto1 = 0.0
|
||||||
@ -103,7 +104,7 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
|
|||||||
TipoAmb = self._tipo_ambiente()
|
TipoAmb = self._tipo_ambiente()
|
||||||
ClTec = str(self.clave_tecnica)
|
ClTec = str(self.clave_tecnica)
|
||||||
|
|
||||||
formatVars = [
|
return [
|
||||||
'%s' % NumFac,
|
'%s' % NumFac,
|
||||||
'%s' % FecFac,
|
'%s' % FecFac,
|
||||||
'%s' % HoraFac,
|
'%s' % HoraFac,
|
||||||
@ -120,6 +121,9 @@ class DianXMLExtensionCUFE(FachoXMLExtension):
|
|||||||
'%s' % ClTec,
|
'%s' % ClTec,
|
||||||
'%d' % TipoAmb,
|
'%d' % TipoAmb,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _generate_cufe(self, invoice, fachoxml):
|
||||||
|
formatVars = self.formatVars(invoice)
|
||||||
cufe = "".join(formatVars)
|
cufe = "".join(formatVars)
|
||||||
|
|
||||||
# crear hash...
|
# crear hash...
|
||||||
|
@ -232,7 +232,7 @@ class Invoice:
|
|||||||
self.invoice_legal_monetary_total.line_extension_amount += invline.total_amount
|
self.invoice_legal_monetary_total.line_extension_amount += invline.total_amount
|
||||||
self.invoice_legal_monetary_total.tax_exclusive_amount += invline.total_tax_exclusive_amount
|
self.invoice_legal_monetary_total.tax_exclusive_amount += invline.total_tax_exclusive_amount
|
||||||
self.invoice_legal_monetary_total.tax_inclusive_amount += invline.total_tax_inclusive_amount
|
self.invoice_legal_monetary_total.tax_inclusive_amount += invline.total_tax_inclusive_amount
|
||||||
self.invoice_legal_monetary_total.charge_total_amount += invline.total_amount
|
self.invoice_legal_monetary_total.charge_total_amount += invline.tax_amount
|
||||||
#self.invoice_legal_monetary_total.payable_amount = self.invoice_legal_monetary_total.tax_exclusive_amount \
|
#self.invoice_legal_monetary_total.payable_amount = self.invoice_legal_monetary_total.tax_exclusive_amount \
|
||||||
# + self.invoice_legal_monetary_total.line_extension_amount \
|
# + self.invoice_legal_monetary_total.line_extension_amount \
|
||||||
# + self.invoice_legal_monetary_total.tax_inclusive_amount
|
# + self.invoice_legal_monetary_total.tax_inclusive_amount
|
||||||
@ -269,6 +269,11 @@ class DianResolucion0001Validator:
|
|||||||
self.errors.append(('invoice', 'operation_type',
|
self.errors.append(('invoice', 'operation_type',
|
||||||
'not found %s' % (invoice.invoice_operation_type)))
|
'not found %s' % (invoice.invoice_operation_type)))
|
||||||
|
|
||||||
|
# MACHETE se espera en zona horario colombia
|
||||||
|
if invoice.invoice_issue.tzname() not in ['UTC-05:00', '-05', None]:
|
||||||
|
self.errors.append(('invoice', 'invoice_issue',
|
||||||
|
'expected timezone UTC-05:00 or -05 or empty got %s' % (invoice.invoice_issue.tzname())))
|
||||||
|
|
||||||
def validate(self, invoice):
|
def validate(self, invoice):
|
||||||
invoice.accept(self)
|
invoice.accept(self)
|
||||||
self._validate_invoice(invoice)
|
self._validate_invoice(invoice)
|
||||||
@ -437,7 +442,6 @@ class DIANInvoiceXML(fe.FeXML):
|
|||||||
"""adiciona etiquetas a FEXML y retorna FEXML
|
"""adiciona etiquetas a FEXML y retorna FEXML
|
||||||
en caso de fallar validacion retorna None"""
|
en caso de fallar validacion retorna None"""
|
||||||
|
|
||||||
invoice.calculate()
|
|
||||||
fexml.placeholder_for('/fe:Invoice/ext:UBLExtensions')
|
fexml.placeholder_for('/fe:Invoice/ext:UBLExtensions')
|
||||||
fexml.set_element('/fe:Invoice/cbc:UBLVersionID', 'UBL 2.1')
|
fexml.set_element('/fe:Invoice/cbc:UBLVersionID', 'UBL 2.1')
|
||||||
fexml.set_element('/fe:Invoice/cbc:CustomizationID', invoice.invoice_operation_type)
|
fexml.set_element('/fe:Invoice/cbc:CustomizationID', invoice.invoice_operation_type)
|
||||||
|
@ -20,10 +20,11 @@ def simple_invoice_without_lines():
|
|||||||
inv.set_period(datetime.now(), datetime.now())
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
inv.set_issue(datetime.now())
|
inv.set_issue(datetime.now())
|
||||||
inv.set_ident('ABC123')
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('10')
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
||||||
inv.set_supplier(form.Party(
|
inv.set_supplier(form.Party(
|
||||||
name = 'facho-supplier',
|
name = 'facho-supplier',
|
||||||
ident = form.PartyIdentification('123',''),
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
responsability_code = form.Responsability(['ZZ']),
|
responsability_code = form.Responsability(['ZZ']),
|
||||||
responsability_regime_code = '48',
|
responsability_regime_code = '48',
|
||||||
organization_code = '1',
|
organization_code = '1',
|
||||||
@ -31,7 +32,7 @@ def simple_invoice_without_lines():
|
|||||||
))
|
))
|
||||||
inv.set_customer(form.Party(
|
inv.set_customer(form.Party(
|
||||||
name = 'facho-customer',
|
name = 'facho-customer',
|
||||||
ident = form.PartyIdentification('321', ''),
|
ident = form.PartyIdentification('321', '', '31'),
|
||||||
responsability_code = form.Responsability(['ZZ']),
|
responsability_code = form.Responsability(['ZZ']),
|
||||||
responsability_regime_code = '48',
|
responsability_regime_code = '48',
|
||||||
organization_code = '1',
|
organization_code = '1',
|
||||||
@ -45,17 +46,18 @@ def simple_invoice():
|
|||||||
inv.set_period(datetime.now(), datetime.now())
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
inv.set_issue(datetime.now())
|
inv.set_issue(datetime.now())
|
||||||
inv.set_ident('ABC123')
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('10')
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), ' 1234'))
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), ' 1234'))
|
||||||
inv.set_supplier(form.Party(
|
inv.set_supplier(form.Party(
|
||||||
name = 'facho-supplier',
|
name = 'facho-supplier',
|
||||||
ident = form.PartyIdentification('123',''),
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
responsability_code = form.Responsability(['ZZ']),
|
responsability_code = form.Responsability(['ZZ']),
|
||||||
responsability_regime_code = '48',
|
responsability_regime_code = '48',
|
||||||
organization_code = '1'
|
organization_code = '1'
|
||||||
))
|
))
|
||||||
inv.set_customer(form.Party(
|
inv.set_customer(form.Party(
|
||||||
name = 'facho-customer',
|
name = 'facho-customer',
|
||||||
ident = form.PartyIdentification('321',''),
|
ident = form.PartyIdentification('321','', '31'),
|
||||||
responsability_code = form.Responsability(['ZZ']),
|
responsability_code = form.Responsability(['ZZ']),
|
||||||
responsability_regime_code = '48',
|
responsability_regime_code = '48',
|
||||||
organization_code = '1'
|
organization_code = '1'
|
||||||
@ -80,7 +82,9 @@ def simple_invoice():
|
|||||||
|
|
||||||
def test_invoicesimple_build(simple_invoice):
|
def test_invoicesimple_build(simple_invoice):
|
||||||
invoice_validator = form.DianResolucion0001Validator()
|
invoice_validator = form.DianResolucion0001Validator()
|
||||||
assert invoice_validator.validate(simple_invoice) == True
|
|
||||||
|
invoice_validator.validate(simple_invoice)
|
||||||
|
assert invoice_validator.errors == []
|
||||||
xml = form.DIANInvoiceXML(simple_invoice)
|
xml = form.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')
|
||||||
@ -177,8 +181,8 @@ def test_invoice_cufe(simple_invoice_without_lines):
|
|||||||
simple_invoice = simple_invoice_without_lines
|
simple_invoice = simple_invoice_without_lines
|
||||||
simple_invoice.invoice_ident = '323200000129'
|
simple_invoice.invoice_ident = '323200000129'
|
||||||
simple_invoice.invoice_issue = datetime.strptime('2019-01-16 10:53:10-05:00', '%Y-%m-%d %H:%M:%S%z')
|
simple_invoice.invoice_issue = datetime.strptime('2019-01-16 10:53:10-05:00', '%Y-%m-%d %H:%M:%S%z')
|
||||||
simple_invoice.invoice_supplier.ident = form.PartyIdentification('700085371', '')
|
simple_invoice.invoice_supplier.ident = form.PartyIdentification('700085371', '', '31')
|
||||||
simple_invoice.invoice_customer.ident = form.PartyIdentification('800199436', '')
|
simple_invoice.invoice_customer.ident = form.PartyIdentification('800199436', '', '31')
|
||||||
simple_invoice.add_invoice_line(form.InvoiceLine(
|
simple_invoice.add_invoice_line(form.InvoiceLine(
|
||||||
quantity = 1,
|
quantity = 1,
|
||||||
description = 'producto',
|
description = 'producto',
|
||||||
@ -192,26 +196,52 @@ def test_invoice_cufe(simple_invoice_without_lines):
|
|||||||
)])
|
)])
|
||||||
))
|
))
|
||||||
|
|
||||||
class FakeDianXMLExtensionCUFE(fe.DianXMLExtensionCUFE):
|
simple_invoice.calculate()
|
||||||
def issue_time(self, datetime_):
|
|
||||||
return '10:53:10-05:00'
|
|
||||||
def issue_date(self, datetime_):
|
|
||||||
return '2019-01-16'
|
|
||||||
|
|
||||||
xml_invoice = form.DIANInvoiceXML(simple_invoice)
|
xml_invoice = form.DIANInvoiceXML(simple_invoice)
|
||||||
|
|
||||||
cufe_extension = FakeDianXMLExtensionCUFE(
|
cufe_extension = fe.DianXMLExtensionCUFE(
|
||||||
simple_invoice,
|
simple_invoice,
|
||||||
tipo_ambiente = fe.DianXMLExtensionCUFE.AMBIENTE_PRODUCCION,
|
tipo_ambiente = fe.DianXMLExtensionCUFE.AMBIENTE_PRODUCCION,
|
||||||
clave_tecnica = '693ff6f2a553c3646a063436fd4dd9ded0311471'
|
clave_tecnica = '693ff6f2a553c3646a063436fd4dd9ded0311471'
|
||||||
)
|
)
|
||||||
|
formatVars = cufe_extension.formatVars(simple_invoice)
|
||||||
|
#NumFac
|
||||||
|
assert formatVars[0] == '323200000129', "NumFac"
|
||||||
|
#FecFac
|
||||||
|
assert formatVars[1] == '2019-01-16', "FecFac"
|
||||||
|
#HoraFac
|
||||||
|
assert formatVars[2] == '10:53:10-05:00', "HoraFac"
|
||||||
|
#ValorBruto
|
||||||
|
assert formatVars[3] == '1500000.00', "ValorBruto"
|
||||||
|
#CodImpuesto1
|
||||||
|
assert formatVars[4] == '01', "CodImpuesto1"
|
||||||
|
#ValorImpuesto1
|
||||||
|
assert formatVars[5] == '285000.00', "ValorImpuesto1"
|
||||||
|
#CodImpuesto2
|
||||||
|
assert formatVars[6] == '04', "CodImpuesto2"
|
||||||
|
#ValorImpuesto2
|
||||||
|
assert formatVars[7] == '0.00', "ValorImpuesto2"
|
||||||
|
#CodImpuesto3
|
||||||
|
assert formatVars[8] == '03', "CodImpuesto3"
|
||||||
|
#ValorImpuesto3
|
||||||
|
assert formatVars[9] == '0.00', "ValorImpuesto3"
|
||||||
|
#ValTotFac
|
||||||
|
assert formatVars[10] == '1785000.00', "ValTotFac"
|
||||||
|
#NitOFE
|
||||||
|
assert formatVars[11] == '700085371', "NitOFE"
|
||||||
|
#NumAdq
|
||||||
|
assert formatVars[12] == '800199436', "NumAdq"
|
||||||
|
#ClTec
|
||||||
|
assert formatVars[13] == '693ff6f2a553c3646a063436fd4dd9ded0311471', "ClTec"
|
||||||
|
#TipoAmbiente
|
||||||
|
assert formatVars[14] == '1', "TipoAmbiente"
|
||||||
|
|
||||||
xml_invoice.add_extension(cufe_extension)
|
xml_invoice.add_extension(cufe_extension)
|
||||||
cufe = xml_invoice.get_element_text('/fe:Invoice/cbc:UUID')
|
cufe = xml_invoice.get_element_text('/fe:Invoice/cbc:UUID')
|
||||||
# RESOLUCION 004: pagina 689
|
# RESOLUCION 004: pagina 689
|
||||||
assert cufe == '8bb918b19ba22a694f1da11c643b5e9de39adf60311cf179179e9b33381030bcd4c3c3f156c506ed5908f9276f5bd9b4'
|
assert cufe == '8bb918b19ba22a694f1da11c643b5e9de39adf60311cf179179e9b33381030bcd4c3c3f156c506ed5908f9276f5bd9b4'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_invoice_payment_mean(monkeypatch, simple_invoice):
|
def test_invoice_payment_mean(monkeypatch, simple_invoice):
|
||||||
invoice_validator = form.DianResolucion0001Validator()
|
invoice_validator = form.DianResolucion0001Validator()
|
||||||
assert invoice_validator.validate(simple_invoice) == True
|
assert invoice_validator.validate(simple_invoice) == True
|
||||||
|
39
tests/test_form.py
Normal file
39
tests/test_form.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# This file is part of facho. The COPYRIGHT file at the top level of
|
||||||
|
# this repository contains the full copyright notices and license terms.
|
||||||
|
|
||||||
|
"""Tests for `facho` package."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from datetime import datetime
|
||||||
|
import io
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
import facho.fe.form as form
|
||||||
|
from facho import fe
|
||||||
|
|
||||||
|
def test_invoice_legalmonetary():
|
||||||
|
inv = form.Invoice()
|
||||||
|
inv.add_invoice_line(form.InvoiceLine(
|
||||||
|
quantity = 1,
|
||||||
|
description = 'producto facho',
|
||||||
|
item = form.StandardItem('test', 9999),
|
||||||
|
price = form.Price(
|
||||||
|
amount = 100.0,
|
||||||
|
type_code = '01',
|
||||||
|
type = 'x'
|
||||||
|
),
|
||||||
|
tax = form.TaxTotal(
|
||||||
|
subtotals = [
|
||||||
|
form.TaxSubTotal(
|
||||||
|
percent = 19.0,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
))
|
||||||
|
inv.calculate()
|
||||||
|
assert inv.invoice_legal_monetary_total.line_extension_amount == 100.0
|
||||||
|
assert inv.invoice_legal_monetary_total.tax_exclusive_amount == 100.0
|
||||||
|
assert inv.invoice_legal_monetary_total.tax_inclusive_amount == 119.0
|
||||||
|
assert inv.invoice_legal_monetary_total.charge_total_amount == 19.0
|
Loading…
Reference in New Issue
Block a user