summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/models.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/point_of_sale/static/src/js/models.js')
-rw-r--r--addons/point_of_sale/static/src/js/models.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 25fcaf028e5..7a3fa82e252 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -182,7 +182,7 @@ exports.PosModel = Backbone.Model.extend({
},{
model: 'res.company',
fields: [ 'currency_id', 'email', 'website', 'company_registry', 'vat', 'name', 'phone', 'partner_id' , 'country_id', 'state_id', 'tax_calculation_rounding_method'],
- ids: function(self){ return [self.user.company_id[0]]; },
+ ids: function(self){ return [session.user_context.allowed_company_ids[0]]; },
loaded: function(self,companies){ self.company = companies[0]; },
},{
model: 'decimal.precision',
@@ -2608,9 +2608,36 @@ exports.Order = Backbone.Model.extend({
}), 0), this.pos.currency.rounding);
},
get_total_tax: function() {
- return round_pr(this.orderlines.reduce((function(sum, orderLine) {
- return sum + orderLine.get_tax();
- }), 0), this.pos.currency.rounding);
+ if (this.pos.company.tax_calculation_rounding_method === "round_globally") {
+ // As always, we need:
+ // 1. For each tax, sum their amount across all order lines
+ // 2. Round that result
+ // 3. Sum all those rounded amounts
+ var groupTaxes = {};
+ this.orderlines.each(function (line) {
+ var taxDetails = line.get_tax_details();
+ var taxIds = Object.keys(taxDetails);
+ for (var t = 0; t<taxIds.length; t++) {
+ var taxId = taxIds[t];
+ if (!(taxId in groupTaxes)) {
+ groupTaxes[taxId] = 0;
+ }
+ groupTaxes[taxId] += taxDetails[taxId];
+ }
+ });
+
+ var sum = 0;
+ var taxIds = Object.keys(groupTaxes);
+ for (var j = 0; j<taxIds.length; j++) {
+ var taxAmount = groupTaxes[taxIds[j]];
+ sum += round_pr(taxAmount, this.pos.currency.rounding);
+ }
+ return sum;
+ } else {
+ return round_pr(this.orderlines.reduce((function(sum, orderLine) {
+ return sum + orderLine.get_tax();
+ }), 0), this.pos.currency.rounding);
+ }
},
get_total_paid: function() {
return round_pr(this.paymentlines.reduce((function(sum, paymentLine) {