master #9

Closed
Aserrador wants to merge 11 commits from master into main
14 changed files with 107 additions and 58 deletions

View File

@@ -57,6 +57,17 @@ If you are proposing a feature:
Get Started! Get Started!
------------ ------------
Using docker
------------
1. make -f Makefile.dev dev-setup
1. make -f Makefile.dev dev-shell
2. make -f Makefile.dev test
3. make -f Makefile.dev tox
From Source Code
-----------
Ready to contribute? Here's how to set up `facho` for local development. Ready to contribute? Here's how to set up `facho` for local development.
1. Fork the `facho` repo . 1. Fork the `facho` repo .
@@ -94,13 +105,6 @@ Ready to contribute? Here's how to set up `facho` for local development.
7. Submit a pull request through the GitHub website. 7. Submit a pull request through the GitHub website.
Using docker
------------
1. make -f Makefile.dev build
2. make -f Makefile.dev dev-shell
3. make -f Makefile.dev python3.8 setup.py develop
4. make -f Makefile.dev python3.8 setup.py test
Pull Request Guidelines Pull Request Guidelines
----------------------- -----------------------

View File

@@ -2,16 +2,23 @@
FROM ubuntu:18.04 FROM ubuntu:18.04
RUN apt-get -qq update RUN apt-get -qq update
RUN apt install software-properties-common -y \
&& add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install -y --no-install-recommends \ RUN apt-get install -y --no-install-recommends \
python3.7 python3.7-distutils python3.7-dev \ python3.7 python3.7-distutils python3.7-dev \
python3.8 python3.8-distutils python3.8-dev \ python3.8 python3.8-distutils python3.8-dev \
python3.9 python3.9-distutils python3.9-dev \
python3.10 python3.10-distutils python3.10-dev \
wget \ wget \
ca-certificates ca-certificates
RUN wget https://bootstrap.pypa.io/get-pip.py \ RUN wget https://bootstrap.pypa.io/get-pip.py \
&& python3 get-pip.py pip==21.3 \ && python3.7 get-pip.py pip==22.2.2 \
&& python3.7 get-pip.py pip==21.3 \ && python3.8 get-pip.py pip==22.2.2 \
&& python3.8 get-pip.py pip==21.3 \ && python3.9 get-pip.py pip==22.2.2 \
&& python3.10 get-pip.py pip==22.2.2 \
&& rm get-pip.py && rm get-pip.py
RUN apt-get install -y --no-install-recommends \ RUN apt-get install -y --no-install-recommends \
@@ -20,12 +27,14 @@ RUN apt-get install -y --no-install-recommends \
build-essential \ build-essential \
zip zip
RUN python3.6 --version
RUN python3.7 --version RUN python3.7 --version
RUN python3.8 --version RUN python3.8 --version
RUN python3.9 --version
RUN python3.10 --version
RUN pip3.6 install setuptools setuptools-rust
RUN pip3.7 install setuptools setuptools-rust RUN pip3.7 install setuptools setuptools-rust
RUN pip3.8 install setuptools setuptools-rust RUN pip3.8 install setuptools setuptools-rust
RUN pip3.9 install setuptools setuptools-rust
RUN pip3.10 install setuptools setuptools-rust
RUN pip3 install tox pytest RUN pip3 install tox pytest

Binary file not shown.

View File

@@ -1,7 +1,7 @@
# -*- Autoconf -*- # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.71]) AC_PREREQ([2.69])
AC_INIT([facho-signer], [0.0.1], [bit4bit@riseup.net]) AC_INIT([facho-signer], [0.0.1], [bit4bit@riseup.net])
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/facho_signer.c]) AC_CONFIG_SRCDIR([src/facho_signer.c])

View File

@@ -181,8 +181,6 @@ class FachoXML:
return etree.QName(self.root).namespace return etree.QName(self.root).namespace
def append_element(self, elem, new_elem): def append_element(self, elem, new_elem):
#elem = self.find_or_create_element(xpath, append=append)
#self.builder.append(elem, new_elem)
self.builder.append(elem, new_elem) self.builder.append(elem, new_elem)
def add_extension(self, extension): def add_extension(self, extension):

View File

