-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #124 Add afip_code to currency model. Add method get_afip_rate …
…to Rate model. Teniamos hard-coded los códigos de las monedas de AFIP. Se agrega el campo afip_code al modelo currency y se cargan algunos valores vía xml (PES, DOL, Libra esterlina, Peso Uruguay, Real). Se agrega metodo de consulta de cotización en el modelo Rate. Por ahora no se hace uso de este método. Tener en cuenta que la devolución de las cotizaciones son siempre de la forma: 1 monda extranjera -> XX.XX peso argentino Si la moneda fuerte es el peso argentino, entonces las cotizaciones en las monedas extranjeras debería den ser: 1 peso argentino -> xx.xx moneda extranjera. REL: issue #172 TODO: Faltaría agregar al resto de las monedas. Consultar cotizacion de la moneda al hacer nota de crédito.
- Loading branch information
Showing
5 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# The COPYRIGHT file at the top level of this repository contains | ||
# the full copyright notices and license terms. | ||
import datetime | ||
from pyafipws.wsfev1 import WSFEv1 | ||
from pyafipws.wsfexv1 import WSFEXv1 | ||
from . import afip_auth | ||
|
||
from trytond.model import fields | ||
from trytond.pyson import Eval, If, In | ||
from trytond.pool import PoolMeta | ||
|
||
__all__ = ['Currency', 'Rate'] | ||
|
||
|
||
class Currency(metaclass=PoolMeta): | ||
__name__ = 'currency.currency' | ||
afip_code = fields.Char('AFIP Code', size=3, | ||
help="The 3 digits AFIP currency code.") | ||
|
||
|
||
class Rate(metaclass=PoolMeta): | ||
__name__ = 'currency.currency.rate' | ||
|
||
def get_afip_rate(self, service='wsfex'): | ||
''' | ||
get rate from afip webservice. | ||
''' | ||
pool = Pool() | ||
Company = pool.get('company.company') | ||
company_id = Transaction().context.get('company') | ||
if not company_id: | ||
logger.error('The company is not defined') | ||
cls.raise_user_error('company_not_defined') | ||
company = Company(company_id) | ||
# authenticate against AFIP: | ||
auth_data = company.pyafipws_authenticate(service=service) | ||
|
||
if service == 'wsfe': | ||
ws = WSFEv1() | ||
if company.pyafipws_mode_cert == 'homologacion': | ||
WSDL = 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL' | ||
elif company.pyafipws_mode_cert == 'produccion': | ||
WSDL = ( | ||
'https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL') | ||
elif service == 'wsfex': | ||
ws = WSFEXv1() | ||
if company.pyafipws_mode_cert == 'homologacion': | ||
WSDL = 'https://wswhomo.afip.gov.ar/wsfexv1/service.asmx?WSDL' | ||
elif company.pyafipws_mode_cert == 'produccion': | ||
WSDL = ( | ||
'https://servicios1.afip.gov.ar/wsfexv1/service.asmx?WSDL') | ||
else: | ||
logger.critical('AFIP ws is not yet supported! %s', service) | ||
cls.raise_user_error('webservice_not_supported', service) | ||
|
||
cache_dir = afip_auth.get_cache_dir() | ||
ws.LanzarExcepciones = True | ||
try: | ||
ws.Conectar(wsdl=wsdl, cache=cache_dir) | ||
except Exception as e: | ||
msg = ws.Excepcion + ' ' + str(e) | ||
logger.error('WSAA connecting to afip: %s' % msg) | ||
cls.raise_user_error('wsaa_error', msg) | ||
ws.Cuit = vat_number | ||
ws.Token = auth_data['token'] | ||
ws.Sign = auth_data['sign'] | ||
|
||
if not date: | ||
Date = pool.get('ir.date') | ||
today = Date.today().strftime("%Y%m%d") | ||
if not self.currency.afip_code: | ||
logger.error('AFIP code is empty %s', self.currency.code) | ||
cls.raise_user_error('afip_code_empty') | ||
|
||
self.rate = Decimal(ws.GetParamCtz('DOL')) | ||
self.date = datetime.datetime.strptime(ws.FchCotiz, '%Y%m%d').date() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<!-- The COPYRIGHT file at the top level of this repository contains | ||
the full copyright notices and license terms. --> | ||
<data> | ||
<xpath expr="/form/field[@name='numeric_code']" position="after"> | ||
<label name="afip_code"/> | ||
<field name="afip_code"/> | ||
</xpath> | ||
</data> |