From 31627cca95eb4bb3540a6ffe3013d8e09ccde58b Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Wed, 23 May 2018 23:42:57 -0500 Subject: [PATCH] Soporte para truncar impuestos --- source/app/controllers/util.py | 6 ++++++ source/app/models/main.py | 15 +++++++++++++++ source/static/js/controller/admin.js | 1 + source/static/js/controller/invoices.js | 6 ++++++ source/static/js/ui/admin.js | 4 ++++ source/static/js/ui/invoices.js | 6 ++++-- 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/source/app/controllers/util.py b/source/app/controllers/util.py index 31fbf31..ceac5f2 100644 --- a/source/app/controllers/util.py +++ b/source/app/controllers/util.py @@ -20,6 +20,7 @@ import uuid import zipfile from io import BytesIO +from math import trunc from pathlib import Path from xml.etree import ElementTree as ET from xml.dom.minidom import parseString @@ -3405,3 +3406,8 @@ def get_timbres(rfc, token): return result.json() except Exception as e: return '' + + +def truncate(value): + return trunc(value * 100) / 100 + diff --git a/source/app/models/main.py b/source/app/models/main.py index 6572380..ebe7117 100644 --- a/source/app/models/main.py +++ b/source/app/models/main.py @@ -246,6 +246,7 @@ def config_timbrar(): 'cfdi_tax_decimals': Configuracion.get_bool('chk_config_tax_decimals'), 'cfdi_with_taxes': Configuracion.get_bool('chk_config_price_with_taxes_in_invoice'), 'cfdi_add_same_product': Configuracion.get_bool('chk_config_add_same_product'), + 'cfdi_tax_locales_truncate': Configuracion.get_bool('chk_config_tax_locales_truncate'), } return conf @@ -334,6 +335,7 @@ class Configuracion(BaseModel): 'chk_config_tax_decimals', 'chk_config_price_with_taxes_in_invoice', 'chk_config_add_same_product', + 'chk_config_tax_locales_truncate', 'chk_config_anticipo', 'chk_config_cuenta_predial', 'chk_config_codigo_barras', @@ -3632,11 +3634,16 @@ class Facturas(BaseModel): rows = tuple(Facturas .select(Facturas.id, Facturas.serie, Facturas.folio, Facturas.uuid, Facturas.fecha, Facturas.tipo_comprobante, Facturas.estatus, + case(Facturas.pagada, ( + (True, 'Si'), + (False, 'No'), + )).alias('paid'), Facturas.total_mn, Socios.nombre.alias('cliente')) .where(filters) .join(Socios) .switch(Facturas).dicts() ) + return {'ok': True, 'rows': rows} @classmethod @@ -3673,6 +3680,7 @@ class Facturas(BaseModel): def _calculate_totals(self, invoice, products, tipo_comprobante): tax_locales = Configuracion.get_bool('chk_config_tax_locales') + tax_locales_truncate = Configuracion.get_bool('chk_config_tax_locales_truncate') tax_decimals = Configuracion.get_bool('chk_config_tax_decimals') subtotal = 0 descuento_cfdi = 0 @@ -3732,6 +3740,9 @@ class Facturas(BaseModel): else: impuesto_producto = round(float(tax.tasa) * base, DECIMALES) + if tax.key == '000' and tax_locales_truncate: + impuesto_producto = util.truncate(float(tax.tasa) * base) + if tax.tipo == 'T' and tax.key != '000': total_trasladados = (total_trasladados or 0) + impuesto_producto elif tax.tipo == 'R' and tax.key != '000': @@ -4674,6 +4685,7 @@ 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_locales_truncate = Configuracion.get_bool('chk_config_tax_locales_truncate') subtotal = 0 descuento_cfdi = 0 totals_tax = {} @@ -4724,6 +4736,9 @@ class PreFacturas(BaseModel): else: impuesto_producto = round(float(tax.tasa) * base, DECIMALES) + if tax.key == '000' and tax_locales_truncate: + impuesto_producto = util.truncate(float(tax.tasa) * base) + if tax.tipo == 'T' and tax.key != '000': total_trasladados = (total_trasladados or 0) + impuesto_producto elif tax.tipo == 'R' and tax.key != '000': diff --git a/source/static/js/controller/admin.js b/source/static/js/controller/admin.js index 8699ae0..5870879 100644 --- a/source/static/js/controller/admin.js +++ b/source/static/js/controller/admin.js @@ -65,6 +65,7 @@ var controllers = { $$('chk_config_tax_decimals').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_price_with_taxes_in_invoice').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_add_same_product').attachEvent('onItemClick', chk_config_item_click) + $$('chk_config_tax_locales_truncate').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_anticipo').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_ine').attachEvent('onItemClick', chk_config_item_click) $$('chk_config_edu').attachEvent('onItemClick', chk_config_item_click) diff --git a/source/static/js/controller/invoices.js b/source/static/js/controller/invoices.js index 8dd4af5..77546d4 100644 --- a/source/static/js/controller/invoices.js +++ b/source/static/js/controller/invoices.js @@ -171,6 +171,7 @@ function default_config(){ cfg_invoice['tax_decimals'] = values.cfdi_tax_decimals cfg_invoice['with_taxes'] = values.cfdi_with_taxes cfg_invoice['add_same_product'] = values.cfdi_add_same_product + cfg_invoice['tax_locales_truncate'] = values.cfdi_tax_locales_truncate if(values.cfdi_show_pedimento){ $$('grid_details').showColumn('pedimento') } @@ -851,6 +852,11 @@ function calcular_impuestos(){ }else{ impuesto_producto = (impuesto.tasa * base).round(DECIMALES) } + + if(cfg_invoice['tax_locales_truncate'] && impuesto.key == '000'){ + impuesto_producto = Math.trunc(impuesto.tasa * base * 100) / 100 + } + tmp = table_totals.findOne({'tax': tax.tax}) if(tmp === null){ table_totals.insert({'tax': tax.tax, 'importe': impuesto_producto}) diff --git a/source/static/js/ui/admin.js b/source/static/js/ui/admin.js index c9f8d5b..3f5cf20 100644 --- a/source/static/js/ui/admin.js +++ b/source/static/js/ui/admin.js @@ -602,6 +602,10 @@ var options_admin_otros = [ {view: 'checkbox', id: 'chk_config_add_same_product', labelWidth: 0, labelRight: 'Permitir agregar el mismo producto'}, ]}, + {cols: [{maxWidth: 15}, + {view: 'checkbox', id: 'chk_config_tax_locales_truncate', labelWidth: 0, + labelRight: 'Impuestos locales, truncar valores'}, + ]}, {maxHeight: 20}, {template: 'Ayudas varias', type: 'section'}, {cols: [{maxWidth: 15}, diff --git a/source/static/js/ui/invoices.js b/source/static/js/ui/invoices.js index 3180945..29c92c1 100644 --- a/source/static/js/ui/invoices.js +++ b/source/static/js/ui/invoices.js @@ -238,6 +238,8 @@ var grid_invoices_cols = [ adjust: 'header', sort: 'string'}, {id: "estatus", header: ["Estatus", {content: "selectFilter"}], adjust: "data", sort:"string"}, + {id: "paid", header: ["Pagada", {content: "selectFilter"}], + adjust: "data", sort:"string"}, {id: 'total_mn', header: ['Total M.N.', {content: 'numberFilter'}], width: 150, sort: 'int', format: webix.i18n.priceFormat, css: 'right', footer: {content: 'summTimbrada', css: 'right'}}, @@ -319,7 +321,7 @@ var grid_details = { var grid_totals_cols = [ {id: 'id', header: 'ID', hidden: true}, - {id: 'concepto', header: 'Concepto', width: 200, + {id: 'concepto', header: 'Concepto', width: 250, footer: {text: 'TOTAL', css:'right_footer'}, css:'right'}, {id: 'importe', header: 'Importe', width: 150, footer: {content: 'summColumn', css:'right_footer'}, @@ -331,7 +333,7 @@ var grid_totals = { view: 'datatable', id: 'grid_totals', select: false, - width: 350, + width: 400, header: false, footer: true, autoheight: true,