From fb6202dcdb9baf42ee2793bbdf098a1f49e12fc4 Mon Sep 17 00:00:00 2001 From: Luiz Felipe do Divino Date: Tue, 15 Feb 2022 17:47:50 -0300 Subject: [PATCH 1/4] =?UTF-8?q?[FIX]=20Fluxo=20offline=20para=20reimpress?= =?UTF-8?q?=C3=A3o=20e=20cancelamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n_br_pos/static/src/js/devices.js | 4 +- l10n_br_pos/static/src/js/screens.js | 63 ++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/l10n_br_pos/static/src/js/devices.js b/l10n_br_pos/static/src/js/devices.js index 9e672433183b..499e1ea48871 100644 --- a/l10n_br_pos/static/src/js/devices.js +++ b/l10n_br_pos/static/src/js/devices.js @@ -211,7 +211,8 @@ odoo.define("l10n_br_pos.devices", function (require) { function (result) { if (result.num_sessao != self.pos.config.sessao_sat) { self.message('cancelar_cfe', {json: order}, {timeout: 5000}) - .then(function (result) { + .then(function (retorno_sat) { + let result = retorno_sat; if (result && typeof result === 'object') { rpc.query({ model: 'pos.order', @@ -231,6 +232,7 @@ odoo.define("l10n_br_pos.devices", function (require) { }) }, function (error, event) { event.preventDefault(); + self.pos.config.sessao_sat++; self.pos.gui.show_popup('error', { 'title': _t('Error: Tempo Excedido'), 'body': _t('Tempo limite de 30 minutos para cancelamento foi excedido.'), diff --git a/l10n_br_pos/static/src/js/screens.js b/l10n_br_pos/static/src/js/screens.js index 266705cfff71..15d096203fd6 100644 --- a/l10n_br_pos/static/src/js/screens.js +++ b/l10n_br_pos/static/src/js/screens.js @@ -34,6 +34,17 @@ odoo.define("l10n_br_pos.screens", function (require) { (response) => { console.log(response); order.set_cfe_return(response); + self.pos.paid_orders.splice(0, 0, { + amount_total: order.get_total_paid() - order.get_change(), + date_order: moment(order.creation_date).format("DD/MM/YYYY hh:mm"), + id: order.sequence_number + 1, + name: order.name, + cnpj_cpf: order.cnpj_cpf || false, + partner_id: order.get_client() ? order.get_client().id : false, + pos_reference: "Order 00001-016-0011", + document_key: response.chaveConsulta, + document_file: response.arquivoCFeSAT + }); resolve(true); }, (error) => { @@ -136,23 +147,47 @@ odoo.define("l10n_br_pos.screens", function (require) { var self = this; this._super(); this.$('.order-list-contents').delegate('.pos_order_reprint','click',function(event){ + let selected_order_id = $(this).parent().parent().data('id'); rpc.query({ model: 'pos.order', method: 'retornar_order_by_id', - args: [$(this).parent().parent().data('id')], + args: [selected_order_id], limit: 1, }).then(function (orders){ self.pos.proxy.reprint_cfe(orders); + }, function (error, event) { + let order = self.pos.paid_orders.find(x => x.id === selected_order_id); + if (order.hasOwnProperty("document_file") && order.document_file) { + let orderSatObj = { + 'order_id': order.id, + 'chaveConsulta': order.document_key, + 'doc_destinatario': order.cnpj_cpf || '', + 'xml_cfe_venda': order.document_file, + } + self.pos.proxy.reprint_cfe(orderSatObj); + } }); }); this.$('.order-list-contents').delegate('.pos_order_cancel','click',function(event){ + let selected_order_id = $(this).parent().parent().data('id'); rpc.query({ model: 'pos.order', method: 'retornar_order_by_id', - args: [$(this).parent().parent().data('id')], + args: [selected_order_id], limit: 1, }).then(function (orders){ self.cancel_order_sat(orders); + }, function (error, event) { + let order = self.pos.paid_orders.find(x => x.id === selected_order_id); + if (order.hasOwnProperty("document_key") && order.document_key) { + let orderSatObj = { + 'order_id': order.id, + 'chaveConsulta': order.document_key, + 'doc_destinatario': order.cnpj_cpf || '', + 'xml_cfe_venda': order.document_file, + } + self.cancel_order_sat(orderSatObj); + } }); }); }, @@ -161,15 +196,27 @@ odoo.define("l10n_br_pos.screens", function (require) { var status = this.pos.proxy.get('status'); this.pos.proxy.cancel_order(order); -// var sat_status = status.drivers.satcfe ? status.drivers.satcfe.status : false; -// if( sat_status == 'connected'){ -// if(this.pos.config.iface_sat_via_proxy){ -// this.pos.proxy.cancel_order(order); -// } -// } }, }); + pos_order_screens.PosOrderScreenWidget.include({ + show: function () { + var self = this; + this._super(); + this.$('.order-list-contents').delegate('.pos_order_reprint','click',function(event){ + rpc.query({ + model: 'pos.order', + method: 'retornar_order_by_id', + args: [$(this).parent().parent().data('id')], + limit: 1, + }).then(function (orders){ + self.pos.proxy.reprint_cfe(orders); + }); + }); + }, + }); + +==== BASE ==== // Screens.PaymentScreenWidget = screens.PaymentScreenWidget.extend({ // order_is_valid: function (parent, options) { // var res = PaymentScreenWidgetSuper.prototype.order_is_valid.call(this, parent, options); From adf864d2fb85e3eafa557c973099b50a3f852c63 Mon Sep 17 00:00:00 2001 From: Luiz Felipe do Divino Date: Thu, 17 Feb 2022 15:23:09 -0300 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=20Fluxo=20de=20cancelamento=20sem=20c?= =?UTF-8?q?onex=C3=A3o=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n_br_pos/static/src/js/devices.js | 2 ++ l10n_br_pos/static/src/js/models.js | 3 +++ l10n_br_pos/static/src/js/screens.js | 12 +----------- l10n_br_pos/static/src/xml/pos.xml | 10 +++++++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/l10n_br_pos/static/src/js/devices.js b/l10n_br_pos/static/src/js/devices.js index 499e1ea48871..66c005ea44e3 100644 --- a/l10n_br_pos/static/src/js/devices.js +++ b/l10n_br_pos/static/src/js/devices.js @@ -206,6 +206,7 @@ odoo.define("l10n_br_pos.devices", function (require) { }, cancel_order: function (order) { var self = this; + paid_order = self.pos.paid_orders.find(x => x.id === order.id); order['cnpj_software_house'] = self.pos.config.cnpj_software_house; self.pos.proxy.message("sessao_sat", {json: self.pos.config.sessao_sat}, {timeout: 5000}).then( function (result) { @@ -214,6 +215,7 @@ odoo.define("l10n_br_pos.devices", function (require) { .then(function (retorno_sat) { let result = retorno_sat; if (result && typeof result === 'object') { + self.pos._refund_order(paid_order, retorno_sat); rpc.query({ model: 'pos.order', method: 'cancelar_order', diff --git a/l10n_br_pos/static/src/js/models.js b/l10n_br_pos/static/src/js/models.js index ffddb13dfc83..9e2505658f93 100644 --- a/l10n_br_pos/static/src/js/models.js +++ b/l10n_br_pos/static/src/js/models.js @@ -369,6 +369,9 @@ odoo.define("l10n_br_pos.models", function (require) { } return null; }, + _refund_order: function(order, retorno_sat) { + + }, }); var _config = _.findWhere(models.PosModel.prototype.models, {model: "pos.config"}); diff --git a/l10n_br_pos/static/src/js/screens.js b/l10n_br_pos/static/src/js/screens.js index 15d096203fd6..2d2400430891 100644 --- a/l10n_br_pos/static/src/js/screens.js +++ b/l10n_br_pos/static/src/js/screens.js @@ -34,17 +34,7 @@ odoo.define("l10n_br_pos.screens", function (require) { (response) => { console.log(response); order.set_cfe_return(response); - self.pos.paid_orders.splice(0, 0, { - amount_total: order.get_total_paid() - order.get_change(), - date_order: moment(order.creation_date).format("DD/MM/YYYY hh:mm"), - id: order.sequence_number + 1, - name: order.name, - cnpj_cpf: order.cnpj_cpf || false, - partner_id: order.get_client() ? order.get_client().id : false, - pos_reference: "Order 00001-016-0011", - document_key: response.chaveConsulta, - document_file: response.arquivoCFeSAT - }); + self.pos.paid_orders.splice(0, 0, order); resolve(true); }, (error) => { diff --git a/l10n_br_pos/static/src/xml/pos.xml b/l10n_br_pos/static/src/xml/pos.xml index 092cc5054aed..2142141565bc 100644 --- a/l10n_br_pos/static/src/xml/pos.xml +++ b/l10n_br_pos/static/src/xml/pos.xml @@ -55,8 +55,12 @@ - - + + + + + + Reimprimir @@ -67,7 +71,7 @@ Cancelar - + From e5dd2174976b3795cb5af0abdfdde9ce2cad9fdf Mon Sep 17 00:00:00 2001 From: Luiz Felipe do Divino Date: Thu, 24 Feb 2022 14:16:34 -0300 Subject: [PATCH 3/4] [ADD] Adicionar os dados de cancelamento no pos.order --- l10n_br_pos/models/pos_order.py | 25 +++++++++- l10n_br_pos/static/src/js/devices.js | 74 ++++++++++++++++++++-------- l10n_br_pos/static/src/js/models.js | 6 +-- 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/l10n_br_pos/models/pos_order.py b/l10n_br_pos/models/pos_order.py index 4e5768b04df3..6fdf4e788b0b 100644 --- a/l10n_br_pos/models/pos_order.py +++ b/l10n_br_pos/models/pos_order.py @@ -199,6 +199,16 @@ def _process_order(self, pos_order_vals): order.document_file_id = order._save_attachment( file_name=order.document_key + ".xml", file_content=document_file ).id + + cancel_document_file = pos_order_vals.get("cancel_document_file") + if cancel_document_file: + order.cancel_document_file_id = order._save_attachment( + file_name=order.cancel_document_key + ".xml", + file_content=cancel_document_file + ).id + + self._refund_cancelled_order(order) + return order @api.model @@ -224,6 +234,13 @@ def _order_fields(self, ui_order): "document_serie": key.numero_serie, } ) + + if ui_order.get("cancel_document_key"): + temp.update({ + "cancel_document_session_number": ui_order["cancel_document_session_number"], + "cancel_document_key": ui_order["cancel_document_key"], + }) + result.update(temp) return result @@ -431,7 +448,10 @@ def _populate_cancel_order_fields(self, order_vals): @api.model def cancelar_order(self, result): _logger.info(f'Result: {result}') - order = self.browse(result['order_id']) + if result.get('order_id'): + order = self.browse(result['order_id']) + else: + order = self.search([('document_key', '=', result['chave_consulta'])]) order._populate_cancel_order_fields(result) order.cancel_document_file_id = order._save_attachment( @@ -439,6 +459,9 @@ def cancelar_order(self, result): file_content=result['xml'] ).id + self._refund_cancelled_order(order) + + def _refund_cancelled_order(self, order): order.with_context( mail_create_nolog=True, tracking_disable=True, mail_create_nosubscribe=True, mail_notrack=True diff --git a/l10n_br_pos/static/src/js/devices.js b/l10n_br_pos/static/src/js/devices.js index 66c005ea44e3..be78bbc96cf7 100644 --- a/l10n_br_pos/static/src/js/devices.js +++ b/l10n_br_pos/static/src/js/devices.js @@ -206,7 +206,7 @@ odoo.define("l10n_br_pos.devices", function (require) { }, cancel_order: function (order) { var self = this; - paid_order = self.pos.paid_orders.find(x => x.id === order.id); + var paid_order = self.pos.paid_orders.find(x => x.id === order.id); order['cnpj_software_house'] = self.pos.config.cnpj_software_house; self.pos.proxy.message("sessao_sat", {json: self.pos.config.sessao_sat}, {timeout: 5000}).then( function (result) { @@ -215,16 +215,16 @@ odoo.define("l10n_br_pos.devices", function (require) { .then(function (retorno_sat) { let result = retorno_sat; if (result && typeof result === 'object') { - self.pos._refund_order(paid_order, retorno_sat); - rpc.query({ - model: 'pos.order', - method: 'cancelar_order', - args: [result], - }).then(function (orders) { - self.pos.gui.show_popup('error', { - message: _t('Venda Cancelada!'), - comment: _t('A venda foi cancelada com sucesso.'), - }); + if ($('.js_synch .js_connected').hasClass('.hidden')) { + rpc.query({ + model: 'pos.order', + method: 'cancelar_order', + args: [result], + }).then(function (orders) { + self.pos.gui.show_popup('error', { + message: _t('Venda Cancelada!'), + comment: _t('A venda foi cancelada com sucesso.'), + }); var config_id = self.pos.config.id; self.pos.config.sessao_sat++; rpc.query({ @@ -232,15 +232,49 @@ odoo.define("l10n_br_pos.devices", function (require) { method: 'update_sessao_sat', args: [config_id] }) - }, function (error, event) { - event.preventDefault(); - self.pos.config.sessao_sat++; - self.pos.gui.show_popup('error', { - 'title': _t('Error: Tempo Excedido'), - 'body': _t('Tempo limite de 30 minutos para cancelamento foi excedido.'), - }); - return false; - }); + }); + } else { + var json_orders = JSON.parse(self.pos.export_paid_orders()); + var cancelled_order = null; + for (var index in json_orders.paid_orders) { + if (json_orders.paid_orders[index].data.document_key == order['chaveConsulta']) { + cancelled_order = json_orders.paid_orders[index].data; + } + } + if (cancelled_order) { + cancelled_order.cancel_document_session_number = result['numSessao']; + cancelled_order.cancel_document_key = result['chave_cfe']; + cancelled_order.cancel_document_file = result['xml']; + var json_as_str = JSON.stringify(json_orders); + self.pos.import_orders(json_as_str); + + var config_id = self.pos.config.id; + self.pos.config.sessao_sat++; + rpc.query({ + model: 'pos.config', + method: 'update_sessao_sat', + args: [config_id] + }) + } else { + rpc.query({ + model: 'pos.order', + method: 'cancelar_order', + args: [result], + }).then(function (orders) { + self.pos.gui.show_popup('error', { + message: _t('Venda Cancelada!'), + comment: _t('A venda foi cancelada com sucesso.'), + }); + var config_id = self.pos.config.id; + self.pos.config.sessao_sat++; + rpc.query({ + model: 'pos.config', + method: 'update_sessao_sat', + args: [config_id] + }) + }); + } + } } else { self.pos.gui.show_popup('error', { 'tittle': _t('Erro SAT: '), diff --git a/l10n_br_pos/static/src/js/models.js b/l10n_br_pos/static/src/js/models.js index 9e2505658f93..463755737a97 100644 --- a/l10n_br_pos/static/src/js/models.js +++ b/l10n_br_pos/static/src/js/models.js @@ -93,6 +93,9 @@ odoo.define("l10n_br_pos.models", function (require) { this.document_session_number = this.document_session_number || null; this.document_key = this.document_key || null; this.document_file = this.document_file || null; + this.cancel_document_session_number = this.cancel_document_session_number || null; + this.cancel_document_key = this.cancel_document_key || null; + this.cancel_document_file = this.cancel_document_file || null; if (options.json) { this.init_from_JSON(options.json); @@ -369,9 +372,6 @@ odoo.define("l10n_br_pos.models", function (require) { } return null; }, - _refund_order: function(order, retorno_sat) { - - }, }); var _config = _.findWhere(models.PosModel.prototype.models, {model: "pos.config"}); From af78776b5dc4683c757a6d7d3e397aca8c8640c8 Mon Sep 17 00:00:00 2001 From: Luiz Felipe do Divino Date: Thu, 24 Feb 2022 16:46:40 -0300 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]=20Valida=C3=A7=C3=A3o=20da=20conex?= =?UTF-8?q?=C3=A3o=20com=20o=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n_br_pos/models/pos_order.py | 2 +- l10n_br_pos/static/src/js/devices.js | 2 +- l10n_br_pos/static/src/js/screens.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/l10n_br_pos/models/pos_order.py b/l10n_br_pos/models/pos_order.py index 6fdf4e788b0b..aecdba07e7d5 100644 --- a/l10n_br_pos/models/pos_order.py +++ b/l10n_br_pos/models/pos_order.py @@ -466,7 +466,7 @@ def _refund_cancelled_order(self, order): mail_create_nolog=True, tracking_disable=True, mail_create_nosubscribe=True, mail_notrack=True ).refund() - order.state = 'cancel' + order.action_pos_order_cancel() # # @api.one diff --git a/l10n_br_pos/static/src/js/devices.js b/l10n_br_pos/static/src/js/devices.js index be78bbc96cf7..44ccc8e1a933 100644 --- a/l10n_br_pos/static/src/js/devices.js +++ b/l10n_br_pos/static/src/js/devices.js @@ -215,7 +215,7 @@ odoo.define("l10n_br_pos.devices", function (require) { .then(function (retorno_sat) { let result = retorno_sat; if (result && typeof result === 'object') { - if ($('.js_synch .js_connected').hasClass('.hidden')) { + if (self.pos.get("synch").state == 'connected') { rpc.query({ model: 'pos.order', method: 'cancelar_order', diff --git a/l10n_br_pos/static/src/js/screens.js b/l10n_br_pos/static/src/js/screens.js index 2d2400430891..ad0c9c4e5944 100644 --- a/l10n_br_pos/static/src/js/screens.js +++ b/l10n_br_pos/static/src/js/screens.js @@ -206,7 +206,6 @@ odoo.define("l10n_br_pos.screens", function (require) { }, }); -==== BASE ==== // Screens.PaymentScreenWidget = screens.PaymentScreenWidget.extend({ // order_is_valid: function (parent, options) { // var res = PaymentScreenWidgetSuper.prototype.order_is_valid.call(this, parent, options);