Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
financing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
credipaz
financing
Merge requests
!1
[ADD] Parse the request and response to ease debug
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[ADD] Parse the request and response to ease debug
parse-ws-response
into
devel
Overview
0
Commits
5
Pipelines
0
Changes
1
Merged
Santiago Said
requested to merge
parse-ws-response
into
devel
7 years ago
Overview
0
Commits
5
Pipelines
0
Changes
1
Expand
Also the requests are stored and enable to trace posible errors
When the invoice is not received with success there is no error, store the problems in ws.request.errors and enable the user to retry later.
Edited
7 years ago
by
Santiago Said
0
0
Merge request reports
Viewing commit
fa060073
Prev
Next
Show latest version
1 file
+
1
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
fa060073
[UPD] Credentials
· fa060073
Santiago Said
authored
7 years ago
models/ws.py
0 → 100644
+
126
−
0
Options
# -*- coding: utf-8 -*-
from
openerp
import
models
,
fields
,
api
,
exceptions
,
_
from
lxml
import
etree
import
re
from
suds.client
import
Client
import
logging
_logger
=
logging
.
getLogger
(
__name__
)
class
ws_request
(
models
.
Model
):
_name
=
'
ws.request
'
_description
=
'
WS Request
'
date
=
fields
.
Datetime
(
default
=
fields
.
Datetime
.
now
)
invoice_id
=
fields
.
Many2one
(
'
account.invoice
'
)
xml_req
=
fields
.
Text
(
'
XML Request
'
)
xml_res
=
fields
.
Text
(
'
XML Response
'
)
detail_ids
=
fields
.
One2many
(
'
ws.request.detail
'
,
'
req_id
'
)
errors_ids
=
fields
.
One2many
(
'
ws.request.error
'
,
'
req_id
'
)
success
=
fields
.
Boolean
()
@api.multi
def
send
(
self
):
self
.
ensure_one
()
conf_obj
=
self
.
env
[
'
ir.config_parameter
'
].
sudo
()
ws_url
=
(
conf_obj
.
get_param
(
'
financing.ws.url
'
)
or
'
http://servicioscpz.credipaz.com/wsMIL/wsMIL.asmx
'
)
+
'
?WSDL
'
ws_user
=
conf_obj
.
sudo
().
get_param
(
'
financing.ws.user
'
)
ws_pass
=
conf_obj
.
sudo
().
get_param
(
'
financing.ws.pass
'
)
ws_pin
=
conf_obj
.
sudo
().
get_param
(
'
financing.ws.pin
'
)
ws_client
=
Client
(
ws_url
)
try
:
self
.
xml_res
=
ws_client
.
service
.
RegistrarVentaMil
(
sUsuario
=
ws_user
,
sPassword
=
ws_pass
,
sPin
=
ws_pin
,
xmlVenta
=
self
.
xml_req
)
except
Exception
as
e
:
self
.
write
({
'
errors_ids
'
:
[(
0
,
0
,
{
'
name
'
:
_
(
'
Connection Error
'
),
'
desc
'
:
e
})]
})
_logger
.
warning
(
'
Unable to send data to credipaz
'
)
_logger
.
warning
(
'
<<<DATA SENT TO CREDIPAZ>>>
\n
%s
'
%
ws_client
.
last_sent
())
_logger
.
warning
(
'
<<<DATA RECEIVED FROM CREDIPAZ>>>
\n
%s
'
%
ws_client
.
last_received
())
retcode
=
1
else
:
retcode
=
self
.
parse_response
()
return
retcode
@api.multi
def
parse_response
(
self
):
self
.
ensure_one
()
root
=
etree
.
fromstring
(
self
.
xml_res
.
encode
(
'
utf-8
'
))
err_lst
=
[]
for
err_obj
in
root
.
findall
(
'
./ERRORES/ERROR
'
):
match_obj
=
re
.
match
(
r
'
^(\w*):\s?(.*)
'
,
err_obj
.
text
)
if
match_obj
:
name
=
match_obj
.
group
(
1
)
desc
=
match_obj
.
group
(
2
)
else
:
name
=
'
_
'
desc
=
err_obj
.
text
err_lst
.
append
({
'
name
'
:
name
,
'
desc
'
:
desc
})
if
not
err_lst
:
self
.
success
=
True
return
0
else
:
self
.
write
({
'
errors_ids
'
:
[(
0
,
0
,
v
)
for
v
in
err_lst
]
})
return
1
return
0
def
create
(
self
,
vals
):
xml_as_str
=
vals
[
'
xml_req
'
]
root
=
etree
.
fromstring
(
xml_as_str
)
det_vals
=
[]
# Catch element that do not require iteration
non_it_elements
=
[
'
.//Fecha/*
'
,
'
.//Hora/*
'
,
'
.//Lugar/Sucursal
'
,
'
.//Lugar/Operador
'
,
'
.//Lugar/Terminal
'
,
'
.//Venta/TipoOperacion
'
,
'
.//Venta/DocumentoComprador
'
,
'
.//Venta/IdVenta
'
,
'
.//Venta/FormaPago
'
,
'
.//Venta/PrecioVenta
'
,
'
.//Venta/DescuentoAplicado
'
,
'
.//Venta/AgenteVentas
'
,
'
.//Comprador/Nombre
'
,
'
.//Comprador/TipoDoc
'
,
'
.//Comprador/Documento
'
,
]
for
el_path
in
non_it_elements
:
el_obj
=
root
.
find
(
el_path
)
det_vals
.
append
({
'
name
'
:
el_obj
.
tag
,
'
content
'
:
el_obj
.
text
})
# Iterate on productos
for
pos
,
el_obj
in
enumerate
(
root
.
findall
(
'
.//Productos/Producto
'
)):
for
sub_el_obj
in
el_obj
.
findall
(
'
./
'
):
prod_tag_name
=
'
Prod(%s): %s
'
%
(
pos
,
sub_el_obj
.
tag
)
det_vals
.
append
({
'
name
'
:
prod_tag_name
,
'
content
'
:
sub_el_obj
.
text
})
# Iterate on productos
for
pos
,
el_obj
in
enumerate
(
root
.
findall
(
'
.//FormasDePago/FormaDePago
'
)):
for
sub_el_obj
in
el_obj
.
findall
(
'
./
'
):
pago_tag_name
=
'
Pago(%s): %s
'
%
(
pos
,
sub_el_obj
.
tag
)
det_vals
.
append
({
'
name
'
:
pago_tag_name
,
'
content
'
:
sub_el_obj
.
text
})
vals
[
'
detail_ids
'
]
=
[(
0
,
0
,
v
)
for
v
in
det_vals
]
res
=
super
(
ws_request
,
self
).
create
(
vals
)
return
res
class
ws_request_detail
(
models
.
Model
):
_name
=
'
ws.request.detail
'
_description
=
'
Details of WS Request
'
req_id
=
fields
.
Many2one
(
'
ws.request
'
,
required
=
True
)
name
=
fields
.
Char
(
'
Field
'
)
content
=
fields
.
Char
(
'
Content
'
)
class
ws_request_error
(
models
.
Model
):
_name
=
'
ws.request.error
'
_description
=
'
Error of WS Request
'
req_id
=
fields
.
Many2one
(
'
ws.request
'
)
name
=
fields
.
Char
(
'
Field
'
)
desc
=
fields
.
Char
(
'
Description
'
)
Loading