21.01.2015 Views

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

es = wsfe.aut(client, token, sign,<br />

CUIT=20234567393, tipo_cbte=1, punto_vta=1,<br />

cbt_desde=1, cbt_hasta=1,<br />

tipo_doc=80, nro_doc=23111111113,<br />

imp_total=121, imp_neto=100, impto_liq=21)<br />

print res['cae'], res['motivo']<br />

If everything went well, this will return the CAE (Electronic Authorization Code in<br />

Spanish), needed to make the electronic bill.<br />

That would be all for webservices in <strong>Python</strong>. For generation of the bill (for example in<br />

PDF), email delivery and such, see PyRece below.<br />

Legacy languages<br />

Beyond the applications in <strong>Python</strong>, this library is compatible with languages such as<br />

Visual Basic, ASP, Fox Pro, Cobol, Delphi, Genexus, PowerBuilder, PHP, .Net, Java, ABAP<br />

(SAP), etc. and with any language/application capable of creating Component Object<br />

Model (http://en.wikipedia.org/wiki/Component_Object_Model) in Windows (for example<br />

Excel or Access).<br />

This is easily accomplished using <strong>Python</strong>COM (part of the win32 extensions), wrapping a<br />

common class of python to be exposed to other applications, defining the methods and<br />

public attributes, the exposed name and other, for example:<br />

class WSAA:<br />

"Interface to the WebService of Authentication and Authorization"<br />

_public_methods_ = ['CreateTRA', 'SignTRA', 'CallWSAA']<br />

_public_attrs_ = ['Token', 'Sign', 'Version', 'XmlResponse']<br />

_readonly_attrs_ = _public_attrs_<br />

_reg_progid_ = "WSAA"<br />

_reg_clsid_ = "{6268820C-8900-4AE9-8A2D-F0A1EBD4CAC5}"<br />

Once the interface is registered, it can be called from any other application with this<br />

technology, for example, in Visual Basic it would be:<br />

Set WSFE = CreateObject("WSFE")<br />

WSFE.Token = WSAA.Token ' set token and sign of wsaa<br />

WSFE.Sign = WSAA.Sign<br />

WSFE.Cuit = "3000000000" ' issuer CUIT<br />

ok = WSFE.Conectar(url)<br />

cae = WSFE.Aut(id, presta_serv, tipo_doc, ...<br />

imp_tot_conc, imp_neto, impto_liq, ...)<br />

In our case this was very useful and made possible to many applications contemplate<br />

these new features (webservices, encryption, etc.) with minor modifications, which<br />

otherwise would have been difficult or even impossible.<br />

Text Files and Command Line<br />

Even though the COM interface is very useful for relatively modern applications, there<br />

are still very difficult to access languages or environments, where practically the only<br />

way of interoperatibility are text files.<br />

Languages as Cobol handle files with fields of fixed length (this was already supported by<br />

the RECE of SIAP app), we went down that road, which with <strong>Python</strong> was quite<br />

straightforward.<br />

The interface includes tools like RECE.PY and RECEX.PY which receive and process<br />

input files by command line, saving results in output files. This behavior es controlled by<br />

a configuration file (RECE.INI) which defines URLs, certificates and paths to use.<br />

PyRece: free SIAP<br />

The history doesn’t end here, some difficulties of the RECE Application or the online<br />

services to make electronic bills (limited functionality, delays or complexities, etc.,<br />

especially for the contributors that do not posess management system) have been seen,<br />

we developed a visual application (“desktop”) to facilitate and extend the possibilities<br />

brought by AFIP:<br />

Set WSAA = CreateObject("WSAA")<br />

tra = WSAA.CreateTRA()<br />

cms = WSAA.SignTRA(tra, "homo.crt", "homo.key")<br />

ta = WSAA.CallWSAA(cms, url)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!