forked from elmau/empresa-libre
Ajuste de impuestos con 4 decimales
This commit is contained in:
parent
046a61a2f2
commit
edcd1ae04e
|
@ -17,10 +17,11 @@ if __name__ == '__main__':
|
||||||
from controllers import util
|
from controllers import util
|
||||||
from settings import log, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI, \
|
from settings import log, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI, \
|
||||||
INIT_VALUES, DEFAULT_PASSWORD, DECIMALES, IMPUESTOS, DEFAULT_SAT_PRODUCTO, \
|
INIT_VALUES, DEFAULT_PASSWORD, DECIMALES, IMPUESTOS, DEFAULT_SAT_PRODUCTO, \
|
||||||
CANCEL_SIGNATURE, PUBLIC, DEFAULT_SERIE_TICKET
|
CANCEL_SIGNATURE, PUBLIC, DEFAULT_SERIE_TICKET, DECIMALES_TAX
|
||||||
|
|
||||||
|
|
||||||
FORMAT = '{0:.2f}'
|
FORMAT = '{0:.2f}'
|
||||||
|
FORMAT_TAX = '{0:.4f}'
|
||||||
|
|
||||||
|
|
||||||
database_proxy = Proxy()
|
database_proxy = Proxy()
|
||||||
|
@ -219,6 +220,7 @@ def config_timbrar():
|
||||||
'cfdi_open_pdf': Configuracion.get_bool('chk_config_open_pdf'),
|
'cfdi_open_pdf': Configuracion.get_bool('chk_config_open_pdf'),
|
||||||
'cfdi_show_pedimento': Configuracion.get_bool('chk_config_show_pedimento'),
|
'cfdi_show_pedimento': Configuracion.get_bool('chk_config_show_pedimento'),
|
||||||
'cfdi_tax_locales': Configuracion.get_bool('chk_config_tax_locales'),
|
'cfdi_tax_locales': Configuracion.get_bool('chk_config_tax_locales'),
|
||||||
|
'cfdi_tax_decimals': Configuracion.get_bool('chk_config_tax_decimals'),
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
@ -3071,6 +3073,7 @@ class Facturas(BaseModel):
|
||||||
|
|
||||||
def _calculate_totals(self, invoice, products):
|
def _calculate_totals(self, invoice, products):
|
||||||
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
||||||
|
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
descuento_cfdi = 0
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
|
@ -3113,6 +3116,9 @@ class Facturas(BaseModel):
|
||||||
for tax in p.impuestos:
|
for tax in p.impuestos:
|
||||||
if tax_locales and tax.tipo == 'R' and tax.key == '000':
|
if tax_locales and tax.tipo == 'R' and tax.key == '000':
|
||||||
base = product['importe']
|
base = product['importe']
|
||||||
|
if tax_decimals:
|
||||||
|
impuesto_producto = round(float(tax.tasa) * base, DECIMALES_TAX)
|
||||||
|
else:
|
||||||
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
|
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
|
||||||
if tax.tipo == 'T' and tax.key != '000':
|
if tax.tipo == 'T' and tax.key != '000':
|
||||||
total_trasladados = (total_trasladados or 0) + impuesto_producto
|
total_trasladados = (total_trasladados or 0) + impuesto_producto
|
||||||
|
@ -3229,6 +3235,8 @@ class Facturas(BaseModel):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _make_xml(self, invoice, auth):
|
def _make_xml(self, invoice, auth):
|
||||||
|
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
|
||||||
|
tmp = 0
|
||||||
emisor = Emisor.select()[0]
|
emisor = Emisor.select()[0]
|
||||||
certificado = Certificado.select()[0]
|
certificado = Certificado.select()[0]
|
||||||
|
|
||||||
|
@ -3317,7 +3325,13 @@ class Facturas(BaseModel):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
base = row.importe - row.descuento
|
base = row.importe - row.descuento
|
||||||
|
if tax_decimals:
|
||||||
|
import_tax = round(impuesto.tasa * base, DECIMALES_TAX)
|
||||||
|
tmp += import_tax
|
||||||
|
xml_importe = FORMAT_TAX.format(import_tax)
|
||||||
|
else:
|
||||||
import_tax = round(impuesto.tasa * base, DECIMALES)
|
import_tax = round(impuesto.tasa * base, DECIMALES)
|
||||||
|
xml_importe = FORMAT.format(import_tax)
|
||||||
tipo_factor = 'Tasa'
|
tipo_factor = 'Tasa'
|
||||||
if impuesto.factor != 'T':
|
if impuesto.factor != 'T':
|
||||||
tipo_factor = 'Cuota'
|
tipo_factor = 'Cuota'
|
||||||
|
@ -3326,7 +3340,7 @@ class Facturas(BaseModel):
|
||||||
"Impuesto": impuesto.key,
|
"Impuesto": impuesto.key,
|
||||||
"TipoFactor": tipo_factor,
|
"TipoFactor": tipo_factor,
|
||||||
"TasaOCuota": str(impuesto.tasa),
|
"TasaOCuota": str(impuesto.tasa),
|
||||||
"Importe": FORMAT.format(import_tax),
|
"Importe": xml_importe,
|
||||||
}
|
}
|
||||||
if impuesto.tipo == 'T':
|
if impuesto.tipo == 'T':
|
||||||
traslados.append(tax)
|
traslados.append(tax)
|
||||||
|
@ -3347,6 +3361,7 @@ class Facturas(BaseModel):
|
||||||
total_locales_retenciones = 0
|
total_locales_retenciones = 0
|
||||||
locales_trasladados = []
|
locales_trasladados = []
|
||||||
locales_retenciones = []
|
locales_retenciones = []
|
||||||
|
|
||||||
if not invoice.total_trasladados is None:
|
if not invoice.total_trasladados is None:
|
||||||
impuestos['TotalImpuestosTrasladados'] = \
|
impuestos['TotalImpuestosTrasladados'] = \
|
||||||
FORMAT.format(invoice.total_trasladados)
|
FORMAT.format(invoice.total_trasladados)
|
||||||
|
@ -3382,12 +3397,18 @@ class Facturas(BaseModel):
|
||||||
tipo_factor = 'Tasa'
|
tipo_factor = 'Tasa'
|
||||||
if tax.impuesto.factor != 'T':
|
if tax.impuesto.factor != 'T':
|
||||||
tipo_factor = 'Cuota'
|
tipo_factor = 'Cuota'
|
||||||
|
|
||||||
|
if tax_decimals:
|
||||||
|
xml_importe = FORMAT_TAX.format(tax.importe)
|
||||||
|
else:
|
||||||
|
xml_importe = FORMAT.format(tax.importe)
|
||||||
|
|
||||||
if tax.impuesto.tipo == 'T':
|
if tax.impuesto.tipo == 'T':
|
||||||
traslado = {
|
traslado = {
|
||||||
"Impuesto": tax.impuesto.key,
|
"Impuesto": tax.impuesto.key,
|
||||||
"TipoFactor": tipo_factor,
|
"TipoFactor": tipo_factor,
|
||||||
"TasaOCuota": str(tax.impuesto.tasa),
|
"TasaOCuota": str(tax.impuesto.tasa),
|
||||||
"Importe": FORMAT.format(tax.importe),
|
"Importe": xml_importe,
|
||||||
}
|
}
|
||||||
traslados.append(traslado)
|
traslados.append(traslado)
|
||||||
else:
|
else:
|
||||||
|
@ -3812,6 +3833,8 @@ class PreFacturas(BaseModel):
|
||||||
|
|
||||||
def _calculate_totals(self, invoice, products):
|
def _calculate_totals(self, invoice, products):
|
||||||
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
|
||||||
|
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
|
||||||
|
tax_decimals = True
|
||||||
subtotal = 0
|
subtotal = 0
|
||||||
descuento_cfdi = 0
|
descuento_cfdi = 0
|
||||||
totals_tax = {}
|
totals_tax = {}
|
||||||
|
@ -3853,6 +3876,9 @@ class PreFacturas(BaseModel):
|
||||||
for tax in p.impuestos:
|
for tax in p.impuestos:
|
||||||
if tax_locales and tax.tipo == 'R' and tax.key == '000':
|
if tax_locales and tax.tipo == 'R' and tax.key == '000':
|
||||||
base = product['importe']
|
base = product['importe']
|
||||||
|
if tax_decimals:
|
||||||
|
impuesto_producto = round(float(tax.tasa) * base, DECIMALES_TAX)
|
||||||
|
else:
|
||||||
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
|
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
|
||||||
if tax.tipo == 'T' and tax.key != '000':
|
if tax.tipo == 'T' and tax.key != '000':
|
||||||
total_trasladados = (total_trasladados or 0) + impuesto_producto
|
total_trasladados = (total_trasladados or 0) + impuesto_producto
|
||||||
|
@ -3883,7 +3909,6 @@ class PreFacturas(BaseModel):
|
||||||
}
|
}
|
||||||
PreFacturasImpuestos.create(**invoice_tax)
|
PreFacturasImpuestos.create(**invoice_tax)
|
||||||
|
|
||||||
# ~ total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
|
|
||||||
total = subtotal - descuento_cfdi + \
|
total = subtotal - descuento_cfdi + \
|
||||||
(total_trasladados or 0) - (total_retenciones or 0) \
|
(total_trasladados or 0) - (total_retenciones or 0) \
|
||||||
+ locales_traslados - locales_retenciones
|
+ locales_traslados - locales_retenciones
|
||||||
|
|
|
@ -111,6 +111,7 @@ PRE = {
|
||||||
|
|
||||||
CURRENT_CFDI = '3.3'
|
CURRENT_CFDI = '3.3'
|
||||||
DECIMALES = 2
|
DECIMALES = 2
|
||||||
|
DECIMALES_TAX = 4
|
||||||
IMPUESTOS = {
|
IMPUESTOS = {
|
||||||
'ISR': '001',
|
'ISR': '001',
|
||||||
'IVA': '002',
|
'IVA': '002',
|
||||||
|
|
|
@ -163,6 +163,7 @@ function default_config(){
|
||||||
}
|
}
|
||||||
cfg_invoice['open_pdf'] = values.cfdi_open_pdf
|
cfg_invoice['open_pdf'] = values.cfdi_open_pdf
|
||||||
cfg_invoice['tax_locales'] = values.cfdi_tax_locales
|
cfg_invoice['tax_locales'] = values.cfdi_tax_locales
|
||||||
|
cfg_invoice['tax_decimals'] = values.cfdi_tax_decimals
|
||||||
if(values.cfdi_show_pedimento){
|
if(values.cfdi_show_pedimento){
|
||||||
$$('grid_details').showColumn('pedimento')
|
$$('grid_details').showColumn('pedimento')
|
||||||
}
|
}
|
||||||
|
@ -796,7 +797,11 @@ function calcular_impuestos(){
|
||||||
base = (base * -1).round(DECIMALES)
|
base = (base * -1).round(DECIMALES)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cfg_invoice.tax_decimals){
|
||||||
|
impuesto_producto = (impuesto.tasa * base).round(DECIMALES_TAX)
|
||||||
|
}else{
|
||||||
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
|
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
|
||||||
|
}
|
||||||
|
|
||||||
tmp = table_totals.findOne({'tax': tax.tax})
|
tmp = table_totals.findOne({'tax': tax.tax})
|
||||||
if(tmp === null){
|
if(tmp === null){
|
||||||
|
|
|
@ -3,6 +3,7 @@ var RFC_PUBLICO = "XAXX010101000";
|
||||||
var RFC_EXTRANJERO = "XEXX010101000";
|
var RFC_EXTRANJERO = "XEXX010101000";
|
||||||
var PAIS = "México";
|
var PAIS = "México";
|
||||||
var DECIMALES = 2;
|
var DECIMALES = 2;
|
||||||
|
var DECIMALES_TAX = 4;
|
||||||
var CLAVE_ANTICIPOS = '84111506';
|
var CLAVE_ANTICIPOS = '84111506';
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue