Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions tko_l10n_br_point_of_sale/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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++) {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; },
});





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ""

});
}
Expand Down Expand Up @@ -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




});


Expand Down