Skip to content

Commit

Permalink
[ADD] Adicionar os dados de cancelamento no pos.order
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdivino committed Feb 24, 2022
1 parent fb46bee commit ab51e3f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 24 deletions.
25 changes: 24 additions & 1 deletion l10n_br_pos/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -430,14 +447,20 @@ 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(
file_name=result['chave_cfe'] + ".xml",
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
Expand Down
74 changes: 54 additions & 20 deletions l10n_br_pos/static/src/js/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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) {
Expand All @@ -203,32 +203,66 @@ 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({
model: 'pos.config',
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: '),
Expand Down
6 changes: 3 additions & 3 deletions l10n_br_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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);
Expand Down Expand Up @@ -349,9 +352,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"});
Expand Down

0 comments on commit ab51e3f

Please sign in to comment.