Ajuste de impuestos con 4 decimales

This commit is contained in:
Mauricio Baeza 2018-01-21 21:38:29 -06:00
parent 046a61a2f2
commit edcd1ae04e
4 changed files with 40 additions and 8 deletions

View File

@ -17,10 +17,11 @@ if __name__ == '__main__':
from controllers import util
from settings import log, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI, \
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_TAX = '{0:.4f}'
database_proxy = Proxy()
@ -219,6 +220,7 @@ def config_timbrar():
'cfdi_open_pdf': Configuracion.get_bool('chk_config_open_pdf'),
'cfdi_show_pedimento': Configuracion.get_bool('chk_config_show_pedimento'),
'cfdi_tax_locales': Configuracion.get_bool('chk_config_tax_locales'),
'cfdi_tax_decimals': Configuracion.get_bool('chk_config_tax_decimals'),
}
return conf
@ -3071,6 +3073,7 @@ class Facturas(BaseModel):
def _calculate_totals(self, invoice, products):
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
subtotal = 0
descuento_cfdi = 0
totals_tax = {}
@ -3113,7 +3116,10 @@ class Facturas(BaseModel):
for tax in p.impuestos:
if tax_locales and tax.tipo == 'R' and tax.key == '000':
base = product['importe']
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
if tax_decimals:
impuesto_producto = round(float(tax.tasa) * base, DECIMALES_TAX)
else:
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
if tax.tipo == 'T' and tax.key != '000':
total_trasladados = (total_trasladados or 0) + impuesto_producto
elif tax.tipo == 'R' and tax.key != '000':
@ -3229,6 +3235,8 @@ class Facturas(BaseModel):
return data
def _make_xml(self, invoice, auth):
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
tmp = 0
emisor = Emisor.select()[0]
certificado = Certificado.select()[0]
@ -3317,7 +3325,13 @@ class Facturas(BaseModel):
continue
base = row.importe - row.descuento
import_tax = round(impuesto.tasa * base, DECIMALES)
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)
xml_importe = FORMAT.format(import_tax)
tipo_factor = 'Tasa'
if impuesto.factor != 'T':
tipo_factor = 'Cuota'
@ -3326,7 +3340,7 @@ class Facturas(BaseModel):
"Impuesto": impuesto.key,
"TipoFactor": tipo_factor,
"TasaOCuota": str(impuesto.tasa),
"Importe": FORMAT.format(import_tax),
"Importe": xml_importe,
}
if impuesto.tipo == 'T':
traslados.append(tax)
@ -3347,6 +3361,7 @@ class Facturas(BaseModel):
total_locales_retenciones = 0
locales_trasladados = []
locales_retenciones = []
if not invoice.total_trasladados is None:
impuestos['TotalImpuestosTrasladados'] = \
FORMAT.format(invoice.total_trasladados)
@ -3382,12 +3397,18 @@ class Facturas(BaseModel):
tipo_factor = 'Tasa'
if tax.impuesto.factor != 'T':
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':
traslado = {
"Impuesto": tax.impuesto.key,
"TipoFactor": tipo_factor,
"TasaOCuota": str(tax.impuesto.tasa),
"Importe": FORMAT.format(tax.importe),
"Importe": xml_importe,
}
traslados.append(traslado)
else:
@ -3812,6 +3833,8 @@ class PreFacturas(BaseModel):
def _calculate_totals(self, invoice, products):
tax_locales = Configuracion.get_bool('chk_config_tax_locales')
tax_decimals = Configuracion.get_bool('chk_config_tax_decimals')
tax_decimals = True
subtotal = 0
descuento_cfdi = 0
totals_tax = {}
@ -3853,7 +3876,10 @@ class PreFacturas(BaseModel):
for tax in p.impuestos:
if tax_locales and tax.tipo == 'R' and tax.key == '000':
base = product['importe']
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
if tax_decimals:
impuesto_producto = round(float(tax.tasa) * base, DECIMALES_TAX)
else:
impuesto_producto = round(float(tax.tasa) * base, DECIMALES)
if tax.tipo == 'T' and tax.key != '000':
total_trasladados = (total_trasladados or 0) + impuesto_producto
elif tax.tipo == 'R' and tax.key != '000':
@ -3883,7 +3909,6 @@ class PreFacturas(BaseModel):
}
PreFacturasImpuestos.create(**invoice_tax)
# ~ total = subtotal + (total_trasladados or 0) - (total_retenciones or 0)
total = subtotal - descuento_cfdi + \
(total_trasladados or 0) - (total_retenciones or 0) \
+ locales_traslados - locales_retenciones

View File

@ -111,6 +111,7 @@ PRE = {
CURRENT_CFDI = '3.3'
DECIMALES = 2
DECIMALES_TAX = 4
IMPUESTOS = {
'ISR': '001',
'IVA': '002',

View File

@ -163,6 +163,7 @@ function default_config(){
}
cfg_invoice['open_pdf'] = values.cfdi_open_pdf
cfg_invoice['tax_locales'] = values.cfdi_tax_locales
cfg_invoice['tax_decimals'] = values.cfdi_tax_decimals
if(values.cfdi_show_pedimento){
$$('grid_details').showColumn('pedimento')
}
@ -796,7 +797,11 @@ function calcular_impuestos(){
base = (base * -1).round(DECIMALES)
}
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
if(cfg_invoice.tax_decimals){
impuesto_producto = (impuesto.tasa * base).round(DECIMALES_TAX)
}else{
impuesto_producto = (impuesto.tasa * base).round(DECIMALES)
}
tmp = table_totals.findOne({'tax': tax.tax})
if(tmp === null){

View File

@ -3,6 +3,7 @@ var RFC_PUBLICO = "XAXX010101000";
var RFC_EXTRANJERO = "XEXX010101000";
var PAIS = "México";
var DECIMALES = 2;
var DECIMALES_TAX = 4;
var CLAVE_ANTICIPOS = '84111506';