From b51ff07c23625d12e6927c5cfc9c487f87ce0245 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Tue, 27 Aug 2019 14:16:03 +0000 Subject: [PATCH] [FIX] point_of_sale: apply tax repartition lines on amount Since implementation of repartition lines on tax in accounting, the amount on the tax is not always the effective amount to apply on price of a product. You can have a tax with amount of 20% for example, and two repartition lines of 100% and -100%, that will lead to have to apply 0% on the tax. So we are computing the effective amount on the tax by multiplying the amount of tax by the sum of repartition lines factor. closes odoo/odoo#36140 Signed-off-by: Laurent Smet --- addons/point_of_sale/models/account_tax.py | 9 +++++++++ addons/point_of_sale/static/src/js/models.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/addons/point_of_sale/models/account_tax.py b/addons/point_of_sale/models/account_tax.py index 48a7ecbe0c6..37cf71324e1 100644 --- a/addons/point_of_sale/models/account_tax.py +++ b/addons/point_of_sale/models/account_tax.py @@ -25,3 +25,12 @@ class AccountTax(models.Model): 'You must close the POS sessions before modifying the tax.' )) return super(AccountTax, self).write(vals) + + def get_real_tax_amount(self): + tax_list = [] + for tax in self: + tax_repartition_lines = tax.invoice_repartition_line_ids.filtered(lambda x: x.repartition_type == 'tax') + total_factor = sum(tax_repartition_lines.mapped('factor')) + real_amount = tax.amount * total_factor + tax_list.append({'id': tax.id, 'amount': real_amount}) + return tax_list diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index fbeddf38ed5..5e681776730 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -242,6 +242,19 @@ exports.PosModel = Backbone.Model.extend({ return self.taxes_by_id[child_tax_id]; }); }); + return new Promise(function (resolve, reject) { + var tax_ids = _.pluck(self.taxes, 'id'); + rpc.query({ + model: 'account.tax', + method: 'get_real_tax_amount', + args: [tax_ids], + }).then(function (taxes) { + _.each(taxes, function (tax) { + self.taxes_by_id[tax.id].amount = tax.amount; + resolve(); + }); + }); + }); }, },{ model: 'pos.session',