Skip to content

Commit

Permalink
Cambios para OpenERP 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
reingart committed Apr 16, 2016
1 parent 1ab8d48 commit 1daf645
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 55 deletions.
55 changes: 29 additions & 26 deletions electronic_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,20 @@ def do_pyafipws_request_cae(self, cr, uid, ids, context=None, *args):

# import the AFIP webservice helper for electronic invoice
if service == 'wsfe':
from pyafipws.wsfev1 import WSFEv1, SoapFault # local market
from pyafipws.wsfev1 import WSFEv1 # local market
ws = WSFEv1()
elif service == 'wsmtxca':
from pyafipws.wsmtx import WSMTXCA, SoapFault # local + detail
from pyafipws.wsmtx import WSMTXCA # local + detail
wsdl = cfg.get_param(cr, uid, 'pyafipws.wsmtxca.url', context=context)
ws = WSMTXCA()
elif service == 'wsfex':
from pyafipws.wsfexv1 import WSFEXv1, SoapFault # foreign trade
from pyafipws.wsfexv1 import WSFEXv1
wsdl = cfg.get_param(cr, uid, 'pyafipws.wsfex.url', context=context)
ws = WSFEXv1()
else:
raise osv.except_osv('Error !', "%s no soportado" % service)


from pyafipws.utils import SoapFault
# connect to the webservice and call to the test method
ws.Conectar(cache or "", wsdl or "", proxy or "")
# set AFIP webservice credentials:
Expand All @@ -146,9 +147,9 @@ def do_pyafipws_request_cae(self, cr, uid, ids, context=None, *args):
cbte_nro_next = int(cbte_nro_afip or 0) + 1
# verify that the invoice is the next one to be registered in AFIP
if cbte_nro != cbte_nro_next:
raise osv.except_osv('Error !',
'Referencia: %s \n'
'El número del comprobante debería ser %s y no %s' % (
raise osv.except_osv(u'Error !',
u'Referencia: %s \n'
u'El número del comprobante debería ser %s y no %s' % (
str(invoice.number), str(cbte_nro_next), str(cbte_nro)))

# invoice number range (from - to) and date:
Expand Down Expand Up @@ -209,7 +210,7 @@ def do_pyafipws_request_cae(self, cr, uid, ids, context=None, *args):
moneda_ctz = str(invoice.currency_id.rate)

# foreign trade data: export permit, country code, etc.:
if invoice.pyafipws_incoterms:
if False:##invoice.pyafipws_incoterms:
incoterms = invoice.pyafipws_incoterms.code
incoterms_ds = invoice.pyafipws_incoterms.name
else:
Expand Down Expand Up @@ -240,19 +241,20 @@ def do_pyafipws_request_cae(self, cr, uid, ids, context=None, *args):
cuit_pais_cliente = None
else:
cuit_pais_cliente = id_impositivo = None
if invoice.address_invoice_id:
# OpenERP 7 no tiene address_invoice_id
if invoice.partner_id:
domicilio_cliente = " - ".join([
invoice.address_invoice_id.name or '',
invoice.address_invoice_id.street or '',
invoice.address_invoice_id.street2 or '',
invoice.address_invoice_id.zip or '',
invoice.address_invoice_id.city or '',
invoice.partner_id.name or '',
invoice.partner_id.street or '',
invoice.partner_id.street2 or '',
invoice.partner_id.zip or '',
invoice.partner_id.city or '',
])
else:
domicilio_cliente = ""
if invoice.address_invoice_id.country_id:
if invoice.partner_id.country_id:
# map ISO country code to AFIP destination country code:
iso_code = invoice.address_invoice_id.country_id.code.lower()
iso_code = invoice.partner_id.country_id.code.lower()
pais_dst_cmp = AFIP_COUNTRY_CODE_MAP[iso_code]


Expand Down Expand Up @@ -614,7 +616,7 @@ def create(self, cr, uid, ids, datas, context):
moneda_ctz = str(invoice.currency_id.rate)

# foreign trade data: export permit, country code, etc.:
if invoice.pyafipws_incoterms:
if False: ##invoice.pyafipws_incoterms:
incoterms = invoice.pyafipws_incoterms.code
incoterms_ds = invoice.pyafipws_incoterms.name
else:
Expand Down Expand Up @@ -645,24 +647,25 @@ def create(self, cr, uid, ids, datas, context):
cuit_pais_cliente = None
else:
cuit_pais_cliente = id_impositivo = None
if invoice.address_invoice_id:
# address_invoice_id -> partner_id
if invoice.partner_id:
domicilio_cliente = " - ".join([
invoice.address_invoice_id.name or '',
invoice.address_invoice_id.street or '',
invoice.address_invoice_id.street2 or '',
invoice.partner_id.name or '',
invoice.partner_id.street or '',
invoice.partner_id.street2 or '',
])
localidad_cliente = " - ".join([
invoice.address_invoice_id.city or '',
invoice.address_invoice_id.zip or '',
invoice.partner_id.city or '',
invoice.partner_id.zip or '',
])
provincia_cliente = invoice.address_invoice_id.state_id
provincia_cliente = invoice.partner_id.state_id
else:
domicilio_cliente = ""
localidad_cliente = ""
provincia_cliente = ""
if invoice.address_invoice_id.country_id:
if invoice.partner_id.country_id:
# map ISO country code to AFIP destination country code:
iso_code = invoice.address_invoice_id.country_id.code.lower()
iso_code = invoice.partner_id.country_id.code.lower()
pais_dst_cmp = AFIP_COUNTRY_CODE_MAP[iso_code]

# set AFIP returned values
Expand Down
72 changes: 43 additions & 29 deletions journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
__license__ = "AGPL 3.0+"

from osv import fields, osv
from openerp.exceptions import Warning

try:
from openerp.tools.translate import _
except:
Expand All @@ -32,36 +34,36 @@

class journal_pyafipws_electronic_invoice(osv.osv):
_name = "account.journal"
_inherit = "account.journal"
_inherit = ["account.journal", 'mail.thread']
_columns = {
'pyafipws_electronic_invoice_service': fields.selection([
('wsfe','Mercado interno -sin detalle- RG2485 (WSFEv1)'),
('wsmtxca','Mercado interno -con detalle- RG2904 (WSMTXCA)'),
('wsbfe','Bono Fiscal -con detalle- RG2557 (WSMTXCA)'),
('wsfex','Exportación -con detalle- RG2758 (WSFEXv1)'),
('wsfe','Mercado interno -sin detalle- RG2485 (WSFEv1)'),
('wsmtxca','Mercado interno -con detalle- RG2904 (WSMTXCA)'),
('wsbfe','Bono Fiscal -con detalle- RG2557 (WSMTXCA)'),
('wsfex','Exportación -con detalle- RG2758 (WSFEXv1)'),
], _('AFIP WS electronic invoice'),
help="Habilita la facturación electrónica por webservices AFIP"),
'pyafipws_invoice_type' : fields.selection([
( '1','01-Factura A'),
( '2','02-Nota de Débito A'),
( '3','03-Nota de Crédito A'),
( '4','04-Recibos A'),
( '5','05-Nota de Venta al Contado A'),
( '6','06-Factura B'),
( '7','07-Nota de Débito B'),
( '8','08-Nota de Crédito B'),
( '9','09-Recibos B'),
('10','10-Notas de Venta al Contado B'),
('11','11-Factura C'),
('12','12-Nota de Débito C'),
('13','13-Nota de Crédito C'),
('15','Recibo C'),
('19','19-Factura E'),
('20','20-Nota de Débito E'),
('21','21-Nota de Crédito E'),
], 'Tipo Comprobante AFIP',
'pyafipws_invoice_type' : fields.selection([
( '1','01-Factura A'),
( '2','02-Nota de Débito A'),
( '3','03-Nota de Crédito A'),
( '4','04-Recibos A'),
( '5','05-Nota de Venta al Contado A'),
( '6','06-Factura B'),
( '7','07-Nota de Débito B'),
( '8','08-Nota de Crédito B'),
( '9','09-Recibos B'),
('10','10-Notas de Venta al Contado B'),
('11','11-Factura C'),
('12','12-Nota de Débito C'),
('13','13-Nota de Crédito C'),
('15','Recibo C'),
('19','19-Factura E'),
('20','20-Nota de Débito E'),
('21','21-Nota de Crédito E'),
], 'Tipo Comprobante AFIP',
help="Tipo de Comprobante AFIP"),
'pyafipws_point_of_sale' : fields.integer('Punto de Venta AFIP',
'pyafipws_point_of_sale' : fields.integer('Punto de Venta AFIP',
help="Prefijo de emisión habilitado en AFIP"),
}

Expand Down Expand Up @@ -95,8 +97,12 @@ def test_pyafipws_dummy(self, cr, uid, ids, context=None):
service,
ws.AppServerStatus,
ws.DbServerStatus,
ws.AuthServerStatus)
ws.AuthServerStatus)

self.log(cr, uid, ids[0], msg)
# OpenChatter (new)
self.message_post(cr, uid, ids, "AFIP Dummy Test", msg, context=context)
raise Warning(msg)
return {}

def test_pyafipws_point_of_sales(self, cr, uid, ids, context=None):
Expand All @@ -123,9 +129,13 @@ def test_pyafipws_point_of_sales(self, cr, uid, ids, context=None):
wsfev1.Sign = auth_data['sign']
# call the webservice method to get the enabled point of sales:
ret = wsfev1.ParamGetPtosVenta(sep=" ")
msg = "Pts.Vta. Habilitados en AFIP: " + '. '.join(ret)
msg += " - ".join([wsfev1.Excepcion, wsfev1.ErrMsg, wsfev1.Obs])
msg = u"Pts.Vta. Habilitados en AFIP: " + '. '.join(ret)
ws = wsfev1
msg += u" - ".join([ws.Excepcion, ws.ErrMsg, ws.Obs])
self.log(cr, uid, ids[0], msg)
# OpenChatter (new)
self.message_post(cr, uid, ids, "AFIP Ptos.Vta.", msg, context=context)
raise Warning(msg)
return {}

def get_pyafipws_last_invoice(self, cr, uid, ids,
Expand Down Expand Up @@ -165,8 +175,12 @@ def get_pyafipws_last_invoice(self, cr, uid, ids,
ult = ws.CompUltimoAutorizado(tipo_cbte, punto_vta)
elif service == "wsfex":
ult = ws.GetLastCMP(tipo_cbte, punto_vta)
msg = " - ".join([ws.Excepcion, ws.ErrMsg, ws.Obs])
msg = u"Ult.Cbte: Nro %s" % (ult, )
msg += u" - ".join([ws.Excepcion, ws.ErrMsg, ws.Obs])
self.log(cr, uid, ids[0], u"Ult.Cbte: N° %s %s" % (ult, msg))
# OpenChatter (new)
self.message_post(cr, uid, ids, "AFIP Ult. Nro", msg, context=context)
##raise Warning(msg)
ret[journal.id] = str(ult)
else:
msg = auth_data['err_msg']
Expand Down

0 comments on commit 1daf645

Please sign in to comment.