From ef79af8684e77fab54ef4f0c57dd2cdfbcaaa5a0 Mon Sep 17 00:00:00 2001 From: Yogesh Kushwaha Date: Wed, 20 Sep 2017 22:01:42 -0300 Subject: [PATCH] pass cfop to applet --- .../static/src/js/models.js | 55 ++++++++++++++++--- .../static/src/js/models.js | 4 +- .../static/src/js/screens.js | 8 +-- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/tko_l10n_br_point_of_sale/static/src/js/models.js b/tko_l10n_br_point_of_sale/static/src/js/models.js index 2798c97..377b733 100644 --- a/tko_l10n_br_point_of_sale/static/src/js/models.js +++ b/tko_l10n_br_point_of_sale/static/src/js/models.js @@ -61,6 +61,27 @@ function l10n_br_fields(instance, module) { //module is instance.point_of_sale }, }); + // Fiscal Classifications + module.PosModel.prototype.models.push({ + model: 'account.product.fiscal.classification', + fields: ['id', 'name', 'cfop_id'], + + loaded: function (self, fiscal_classifications) { + self.fiscal_classifications = fiscal_classifications; + }, + }); + + + // CFOPs + module.PosModel.prototype.models.push({ + model: 'l10n_br_account_product.cfop', + fields: ['id', 'code', 'name'], + + loaded: function (self, cfops) { + self.cfops = cfops; + }, + }); + // inherit Orderline to update product and taxes detail on line var OrderlineSuper = module.Orderline; module.Orderline = module.Orderline.extend({ @@ -69,6 +90,20 @@ function l10n_br_fields(instance, module) { //module is instance.point_of_sale return this.get_product().fiscal_classification_id[0]; }, + // return cfop_id and cfop_code + // cfop_id is saved in pos line and cfop_code is passed to applet + get_cfop_code: function () { + var fiscal_classification_id = this.get_product().fiscal_classification_id[0]; + var fiscal_classification = _.filter(this.pos.fiscal_classifications, function (fiscal_classification) { + return fiscal_classification && fiscal_classification.id === fiscal_classification_id; + }) + var cfop_id = fiscal_classification[0].cfop_id[0] || "" + var cfop = _.filter(this.pos.cfops, function (cfop) { + return cfop.id === cfop_id; + }) + return [cfop_id, cfop && cfop[0] && cfop[0].code || ""] + }, + get_tax_code: function (tax_code_id) { var tax_codes = this.pos.tax_codes; for (i = 0; i < tax_codes.length; i++) { @@ -107,13 +142,14 @@ function l10n_br_fields(instance, module) { //module is instance.point_of_sale return [tax_code_id, tax_amount] }, - // commented because we will get taxes from sever while saving order - // pass taxes from pos - //export_as_JSON: function() { - // var res = OrderlineSuper.prototype.export_as_JSON.call(this); - // res.taxes = this.get_tax_details(); - // return res; - //}, + //commented because we will get taxes from sever while saving order + //write cfop_id in the database + export_as_JSON: function() { + var res = OrderlineSuper.prototype.export_as_JSON.call(this); + //res.taxes = this.get_tax_details(); + res.cfop_id = this.get_cfop_code()[0] || false; + return res; + }, export_for_printing: function () { @@ -124,6 +160,11 @@ function l10n_br_fields(instance, module) { //module is instance.point_of_sale res.icms_tax_code = tax_detail[0] res.icms_tax_value = Number(parseFloat(tax_detail[1]).toFixed(2)) res.ncm = this.get_ncm(); + cfop = this.get_cfop_code() + cfop_id = cfop[0] + cfop_code = cfop[1] + res.cfop_id = cfop_id + res.cfop_code = cfop_code return res; }, diff --git a/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/models.js b/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/models.js index 4be8993..2d21157 100644 --- a/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/models.js +++ b/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/models.js @@ -16,8 +16,8 @@ function tko_pos_store_cnpj_cpf(instance, module){ //module is instance.point_of fields: ['id','journal_id','config_id','fiscal_code'], loaded: function(self,fiscal_codes){ self.fiscal_codes = fiscal_codes; }, }); - - + + diff --git a/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/screens.js b/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/screens.js index 16a6bc3..fbc2ba2 100644 --- a/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/screens.js +++ b/tko_l10n_br_point_of_sale_print_cupom_fiscal/static/src/js/screens.js @@ -496,7 +496,8 @@ function tko_pos_print_screens(instance, module) { //module is instance.point_of "quantidade": orderlines[i].quantity || 0, "valor_unitario": orderlines[i].price || 0.0, "percentualDesconto": orderlines_disc[i].discount_type === 'fi' ? fixed_discount : Number((parseFloat(orderlines_disc[i].quantity * orderlines_disc[i].price * orderlines_disc[i].discount) / 100).toFixed(2)) || 0.0, - "codDepartamento": 3 + "codDepartamento": 3, + "cfop_code": orderlines[i].cfop_code || "" }); } @@ -559,13 +560,8 @@ function tko_pos_print_screens(instance, module) { //module is instance.point_of document.activeElement.blur(); $("input").blur(); }, 250); - - } // end of if - - - });