facho/fe/form.py a modulo.
* facho/fe/form/query.py: utilidades. FossilOrigin-Name: a1486421fcfcf6bda1e3b4901f3fc3fe86b7156852571aad74274d5b7ce3778a
This commit is contained in:
parent
c394663cc8
commit
f4c2282e3d
@ -1,4 +1,5 @@
|
|||||||
from .fe import FeXML
|
from .fe import FeXML
|
||||||
|
from .fe import fe_from_string
|
||||||
from .fe import NAMESPACES
|
from .fe import NAMESPACES
|
||||||
from .fe import DianXMLExtensionSigner
|
from .fe import DianXMLExtensionSigner
|
||||||
from .fe import DianXMLExtensionSoftwareSecurityCode
|
from .fe import DianXMLExtensionSoftwareSecurityCode
|
||||||
|
@ -48,6 +48,10 @@ NAMESPACES = {
|
|||||||
'sig': 'http://www.w3.org/2000/09/xmldsig#',
|
'sig': 'http://www.w3.org/2000/09/xmldsig#',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def fe_from_string(document: str) -> FachoXML:
|
||||||
|
xml = LXMLBuilder.from_string(document)
|
||||||
|
return FachoXML(xml, nsmap=NAMESPACES)
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def mock_xades_policy():
|
def mock_xades_policy():
|
||||||
|
@ -11,7 +11,7 @@ import decimal
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from .data.dian import codelist
|
from ..data.dian import codelist
|
||||||
|
|
||||||
DECIMAL_PRECISION = 6
|
DECIMAL_PRECISION = 6
|
||||||
|
|
23
facho/fe/form/query.py
Normal file
23
facho/fe/form/query.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"""
|
||||||
|
utilidades
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .. import form
|
||||||
|
from ..fe import fe_from_string
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def billing_reference(xmldocument: str, klass: form.BillingReference) -> form.BillingReference:
|
||||||
|
"""
|
||||||
|
construye BillingReference desde XMLDOCUMENT
|
||||||
|
usando KLASS como clase.
|
||||||
|
"""
|
||||||
|
if not issubclass(klass, form.BillingReference):
|
||||||
|
raise TypeError('klass expected subclass of BillingReference')
|
||||||
|
|
||||||
|
fachoxml = fe_from_string(xmldocument)
|
||||||
|
|
||||||
|
uid = fachoxml.get_element_text('./cbc:ID')
|
||||||
|
uuid = fachoxml.get_element_text('./cbc:UUID')
|
||||||
|
issue_date = fachoxml.get_element_text('./cbc:IssueDate')
|
||||||
|
date = datetime.strptime(issue_date, '%Y-%m-%d')
|
||||||
|
return klass(ident=uid, uuid=uuid, date=date)
|
146
tests/fixtures.py
Normal file
146
tests/fixtures.py
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
import pytest
|
||||||
|
import facho.fe.form as form
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_debit_note_without_lines():
|
||||||
|
inv = form.DebitNote(form.InvoiceDocumentReference('1234', 'xx', datetime.now()))
|
||||||
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
|
inv.set_issue(datetime.now())
|
||||||
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('30')
|
||||||
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
||||||
|
inv.set_supplier(form.Party(
|
||||||
|
name = 'facho-supplier',
|
||||||
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
inv.set_customer(form.Party(
|
||||||
|
name = 'facho-customer',
|
||||||
|
ident = form.PartyIdentification('321', '', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
return inv
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_credit_note_without_lines():
|
||||||
|
inv = form.CreditNote(form.InvoiceDocumentReference('1234', 'xx', datetime.now()))
|
||||||
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
|
inv.set_issue(datetime.now())
|
||||||
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('20')
|
||||||
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
||||||
|
inv.set_supplier(form.Party(
|
||||||
|
name = 'facho-supplier',
|
||||||
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
inv.set_customer(form.Party(
|
||||||
|
name = 'facho-customer',
|
||||||
|
ident = form.PartyIdentification('321', '', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
return inv
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_invoice_without_lines():
|
||||||
|
inv = form.NationalSalesInvoice()
|
||||||
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
|
inv.set_issue(datetime.now())
|
||||||
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('10')
|
||||||
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
||||||
|
inv.set_supplier(form.Party(
|
||||||
|
name = 'facho-supplier',
|
||||||
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
inv.set_customer(form.Party(
|
||||||
|
name = 'facho-customer',
|
||||||
|
ident = form.PartyIdentification('321', '', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
return inv
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def simple_invoice():
|
||||||
|
inv = form.NationalSalesInvoice()
|
||||||
|
inv.set_period(datetime.now(), datetime.now())
|
||||||
|
inv.set_issue(datetime.now())
|
||||||
|
inv.set_ident('ABC123')
|
||||||
|
inv.set_operation_type('10')
|
||||||
|
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), ' 1234'))
|
||||||
|
inv.set_supplier(form.Party(
|
||||||
|
name = 'facho-supplier',
|
||||||
|
ident = form.PartyIdentification('123','', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
inv.set_customer(form.Party(
|
||||||
|
name = 'facho-customer',
|
||||||
|
ident = form.PartyIdentification('321','', '31'),
|
||||||
|
responsability_code = form.Responsability(['O-07']),
|
||||||
|
responsability_regime_code = '48',
|
||||||
|
organization_code = '1',
|
||||||
|
address = form.Address(
|
||||||
|
'', '', form.City('05001', 'Medellín'),
|
||||||
|
form.Country('CO', 'Colombia'),
|
||||||
|
form.CountrySubentity('05', 'Antioquia'))
|
||||||
|
))
|
||||||
|
inv.add_invoice_line(form.InvoiceLine(
|
||||||
|
quantity = 1,
|
||||||
|
description = 'producto facho',
|
||||||
|
item = form.StandardItem('test', 9999),
|
||||||
|
price = form.Price(form.Amount(100.0), '01', ''),
|
||||||
|
tax = form.TaxTotal(
|
||||||
|
tax_amount = form.Amount(0.0),
|
||||||
|
taxable_amount = form.Amount(0.0),
|
||||||
|
subtotals = [
|
||||||
|
form.TaxSubTotal(
|
||||||
|
percent = 19.0,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
))
|
||||||
|
return inv
|
@ -14,149 +14,7 @@ import facho.fe.form as form
|
|||||||
from facho import fe
|
from facho import fe
|
||||||
from facho.fe.form_xml import DIANInvoiceXML, DIANCreditNoteXML, DIANDebitNoteXML
|
from facho.fe.form_xml import DIANInvoiceXML, DIANCreditNoteXML, DIANDebitNoteXML
|
||||||
|
|
||||||
@pytest.fixture
|
from fixtures import *
|
||||||
def simple_debit_note_without_lines():
|
|
||||||
inv = form.DebitNote(form.InvoiceDocumentReference('1234', 'xx', datetime.now()))
|
|
||||||
inv.set_period(datetime.now(), datetime.now())
|
|
||||||
inv.set_issue(datetime.now())
|
|
||||||
inv.set_ident('ABC123')
|
|
||||||
inv.set_operation_type('30')
|
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
|
||||||
inv.set_supplier(form.Party(
|
|
||||||
name = 'facho-supplier',
|
|
||||||
ident = form.PartyIdentification('123','', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
inv.set_customer(form.Party(
|
|
||||||
name = 'facho-customer',
|
|
||||||
ident = form.PartyIdentification('321', '', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
return inv
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def simple_credit_note_without_lines():
|
|
||||||
inv = form.CreditNote(form.InvoiceDocumentReference('1234', 'xx', datetime.now()))
|
|
||||||
inv.set_period(datetime.now(), datetime.now())
|
|
||||||
inv.set_issue(datetime.now())
|
|
||||||
inv.set_ident('ABC123')
|
|
||||||
inv.set_operation_type('20')
|
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
|
||||||
inv.set_supplier(form.Party(
|
|
||||||
name = 'facho-supplier',
|
|
||||||
ident = form.PartyIdentification('123','', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
inv.set_customer(form.Party(
|
|
||||||
name = 'facho-customer',
|
|
||||||
ident = form.PartyIdentification('321', '', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
return inv
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def simple_invoice_without_lines():
|
|
||||||
inv = form.NationalSalesInvoice()
|
|
||||||
inv.set_period(datetime.now(), datetime.now())
|
|
||||||
inv.set_issue(datetime.now())
|
|
||||||
inv.set_ident('ABC123')
|
|
||||||
inv.set_operation_type('10')
|
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234'))
|
|
||||||
inv.set_supplier(form.Party(
|
|
||||||
name = 'facho-supplier',
|
|
||||||
ident = form.PartyIdentification('123','', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
inv.set_customer(form.Party(
|
|
||||||
name = 'facho-customer',
|
|
||||||
ident = form.PartyIdentification('321', '', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
return inv
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def simple_invoice():
|
|
||||||
inv = form.NationalSalesInvoice()
|
|
||||||
inv.set_period(datetime.now(), datetime.now())
|
|
||||||
inv.set_issue(datetime.now())
|
|
||||||
inv.set_ident('ABC123')
|
|
||||||
inv.set_operation_type('10')
|
|
||||||
inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), ' 1234'))
|
|
||||||
inv.set_supplier(form.Party(
|
|
||||||
name = 'facho-supplier',
|
|
||||||
ident = form.PartyIdentification('123','', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
inv.set_customer(form.Party(
|
|
||||||
name = 'facho-customer',
|
|
||||||
ident = form.PartyIdentification('321','', '31'),
|
|
||||||
responsability_code = form.Responsability(['O-07']),
|
|
||||||
responsability_regime_code = '48',
|
|
||||||
organization_code = '1',
|
|
||||||
address = form.Address(
|
|
||||||
'', '', form.City('05001', 'Medellín'),
|
|
||||||
form.Country('CO', 'Colombia'),
|
|
||||||
form.CountrySubentity('05', 'Antioquia'))
|
|
||||||
))
|
|
||||||
inv.add_invoice_line(form.InvoiceLine(
|
|
||||||
quantity = 1,
|
|
||||||
description = 'producto facho',
|
|
||||||
item = form.StandardItem('test', 9999),
|
|
||||||
price = form.Price(form.Amount(100.0), '01', ''),
|
|
||||||
tax = form.TaxTotal(
|
|
||||||
tax_amount = form.Amount(0.0),
|
|
||||||
taxable_amount = form.Amount(0.0),
|
|
||||||
subtotals = [
|
|
||||||
form.TaxSubTotal(
|
|
||||||
percent = 19.0,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
))
|
|
||||||
return inv
|
|
||||||
|
|
||||||
|
|
||||||
def test_invoicesimple_build(simple_invoice):
|
def test_invoicesimple_build(simple_invoice):
|
||||||
xml = DIANInvoiceXML(simple_invoice)
|
xml = DIANInvoiceXML(simple_invoice)
|
||||||
|
26
tests/test_query.py
Normal file
26
tests/test_query.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/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.
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import facho.fe.form as form
|
||||||
|
from facho import fe
|
||||||
|
from facho.fe.form_xml import DIANInvoiceXML, DIANCreditNoteXML, DIANDebitNoteXML
|
||||||
|
|
||||||
|
from fixtures import *
|
||||||
|
|
||||||
|
from facho.fe.form import query
|
||||||
|
|
||||||
|
def test_query_billing_reference(simple_invoice):
|
||||||
|
xml = DIANInvoiceXML(simple_invoice)
|
||||||
|
cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
|
||||||
|
xml.add_extension(cufe_extension)
|
||||||
|
out = xml.tostring()
|
||||||
|
|
||||||
|
reference = query.billing_reference(out, form.BillingReference)
|
||||||
|
assert isinstance(reference, form.BillingReference)
|
||||||
|
assert reference.ident != ''
|
||||||
|
assert reference.uuid != ''
|
||||||
|
assert reference.date != ''
|
Loading…
Reference in New Issue
Block a user