Permalink
Browse files

[IMP] Moves being generated.

[IMP] local xsd files should point internally to s3 to avoid problems
with bad caching from sat website.

[TEST] lxml never from dev environment
  • Loading branch information...
nhomar committed Nov 2, 2016
1 parent 408dd66 commit 77a334465437a1ef4834d993e83c0895aa878c7c
View
@@ -27,6 +27,10 @@ def __init__(self, adict):
self.__dict__[k] = u'NA'
if isinstance(v, dict):
self.__dict__[k] = Struct(v)
if isinstance(v, list):
# import pdb; pdb.set_trace()
self.__dict__[k] = [Struct(x) for x in v]
class BaseDocument:
@@ -85,6 +89,10 @@ def __init__(self, dict_document, debug_mode=False, cache=1000):
self.__dict__[k] = u'NA'
if isinstance(v, dict):
self.__dict__[k] = Struct(v)
if isinstance(v, list):
# import pdb; pdb.set_trace()
self.__dict__[k] = [Struct(x) for x in v]
self.set_xml()
self.set_xslt_fname()
self.document_orginal = self.set_original()
View
@@ -96,3 +96,33 @@ def set_xslt(self):
def get_balance(dict_balance, debug_mode=False):
return CFDIBalance(dict_balance, debug_mode=debug_mode)
class CFDIMoves(BaseDocument):
"""Balance XML document
cfdi: v1.1 for Accounting."""
def __init__(self, dict_accounts, debug_mode=False):
self.template_fname = 'cfdi11moves.xml'
# We explicitly cached into s3 with the local test then ensure use
# the s3 url to use our cache. remove the tools.s3_url if you want to
# load first in the future
self.xslt_fname = \
tools.s3_url('http://s3.vauxoo.com/esquemas/ContabilidadE/1_1/PolizasPeriodo/PolizasPeriodo_1_1.xslt')
self.global_namespace = 'http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo'
self.set_template(self.template_fname)
super(CFDIMoves, self).__init__(dict_accounts, debug_mode=debug_mode)
def set_template(self, template_fname):
self.template = super(CFDIMoves, self).set_template(template_fname)
def set_schema(self, schema_fname):
self.schema = super(CFDIMoves, self).set_schema(schema_fname)
def set_xslt(self):
# TODO: Standarize the schema in this way also,
# we can not use different algorithms here
self.xstl = super(CFDIMoves, self).set_xslt()
def get_moves(dict_moves, debug_mode=False):
return CFDIMoves(dict_moves, debug_mode=debug_mode)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:catalogocuentas="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:contelec_td="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogosParaEsqContE" targetNamespace="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogosParaEsqContE" schemaLocation="http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogosParaEsqContE/CatalogosParaEsqContE.xsd"/>
<xs:import namespace="www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogosParaEsqContE" schemaLocation="http://s3.vauxoo.com/esquemas/ContabilidadE/1_1/CatalogosParaEsqContE/CatalogosParaEsqContE.xsd"/>
<xs:element name="Catalogo">
<xs:annotation>
<xs:documentation>Estándar de catálogo de cuentas que se entrega como parte de la contabilidad electrónica.</xs:documentation>
@@ -0,0 +1,20 @@
<PLZ:Polizas
xmlns:PLZ="www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo/PolizasPeriodo_1_1.xsd"
Anio="{{ inv.year }}"
Mes="{{ inv.month }}"
RFC="{{ inv.vat }}"
TipoSolicitud="{{ inv.type }}"
Version="1.1">
{% for move in inv.moves %}
<PLZ:Poliza Concepto="{{ move.name }}" Fecha="{{ move.date }}" NumUnIdenPol="{{ move.number }}">
{% for line in move.lines %}
<PLZ:Transaccion Concepto="{{ line.concept }}" DesCta="{{ line.account_name }}"
NumCta="{{ line.account_code }}" Debe="{{ line.debit }}" Haber="{{ line.credit }}">
</PLZ:Transaccion>
{% endfor %}
</PLZ:Poliza>
{% endfor %}
</PLZ:Polizas>

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -9,13 +9,9 @@ cryptography==1.0.1
PyYAML==3.11
click
suds
# m2crypto
# qrcode
# xmltodict
# pyopenssl
jinja2
lxml
# To use tools related to sync some things with s3.
# You will need lxml from the system environment in ubuntu
boto3
View
@@ -16,7 +16,7 @@
print(type(os.environ.get('TRAVIS')))
print('*'*50)
cfdiv32 = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_2/cadenaoriginal_3_2.xslt' # noqa
cfdiv32 = 'http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/PolizasPeriodo/PolizasPeriodo_1_1.xslt' # noqa
if not os.environ.get('TRAVIS') == 'true':
'''Here basically you need to have a profile called "dev" to use boto3
View
@@ -0,0 +1,69 @@
{'vat': 'VAU111017CG9',
'month': '01',
'year': '2016',
'type': 'AF',
'moves': [
{
'name': 'name of the move0',
'date': '2016-05-01',
'number': '1245-999-podr',
'lines': [
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111000001',
'debit': '123.22',
'credit': '0.0'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111000002',
'debit': '0.0',
'credit': '123.22'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111003',
'debit': '0.0',
'credit': '123.22'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111004',
'debit': '123.22',
'credit': '0.0'
}
]
},
{
'name': 'name of the move',
'date': '2016-05-31',
'number': '1245-999-podr',
'lines': [
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111000001',
'debit': '123.22',
'credit': '0.0'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111000002',
'debit': '0.0',
'credit': '123.22'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111003',
'debit': '0.0',
'credit': '123.22'
},
{'concept': 'something interesting',
'account_name': 'Some account name',
'account_code': '1111004',
'debit': '123.22',
'credit': '0.0'
}
]
},
]
}
View
@@ -45,6 +45,8 @@ def setUp(self):
self._get_test_file('coa.txt'))
self.dict_balance = eval(
self._get_test_file('balance.txt'))
self.dict_moves = eval(
self._get_test_file('moves.txt'))
self.real_document_xml = join(
dirname(cfdilib.__file__), "..", "tests", "demo", 'cfdv32.xml')
self.test_plain = join(
@@ -67,7 +69,7 @@ def test_002_get_cfd_debugged(self):
invoice = cfdv32.get_invoice(self.dict_invoice_basic_32,
debug_mode=True)
self.assertFalse(bool(invoice.ups),
'A valid dictionary gave error debugged_mode enabled %s' % invoice.document)
'A valid dictionary gave error debugged_mode enabled %s' % invoice.document)
self.assertTrue(invoice.document,
'A valid dictionary gave error debugged_mode enabled')
@@ -87,10 +89,20 @@ def test_002_get_balance(self):
balance = cfdv32.get_balance(self.dict_balance,
debug_mode=True)
self.assertFalse(bool(balance.ups),
'A valid dictionary gave error coa %s' % balance.document)
'A valid dictionary gave error coa %s' % balance.document)
self.assertTrue(balance.document,
'A valid dictionary gave error with the coa')
def test_002_get_moves(self):
"""With a given valid dict an
invoice object is created in debug_mode"""
moves = cfdv32.get_moves(self.dict_moves,
debug_mode=True)
self.assertFalse(bool(moves.ups),
'A valid dictionary gave error coa %s' % moves.document)
self.assertTrue(moves.document,
'A valid dictionary gave error with the coa')
def test_003_get_cfd(self):
"""With a given valid dict an invoice object is created"""
invoice = cfdv32.get_invoice(self.dict_invoice_basic_32)

0 comments on commit 77a3344

Please sign in to comment.