@@ -21,10 +21,10 @@ __all__ = ['DianClient',
class SOAPService: class SOAPService:
def get_wsdl(self): def wsdl(self):
raise NotImplementedError() raise NotImplementedError()
def get_service(self): def service(self):
raise NotImplementedError() raise NotImplementedError()
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -63,10 +63,10 @@ class GetNumberingRange(SOAPService):
accountCodeT: str accountCodeT: str
softwareCode: str softwareCode: str
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'GetNumberingRange' return 'GetNumberingRange'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -78,10 +78,10 @@ class SendBillAsync(SOAPService):
fileName: str fileName: str
contentFile: str contentFile: str
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'SendBillAsync' return 'SendBillAsync'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -106,10 +106,10 @@ class SendTestSetAsync(SOAPService):
contentFile: str contentFile: str
testSetId: str = '' testSetId: str = ''
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'SendTestSetAsync' return 'SendTestSetAsync'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -120,10 +120,10 @@ class SendBillSync(SOAPService):
fileName: str fileName: str
contentFile: bytes contentFile: bytes
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'SendBillSync' return 'SendBillSync'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -153,10 +153,10 @@ class GetStatusResponse:
class GetStatus(SOAPService): class GetStatus(SOAPService):
trackId: bytes trackId: bytes
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'GetStatus' return 'GetStatus'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -166,10 +166,10 @@ class GetStatus(SOAPService):
class GetStatusZip(SOAPService): class GetStatusZip(SOAPService):
trackId: bytes trackId: bytes
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'GetStatusZip' return 'GetStatusZip'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -179,10 +179,10 @@ class GetStatusZip(SOAPService):
class SendNominaSync(SOAPService): class SendNominaSync(SOAPService):
contentFile: bytes contentFile: bytes
def get_wsdl(self): def wsdl(self):
return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl' return 'https://vpfe.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
def get_service(self): def service(self):
return 'SendNominaSync' return 'SendNominaSync'
def build_response(self, as_dict): def build_response(self, as_dict):
@@ -193,31 +193,31 @@ class Habilitacion:
WSDL = 'https://vpfe-hab.dian.gov.co/WcfDianCustomerServices.svc?wsdl' WSDL = 'https://vpfe-hab.dian.gov.co/WcfDianCustomerServices.svc?wsdl'
class GetNumberingRange(GetNumberingRange): class GetNumberingRange(GetNumberingRange):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class SendBillAsync(SendBillAsync): class SendBillAsync(SendBillAsync):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class SendBillSync(SendBillSync): class SendBillSync(SendBillSync):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class SendTestSetAsync(SendTestSetAsync): class SendTestSetAsync(SendTestSetAsync):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class GetStatus(GetStatus): class GetStatus(GetStatus):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class GetStatusZip(GetStatusZip): class GetStatusZip(GetStatusZip):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class SendNominaSync(SendNominaSync): class SendNominaSync(SendNominaSync):
def get_wsdl(self): def wsdl(self):
return Habilitacion.WSDL return Habilitacion.WSDL
class DianGateway: class DianGateway:
@@ -226,7 +226,7 @@ class DianGateway:
raise NotImplementedError() raise NotImplementedError()
def _remote_service(self, conn, service): def _remote_service(self, conn, service):
return conn.service[service.get_service()] return conn.service[service.service()]
def _close(self, conn): def _close(self, conn):
return return
@@ -250,7 +250,7 @@ class DianClient(DianGateway):
self._password = password self._password = password
def _open(self, service): def _open(self, service):
return zeep.Client(service.get_wsdl(), wsse=UsernameToken(self._username, self._password)) return zeep.Client(service.wsdl(), wsse=UsernameToken(self._username, self._password))
class DianSignatureClient(DianGateway): class DianSignatureClient(DianGateway):
@@ -264,7 +264,7 @@ class DianSignatureClient(DianGateway):
# RESOLUCCION 0004: pagina 756 # RESOLUCCION 0004: pagina 756
from zeep.wsse import utils from zeep.wsse import utils
client = zeep.Client(service.get_wsdl(), wsse= client = zeep.Client(service.wsdl(), wsse=
BinarySignature( BinarySignature(
self.private_key_path, self.public_key_path, self.password, self.private_key_path, self.public_key_path, self.password,
signature_method=xmlsec.Transform.RSA_SHA256, signature_method=xmlsec.Transform.RSA_SHA256,

View File

@@ -122,8 +122,7 @@ class DianXMLExtensionCUDFE(FachoXMLExtension):
fachoxml.set_element('./cbc:UUID', cufe, fachoxml.set_element('./cbc:UUID', cufe,
schemeID=self.tipo_ambiente, schemeID=self.tipo_ambiente,
schemeName=self.schemeName()) schemeName=self.schemeName())
#DIAN 1.8.-2021: FAD03
fachoxml.set_element('./cbc:ProfileID', 'DIAN 2.1: Factura Electrónica de Venta')
fachoxml.set_element('./cbc:ProfileExecutionID', self._tipo_ambiente_int()) fachoxml.set_element('./cbc:ProfileExecutionID', self._tipo_ambiente_int())
#DIAN 1.7.-2020: FAB36 #DIAN 1.7.-2020: FAB36
fachoxml.set_element('./ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:QRCode', fachoxml.set_element('./ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:QRCode',

View File

@@ -18,3 +18,6 @@ class DIANCreditNoteXML(DIANInvoiceXML):
def tag_document_concilied(fexml): def tag_document_concilied(fexml):
return 'Credited' return 'Credited'
def post_attach_invoice(fexml, invoice):
fexml.set_element('./cbc:ProfileID', 'DIAN 2.1: Nota Crédito de Factura Electrónica de Venta')

View File

@@ -13,6 +13,9 @@ class DIANDebitNoteXML(DIANInvoiceXML):
def __init__(self, invoice): def __init__(self, invoice):
super().__init__(invoice, 'DebitNote') super().__init__(invoice, 'DebitNote')
def post_attach_invoice(fexml, invoice):
fexml.set_element('./cbc:ProfileID', 'DIAN 2.1 Nota Débito de Factura Electrónica de Venta')
def tag_document(fexml): def tag_document(fexml):
return 'DebitNote' return 'DebitNote'

View File

@@ -21,6 +21,7 @@ class DIANInvoiceXML(fe.FeXML):
ublextension = self.fragment('./ext:UBLExtensions/ext:UBLExtension', append=True) ublextension = self.fragment('./ext:UBLExtensions/ext:UBLExtension', append=True)
extcontent = ublextension.find_or_create_element('/ext:UBLExtension/ext:ExtensionContent') extcontent = ublextension.find_or_create_element('/ext:UBLExtension/ext:ExtensionContent')
self.attach_invoice(invoice) self.attach_invoice(invoice)
self.post_attach_invoice(invoice)
def set_supplier(fexml, invoice): def set_supplier(fexml, invoice):
fexml.placeholder_for('./cac:AccountingSupplierParty') fexml.placeholder_for('./cac:AccountingSupplierParty')
@@ -415,7 +416,6 @@ class DIANInvoiceXML(fe.FeXML):
return fexml._set_debit_note_document_reference(reference) return fexml._set_debit_note_document_reference(reference)
if isinstance(reference, CreditNoteDocumentReference): if isinstance(reference, CreditNoteDocumentReference):
return fexml._set_credit_note_document_reference(reference) return fexml._set_credit_note_document_reference(reference)
if isinstance(reference, InvoiceDocumentReference): if isinstance(reference, InvoiceDocumentReference):
return fexml._set_invoice_document_reference(reference) return fexml._set_invoice_document_reference(reference)
@@ -439,6 +439,7 @@ class DIANInvoiceXML(fe.FeXML):
if subtotal.scheme is not None: if subtotal.scheme is not None:
tax_amount_for[subtotal.scheme.code]['tax_amount'] += subtotal.tax_amount tax_amount_for[subtotal.scheme.code]['tax_amount'] += subtotal.tax_amount
tax_amount_for[subtotal.scheme.code]['taxable_amount'] += invoice_line.taxable_amount tax_amount_for[subtotal.scheme.code]['taxable_amount'] += invoice_line.taxable_amount
tax_amount_for[subtotal.scheme.code]['name'] = subtotal.scheme.name
# MACHETE ojo InvoiceLine.tax pasar a Invoice # MACHETE ojo InvoiceLine.tax pasar a Invoice
percent_for[subtotal.scheme.code] = subtotal.percent percent_for[subtotal.scheme.code] = subtotal.percent
@@ -453,10 +454,9 @@ class DIANInvoiceXML(fe.FeXML):
for index, item in enumerate(tax_amount_for.items()): for index, item in enumerate(tax_amount_for.items()):
cod_impuesto, amount_of = item cod_impuesto, amount_of = item
next_append = index > 0
#DIAN 1.7.-2020: FAS01 #DIAN 1.7.-2020: FAS01
line = fexml.fragment('./cac:TaxTotal', append=next_append) line = fexml.fragment('./cac:TaxTotal', append=True)
#DIAN 1.7.-2020: FAU06 #DIAN 1.7.-2020: FAU06
tax_amount = amount_of['tax_amount'] tax_amount = amount_of['tax_amount']
fexml.set_element_amount_for(line, fexml.set_element_amount_for(line,
@@ -486,7 +486,7 @@ class DIANInvoiceXML(fe.FeXML):
line.set_element('/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme/cbc:ID', line.set_element('/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme/cbc:ID',
cod_impuesto) cod_impuesto)
line.set_element('/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme/cbc:Name', line.set_element('/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme/cbc:Name',
'IVA') amount_of['name'])
# abstract method # abstract method
def tag_document(fexml): def tag_document(fexml):
@@ -566,7 +566,11 @@ class DIANInvoiceXML(fe.FeXML):
line.set_element('./cbc:MultiplierFactorNumeric', str(round(charge.multiplier_factor_numeric, 2))) line.set_element('./cbc:MultiplierFactorNumeric', str(round(charge.multiplier_factor_numeric, 2)))
fexml.set_element_amount_for(line, './cbc:Amount', charge.amount) fexml.set_element_amount_for(line, './cbc:Amount', charge.amount)
fexml.set_element_amount_for(line, './cbc:BaseAmount', charge.base_amount) fexml.set_element_amount_for(line, './cbc:BaseAmount', charge.base_amount)
def post_attach_invoice(fexml, invoice):
#DIAN 1.8.-2021: FAD03
fexml.set_element('./cbc:ProfileID', 'DIAN 2.1: Factura Electrónica de Venta')
def attach_invoice(fexml, invoice): def attach_invoice(fexml, invoice):
"""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"""

17
requirements_dev.txt Normal file
View File

@@ -0,0 +1,17 @@
attrs==22.1.0
distlib==0.3.6
filelock==3.8.0
iniconfig==1.1.1
packaging==21.3
platformdirs==2.5.2
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.9
pytest==7.1.3
semantic-version==2.10.0
setuptools-rust==1.5.2
six==1.16.0
tomli==2.0.1
tox==3.26.0
typing_extensions==4.4.0
virtualenv==20.16.5

View File

@@ -33,7 +33,24 @@ def test_invoicesimple_build_with_cufe(simple_invoice):
cufe = xml.get_element_text('/fe:Invoice/cbc:UUID') cufe = xml.get_element_text('/fe:Invoice/cbc:UUID')
assert cufe != '' assert cufe != ''
def test_invoice_profile_id(simple_invoice):
xml = DIANInvoiceXML(simple_invoice)
cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
xml.add_extension(cufe_extension)
assert xml.get_element_text('/fe:Invoice/cbc:ProfileID') == 'DIAN 2.1: Factura Electrónica de Venta'
def test_debit_note_profile_id(simple_invoice):
xml = DIANDebitNoteXML(simple_invoice)
cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
xml.add_extension(cufe_extension)
assert xml.get_element_text('/fe:DebitNote/cbc:ProfileID') == 'DIAN 2.1 Nota Débito de Factura Electrónica de Venta'
def test_credit_note_profile_id(simple_invoice):
xml = DIANCreditNoteXML(simple_invoice)
cufe_extension = fe.DianXMLExtensionCUFE(simple_invoice)
xml.add_extension(cufe_extension)
assert xml.get_element_text('/fe:CreditNote/cbc:ProfileID') == 'DIAN 2.1: Nota Crédito de Factura Electrónica de Venta'
def test_invoicesimple_xml_signed(monkeypatch, simple_invoice): def test_invoicesimple_xml_signed(monkeypatch, simple_invoice):
xml = DIANInvoiceXML(simple_invoice) xml = DIANInvoiceXML(simple_invoice)

15
tox.ini
View File

@@ -1,17 +1,12 @@
[tox] [tox]
envlist = py27, py34, py35, py36, flake8 envlist = py37, py38, py39, py310
[travis] [travis]
python = python =
3.6: py36 3.7: py37
3.5: py35 3.8: py38
3.4: py34 3.9: py39
2.7: py27 3.10: py310
[testenv:flake8]
basepython = python
deps = flake8
commands = flake8 facho
[testenv] [testenv]
setenv = setenv =