Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
9
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Daniel Santibáñez Polanco
l10n_cl_dte_exportacion
Commits
61b2403c
Commit
61b2403c
authored
Jan 20, 2020
by
Daniel Santibáñez Polanco
Browse files
[IMP]Mejoras para la emisión
parent
a66ce4e8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
166 additions
and
43 deletions
+166
-43
__manifest__.py
__manifest__.py
+1
-1
data/aduanas.formas_pago.csv
data/aduanas.formas_pago.csv
+2
-2
models/account_invoice.py
models/account_invoice.py
+143
-31
views/invoice_exportacion.xml
views/invoice_exportacion.xml
+2
-1
views/invoice_view.xml
views/invoice_view.xml
+18
-8
No files found.
__manifest__.py
View file @
61b2403c
...
...
@@ -2,7 +2,7 @@
{
"name"
:
"""Factura de Exportación Electrónica para Chile
\
"""
,
'version'
:
'
11.
0.18.
0.0
'
,
'version'
:
'0.18.
1
'
,
'category'
:
'Localization/Chile'
,
'sequence'
:
12
,
'author'
:
'Daniel Santibáñez Polanco, Cooperativa OdooCoop'
,
...
...
data/aduanas.formas_pago.csv
View file @
61b2403c
code,name,sigla
0
1,Cobranza hasta 1 año,COB1
0
2,Cobranza más de 1 año,COBRANZA
1,Cobranza hasta 1 año,COB1
2,Cobranza más de 1 año,COBRANZA
11,Acreditivo hasta 1 año,ACRED
12,Crédito de bancos y Org. financieros más de 1 año,CBOF
21,Sin pago,S/PAGO
...
...
models/account_invoice.py
View file @
61b2403c
...
...
@@ -13,6 +13,7 @@ class Exportacion(models.Model):
comodel_name
=
"account.invoice.exportacion"
,
readonly
=
True
,
states
=
{
'draft'
:
[(
'readonly'
,
False
)]},
copy
=
False
,
)
pais_destino
=
fields
.
Many2one
(
'aduanas.paises'
,
...
...
@@ -87,14 +88,30 @@ class Exportacion(models.Model):
related
=
"exportacion.pais_recepcion"
,
string
=
'País de Recepción'
,
)
bultos
=
fields
.
One2many
(
string
=
"Bultos"
,
comodel_name
=
"account.invoice.exportacion.bultos"
,
inverse_name
=
"exportacion_id"
,
related
=
'exportacion.bultos'
,
)
picking_id
=
fields
.
Many2one
(
'stock.picking'
,
string
=
"Movimiento Relacionado"
string
=
"Movimiento Relacionado"
,
)
@
api
.
one
@
api
.
returns
(
'self'
,
lambda
value
:
value
.
id
)
def
copy
(
self
,
default
=
None
):
default
=
dict
(
default
or
{})
if
self
.
exportacion
:
exp
=
self
.
exportacion
.
copy
()
default
.
setdefault
(
'exportacion'
,
exp
.
id
)
return
super
(
Exportacion
,
self
).
copy
(
default
)
def
format_vat
(
self
,
value
,
con_cero
=
False
):
if
self
[
0
].
_es_exportacion
()
and
self
[
0
].
partner_id
.
commercial_partner_id
.
vat
==
value
:
value
=
"CL555555555"
if
self
[
0
].
_es_exportacion
():
if
self
[
0
].
company_id
.
vat
!=
value
:
value
=
"CL555555555"
return
super
(
Exportacion
,
self
).
format_vat
(
value
,
con_cero
)
@
api
.
multi
...
...
@@ -104,13 +121,16 @@ class Exportacion(models.Model):
'currency_id'
:
self
.
currency_id
.
id
,
})
@
api
.
multi
def
eliminar_exportacion
(
self
):
if
self
.
state
==
'draft'
:
self
.
exportacion
.
unlink
()
def
_es_nc_exportacion
(
self
):
return
self
.
document_class_id
.
sii_code
in
[
111
,
112
]
def
_es_exportacion
(
self
):
if
self
.
document_class_id
.
sii_code
in
[
110
,
111
,
112
]:
return
True
return
False
return
self
.
document_class_id
.
sii_code
in
[
110
]
or
self
.
_es_nc_exportacion
()
def
currency_base
(
self
):
result
=
super
(
Exportacion
,
self
).
currency_base
()
...
...
@@ -118,6 +138,14 @@ class Exportacion(models.Model):
return
result
return
self
.
currency_id
def
currency_target
(
self
):
if
self
.
_es_exportacion
():
clp
=
self
.
env
.
ref
(
'base.CLP'
).
with_context
(
date
=
self
.
date_invoice
)
if
self
.
currency_id
!=
clp
:
return
self
.
env
.
ref
(
'base.CLP'
).
with_context
(
date
=
self
.
date_invoice
)
return
False
return
super
(
Exportacion
,
self
).
currency_target
()
def
_totales_normal
(
self
,
currency_id
,
MntExe
,
MntNeto
,
IVA
,
TasaIVA
,
MntTotal
=
0
,
MntBase
=
0
):
if
not
self
.
_es_exportacion
():
...
...
@@ -154,9 +182,66 @@ class Exportacion(models.Model):
def
_id_doc
(
self
,
taxInclude
=
False
,
MntExe
=
0
):
res
=
super
(
Exportacion
,
self
).
_id_doc
(
taxInclude
,
MntExe
)
res
[
'FmaPagExp'
]
=
self
.
payment_term_id
.
forma_pago_aduanas
.
code
if
self
.
_es_exportacion
()
and
self
.
payment_term_id
.
forma_pago_aduanas
:
res
[
'FmaPagExp'
]
=
self
.
payment_term_id
.
forma_pago_aduanas
.
code
return
res
def
_receptor
(
self
):
Receptor
=
{}
if
not
self
.
commercial_partner_id
.
vat
and
not
self
.
_es_boleta
()
and
not
self
.
_nc_boleta
()
and
not
self
.
_es_exportacion
():
raise
UserError
(
"Debe Ingresar RUT Receptor"
)
#if self._es_boleta():
# Receptor['CdgIntRecep']
Receptor
[
'RUTRecep'
]
=
self
.
format_vat
(
self
.
commercial_partner_id
.
vat
)
Receptor
[
'RznSocRecep'
]
=
self
.
_acortar_str
(
self
.
commercial_partner_id
.
name
,
100
)
if
not
self
.
partner_id
or
Receptor
[
'RUTRecep'
]
==
'66666666-6'
:
return
Receptor
if
not
self
.
_es_boleta
()
and
not
self
.
_nc_boleta
():
GiroRecep
=
self
.
acteco_id
.
name
or
self
.
commercial_partner_id
.
activity_description
.
name
if
not
GiroRecep
and
not
self
.
_es_exportacion
():
raise
UserError
(
_
(
'Seleccione giro del partner'
))
if
GiroRecep
:
Receptor
[
'GiroRecep'
]
=
self
.
_acortar_str
(
GiroRecep
,
40
)
if
self
.
partner_id
.
phone
or
self
.
commercial_partner_id
.
phone
:
Receptor
[
'Contacto'
]
=
self
.
_acortar_str
(
self
.
partner_id
.
phone
or
self
.
commercial_partner_id
.
phone
or
self
.
partner_id
.
email
,
80
)
if
(
self
.
commercial_partner_id
.
email
or
self
.
commercial_partner_id
.
dte_email
or
self
.
partner_id
.
email
or
self
.
partner_id
.
dte_email
)
and
not
self
.
_es_boleta
():
Receptor
[
'CorreoRecep'
]
=
self
.
commercial_partner_id
.
dte_email
or
self
.
partner_id
.
dte_email
or
self
.
commercial_partner_id
.
email
or
self
.
partner_id
.
email
street_recep
=
(
self
.
partner_id
.
street
or
self
.
commercial_partner_id
.
street
or
False
)
if
not
street_recep
and
not
self
.
_es_boleta
()
and
not
self
.
_nc_boleta
():
# or self.indicador_servicio in [1, 2]:
raise
UserError
(
'Debe Ingresar dirección del cliente'
)
street2_recep
=
(
self
.
partner_id
.
street2
or
self
.
commercial_partner_id
.
street2
or
False
)
if
street_recep
or
street2_recep
:
Receptor
[
'DirRecep'
]
=
self
.
_acortar_str
(
street_recep
+
(
' '
+
street2_recep
if
street2_recep
else
''
),
70
)
cmna_recep
=
self
.
partner_id
.
city_id
.
name
or
self
.
commercial_partner_id
.
city_id
.
name
if
not
cmna_recep
and
not
self
.
_es_boleta
()
and
not
self
.
_nc_boleta
()
and
not
self
.
_es_exportacion
():
raise
UserError
(
'Debe Ingresar Comuna del cliente'
)
else
:
Receptor
[
'CmnaRecep'
]
=
cmna_recep
ciudad_recep
=
self
.
partner_id
.
city
or
self
.
commercial_partner_id
.
city
if
ciudad_recep
:
Receptor
[
'CiudadRecep'
]
=
ciudad_recep
country
=
self
.
env
[
'aduanas.paises'
].
sudo
().
search
([
(
'name'
,
'='
,
self
.
partner_id
.
commercial_partner_id
.
country_id
.
name
.
upper
())])
Receptor
[
'Nacionalidad'
]
=
country
.
code
return
Receptor
def
_validaciones_uso_dte
(
self
):
super
(
Exportacion
,
self
).
_validaciones_uso_dte
()
if
self
.
_es_exportacion
():
if
self
.
incoterms_id
and
not
self
.
payment_term_id
:
raise
UserError
(
"Debe Ingresar un Término de Pago"
)
expo
=
self
.
exportacion
if
not
self
.
payment_term_id
.
modalidad_venta
and
not
self
.
_es_nc_exportacion
():
raise
UserError
(
"Debe indicar Modalidad de venta"
)
if
self
.
ind_servicio
in
[
3
,
4
,
5
]
and
self
.
payment_term_id
.
modalidad_venta
.
code
!=
'1'
:
raise
UserError
(
"La modalidad de venta del plazo de pago debe ser 1.- A FIRME"
)
def
get_monto_clausura
(
self
):
mnt_clau
=
self
.
payment_term_id
.
with_context
(
currency_id
=
self
.
currency_id
.
id
).
compute
(
self
.
amount_total
,
date_ref
=
self
.
date_invoice
)[
0
]
return
round
(
mnt_clau
[
0
][
1
],
2
)
def
_bultos
(
self
,
bultos
):
Bultos
=
[]
for
b
in
bultos
:
...
...
@@ -170,17 +255,11 @@ class Exportacion(models.Model):
def
_aduana
(
self
):
expo
=
self
.
exportacion
Aduana
=
{}
#if not in 3,4,5
if
self
.
payment_term_id
:
Aduana
[
'CodModVenta'
]
=
self
.
payment_term_id
.
forma_pago_aduanas
.
code
elif
not
self
.
_es_nc_exportacion
():
raise
UserError
(
"Debe Ingresar un Término de Pago"
)
Aduana
[
'CodModVenta'
]
=
self
.
payment_term_id
.
modalidad_venta
.
code
if
self
.
incoterms_id
:
Aduana
[
'CodClauVenta'
]
=
self
.
incoterms_id
.
aduanas_code
if
self
.
payment_term_id
:
mnt_clau
=
self
.
payment_term_id
.
with_context
(
currency_id
=
self
.
currency_id
.
id
).
compute
(
self
.
amount_total
,
date_ref
=
self
.
date_invoice
)[
0
]
Aduana
[
'TotClauVenta'
]
=
round
(
mnt_clau
[
0
][
1
],
2
)
Aduana
[
'TotClauVenta'
]
=
self
.
get_monto_clausura
()
if
expo
.
via
:
Aduana
[
'CodViaTransp'
]
=
expo
.
via
.
code
if
expo
.
chofer_id
:
...
...
@@ -198,12 +277,15 @@ class Exportacion(models.Model):
#Aduana['IdAdicPtoDesemb'] = expo.ind_puerto_desembarque
if
expo
.
tara
:
Aduana
[
'Tara'
]
=
expo
.
tara
if
expo
.
uom_tara
.
code
:
Aduana
[
'CodUnidMedTara'
]
=
expo
.
uom_tara
.
code
if
expo
.
peso_bruto
:
Aduana
[
'PesoBruto'
]
=
round
(
expo
.
peso_bruto
,
2
)
if
expo
.
uom_peso_bruto
.
code
:
Aduana
[
'CodUnidPesoBruto'
]
=
expo
.
uom_peso_bruto
.
code
if
expo
.
peso_neto
:
Aduana
[
'PesoNeto'
]
=
round
(
expo
.
peso_neto
,
2
)
if
expo
.
uom_peso_neto
.
code
:
Aduana
[
'CodUnidPesoNeto'
]
=
expo
.
uom_peso_neto
.
code
if
expo
.
total_items
:
Aduana
[
'TotItems'
]
=
expo
.
total_items
...
...
@@ -246,10 +328,11 @@ class Exportacion(models.Model):
Transporte
[
'Chofer'
]
=
{}
Transporte
[
'Chofer'
][
'RUTChofer'
]
=
self
.
format_vat
(
self
.
chofer
.
vat
)
Transporte
[
'Chofer'
][
'NombreChofer'
]
=
self
.
chofer
.
name
[:
30
]
partner_id
=
self
.
partner_id
or
self
.
company_id
.
partner_id
Transporte
[
'DirDest'
]
=
(
partner_id
.
street
or
''
)
+
' '
+
(
partner_id
.
street2
or
''
)
Transporte
[
'CmnaDest'
]
=
partner_id
.
state_id
.
name
or
''
Transporte
[
'CiudadDest'
]
=
partner_id
.
city
or
''
if
not
self
.
_es_exportacion
():
partner_id
=
self
.
partner_id
or
self
.
company_id
.
partner_id
Transporte
[
'DirDest'
]
=
(
partner_id
.
street
or
''
)
+
' '
+
(
partner_id
.
street2
or
''
)
Transporte
[
'CmnaDest'
]
=
partner_id
.
state_id
.
name
or
''
Transporte
[
'CiudadDest'
]
=
partner_id
.
city
or
''
Transporte
[
'Aduana'
]
=
self
.
_aduana
()
return
Transporte
...
...
@@ -264,19 +347,48 @@ class Exportacion(models.Model):
res
[
'OtraMoneda'
]
=
self
.
_totales_otra_moneda
(
another_currency_id
,
MntExe
,
MntNeto
,
IVA
,
TasaIVA
,
MntTotal
,
MntBase
)
res
[
'Transporte'
]
=
self
.
_transporte
()
if
self
.
_es_exportacion
()
and
self
.
ind_servicio
!=
4
:
res
[
'Transporte'
]
=
self
.
_transporte
()
elif
self
.
_es_exportacion
()
and
not
self
.
ind_servicio
:
raise
UserError
(
"Si es una factura de exportación, debe indicar el tipo de servicio"
)
return
res
@
api
.
onchange
(
'
global_descuentos_recargos
'
)
@
api
.
onchange
(
'
monto_flete'
,
'monto_seguro
'
)
def
_set_seguros
(
self
):
_logger
.
warning
(
"expo"
)
mnt_seguro
=
0
mnt_flete
=
0
if
self
.
exportacion
:
for
gdr
in
self
.
global_descuentos_recargos
:
if
gdr
.
aplicacion
==
'flete'
:
mnt_flete
+=
gdr
.
valor
elif
gdr
.
aplicacion
==
'seguro'
:
mnt_seguro
+=
gdr
.
valor
self
.
exportacion
.
monto_flete
=
mnt_flete
self
.
exportacion
.
monto_seguro
=
mnt_seguro
if
self
.
monto_flete
:
flete
=
self
.
env
[
'account.invoice.gdr'
].
search
([
(
'type'
,
'='
,
'R'
),
(
'invoice_id'
,
'='
,
self
.
id
),
(
'aplicacion'
,
'='
,
'flete'
),
])
if
not
flete
:
flete
=
self
.
env
[
'account.invoice.gdr'
].
create
({
'type'
:
'R'
,
'invoice_id'
:
self
.
id
,
'aplicacion'
:
'flete'
,
'impuesto'
:
'exentos'
,
'gdr_detail'
:
'Flete'
,
'gdr_type'
:
'amount'
,
})
flete
.
valor
=
self
.
monto_flete
if
self
.
monto_seguro
:
seguro
=
self
.
env
[
'account.invoice.gdr'
].
search
([
(
'type'
,
'='
,
'R'
),
(
'invoice_id'
,
'='
,
self
.
id
),
(
'aplicacion'
,
'='
,
'seguro'
),
])
if
not
seguro
:
seguro
=
self
.
env
[
'account.invoice.gdr'
].
create
({
'type'
:
'R'
,
'invoice_id'
:
self
.
id
,
'aplicacion'
:
'seguro'
,
'impuesto'
:
'exentos'
,
'gdr_detail'
:
'Seguro'
,
'gdr_type'
:
'amount'
,
})
seguro
.
valor
=
self
.
monto_seguro
@
api
.
onchange
(
'bultos'
)
def
tot_bultos
(
self
):
self
.
exportacion
.
tot_bultos
()
views/invoice_exportacion.xml
View file @
61b2403c
...
...
@@ -19,12 +19,12 @@
<field
name=
"peso_neto"
/>
<field
name=
"uom_peso_neto"
/>
<field
name=
"total_items"
/>
<field
name=
"total_bultos"
invisible=
"1"
/>
<field
name=
"monto_flete"
/>
<field
name=
"monto_seguro"
/>
<field
name=
"pais_recepcion"
/>
<field
name=
"total_bultos"
/>
<field
name=
"bultos"
/>
<field
name=
"currency_id"
/>
</group>
</sheet>
...
...
@@ -42,6 +42,7 @@
<field
name=
"tipo_bulto"
/>
<field
name=
"cantidad_bultos"
/>
<field
name=
"marcas"
/>
<field
name=
"exportacion_id"
invisible=
"1"
/>
</group>
</sheet>
</form>
...
...
views/invoice_view.xml
View file @
61b2403c
...
...
@@ -9,21 +9,22 @@
<notebook>
<page
string=
"Datos de Exportación"
name=
"exportacion"
>
<header>
<button
name=
"crear_exportacion"
type=
"object"
string=
"Crear Exportación"
/>
<button
name=
"crear_exportacion"
type=
"object"
string=
"Crear Exportación"
attrs=
"{'invisible': [('exportacion', '!=', False)]}"
/>
<button
name=
"eliminar_exportacion"
type=
"object"
string=
"Eliminar Exportación"
attrs=
"{'invisible': [('exportacion', '=', False)]}"
/>
</header>
<group>
<field
name=
"exportacion"
/>
<field
name=
"exportacion"
invisible=
"1"
/>
</group>
<group
string=
"Resumen Exportación"
>
<group
string=
"Resumen Exportación"
attrs=
"{'invisible': [('exportacion', '=', False)]}"
>
<group>
<field
name=
"
pais_destino"
/>
<field
name=
"
via"
/>
<field
name=
"puerto_embarque"
/>
<field
name=
"pais_destino"
/>
<field
name=
"puerto_desembarque"
/>
<field
name=
"via"
/>
<field
name=
"pais_recepcion"
/>
<field
name=
"carrier_id"
/>
</group>
<group>
<field
name=
"carrier_id"
/>
<field
name=
"tara"
/>
<field
name=
"uom_tara"
/>
<field
name=
"peso_bruto"
/>
...
...
@@ -32,9 +33,18 @@
<field
name=
"uom_peso_neto"
/>
<field
name=
"total_items"
/>
<field
name=
"total_bultos"
/>
<field
name=
"monto_flete"
readonly=
"1"
/>
<field
name=
"monto_seguro"
readonly=
"1"
/>
<field
name=
"monto_flete"
/>
<field
name=
"monto_seguro"
/>
</group>
<h4>
Bultos
</h4>
<field
name=
"bultos"
context=
"{'default_exportacion_id': exportacion}"
>
<tree>
<field
name=
"cantidad_bultos"
/>
<field
name=
"tipo_bulto"
/>
<field
name=
"marcas"
/>
<field
name=
"exportacion_id"
invisible=
"1"
/>
</tree>
</field>
</group>
</page>
</notebook>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment