Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Maria Agustina
/
tpv_correcciones
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 42bc81a6
authored
2021-02-13 19:35:33 -0300
by
adrian
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
el qr generico anda
1 parent
e59c1f70
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
4 deletions
models/comprobante.py
models/qr.py
views/comprobante.xml
models/comprobante.py
View file @
42bc81a
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from
odoo
import
models
,
fields
,
api
,
exceptions
from
odoo
import
models
,
fields
,
api
,
exceptions
from
.qr
import
qrfiscal
class
asw_comprobante
(
models
.
Model
):
class
asw_comprobante
(
models
.
Model
):
_inherit
=
'asw.comprobante'
_inherit
=
'asw.comprobante'
...
@@ -14,10 +15,45 @@ class asw_comprobante(models.Model):
...
@@ -14,10 +15,45 @@ class asw_comprobante(models.Model):
inverse_name
=
'factura'
,
inverse_name
=
'factura'
,
)
)
qr
=
fields
.
Binary
(
afip_qr_img
=
fields
.
Binary
(
string
=
u'QR'
,
string
=
u'QR'
,
default
=
"QR Fiscal"
)
)
afip_qr
=
fields
.
Char
(
compute
=
'_compute_afip_qr'
,
string
=
'QR Fiscal'
)
qr
=
fields
.
Char
(
string
=
'QR'
)
@api.depends
(
'afip_qr_img'
)
def
_compute_afip_qr
(
self
):
for
rec
in
self
:
print
(
rec
.
comp_fecha
)
print
(
rec
.
comp_talonario
.
tal_tpc_id
.
tc_cod_afip
)
print
(
rec
.
comp_talonario
.
tal_ptv_id
.
ptv_nro
)
print
(
rec
.
afip_auth_code
)
print
(
rec
.
comp_total
)
try
:
if
rec
.
afip_auth_code
==
False
:
continue
()
print
(
self
.
cae_due_qr
(
rec
))
QR
=
qrfiscal
(
FechaEmision
=
rec
.
comp_fecha
,)
QR
.
GenerarQR
()
rec
.
afip_qr_img
=
QR
.
LeerQR
()
except
:
rec
.
afip_qr_img
=
False
def
cae_due_qr
(
self
,
rec
):
cae_due
=
''
.
join
(
[
c
for
c
in
str
(
rec
.
afip_auth_code_due
or
''
)
if
c
.
isdigit
()])
return
(
cae_due
)
#metodo p q campo de referencia escriba name
#metodo p q campo de referencia escriba name
#como el campo es one2many puse que tome el nombre de la primer referencia elegida
#como el campo es one2many puse que tome el nombre de la primer referencia elegida
@api.onchange
(
'referencia_corr'
)
@api.onchange
(
'referencia_corr'
)
...
...
models/qr.py
0 → 100644
View file @
42bc81a
import
qrcode
,
json
,
base64
class
qrfiscal
():
"""Armo esta clase para separar la generacion de la imagen del modelo
El unico objetivo es el orden, no tengo en claro cuanto me va a llevar
Capas es al pedo"""
doc_a
=
{
"fac"
:
"001:"
,
"notc"
:
"003"
,
"notd"
:
"002"
}
doc_b
=
{
"fac"
:
"006:"
,
"notc"
:
"008"
,
"notd"
:
"007"
}
def
__init__
(
self
,
ver
=
1
,
FechaEmision
=
"2020-10-13"
,
cuit
=
30000000007
,
PuntoVenta
=
10
,
tipoComprobante
=
"001"
,
nroCmp
=
94
,
importe
=
12100
,
moneda
=
"PES"
,
ctz
=
1
,
tipoDocRec
=
80
,
nroDocRec
=
20000000001
,
tipoCodAut
=
"E"
,
codAut
=
70417054367476
)
->
dict
:
self
.
data
=
{
"ver"
:
1
,
"fecha"
:
FechaEmision
,
"cuit"
:
cuit
,
"ptoVta"
:
PuntoVenta
,
"tipoCmp"
:
tipoComprobante
,
"nroCmp"
:
nroCmp
,
"importe"
:
importe
,
"moneda"
:
moneda
,
"ctz"
:
ctz
,
"tipoDocRec"
:
tipoDocRec
,
"nroDocRec"
:
nroDocRec
,
"tipoCodAut"
:
tipoCodAut
,
"codAut"
:
codAut
,
}
self
.
archivo
=
"""/dev/shm/{}.png"""
.
format
(
self
.
data
[
"cuit"
])
def
GenerarQR
(
self
):
json_dump
=
json
.
dumps
(
self
.
data
,
separators
=
(
','
,
':'
))
data
=
json_dump
.
encode
(
'ascii'
)
base64_bytes
=
base64
.
b64encode
(
data
)
base64_message
=
base64_bytes
.
decode
(
'ascii'
)
URL
=
"""https://www.afip.gob.ar/fe/qr/?p={}"""
.
format
(
base64_message
)
self
.
generadorQR
(
URL
)
def
generadorQR
(
self
,
URL
):
qr
=
qrcode
.
QRCode
(
version
=
1
,
box_size
=
2
,
border
=
2
)
qr
.
add_data
(
URL
)
qr
.
make
(
fit
=
True
)
img
=
qr
.
make_image
(
fill
=
'black'
,
back_color
=
'white'
)
img
.
save
(
self
.
archivo
)
def
LeerQR
(
self
):
data
=
open
(
self
.
archivo
,
"rb"
)
.
read
()
encoded
=
base64
.
b64encode
(
data
)
return
(
encoded
)
#qr = qrfiscal()
#jsz = qr.GenerarQR()
#import ipdb; ipdb.set_trace()
views/comprobante.xml
View file @
42bc81a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
<field
name=
"arch"
type=
"xml"
>
<field
name=
"arch"
type=
"xml"
>
<data>
<data>
<xpath
expr=
"//group[1]"
position=
"after"
>
<xpath
expr=
"//group[1]"
position=
"after"
>
<group
string=
"Referencias"
col=
"4"
>
<group
string=
"Referencias"
col=
"4"
attrs=
"{'invisible': [('comp_tal_menu', '!=', 'fac')]}"
>
<field
name=
"referencia_corr"
nolabel=
"1"
widget=
"many2many_tags"
/>
<field
name=
"referencia_corr"
nolabel=
"1"
widget=
"many2many_tags"
/>
</group>
</group>
</xpath>
</xpath>
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
<field
name=
"arch"
type=
"xml"
>
<field
name=
"arch"
type=
"xml"
>
<data>
<data>
<xpath
expr=
"//group[1]"
position=
"after"
>
<xpath
expr=
"//group[1]"
position=
"after"
>
<group
string=
"Referencias"
col=
"4"
>
<group
string=
"Referencias"
col=
"4"
attrs=
"{'invisible': [('comp_tal_menu', '!=', 'fac')]}"
>
<field
name=
"referencia_corr"
nolabel=
"1"
widget=
"many2many_tags"
/>
<field
name=
"referencia_corr"
nolabel=
"1"
widget=
"many2many_tags"
/>
</group>
</group>
</xpath>
</xpath>
...
@@ -37,7 +37,8 @@
...
@@ -37,7 +37,8 @@
<field
name=
"arch"
type=
"xml"
>
<field
name=
"arch"
type=
"xml"
>
<data>
<data>
<xpath
expr=
"//field[@name='afip_xml_response']"
position=
"after"
>
<xpath
expr=
"//field[@name='afip_xml_response']"
position=
"after"
>
<field
name=
"qr"
/>
<field
name=
"afip_qr"
/>
<field
name=
"afip_qr_img"
widget=
"image"
/>
</xpath>
</xpath>
</data>
</data>
</field>
</field>
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment