From 162fadd48ed9dbbcbe1f56ac4be206ce51982174 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Mon, 22 Nov 2021 16:06:08 +0000 Subject: [PATCH] [FIX] point_of_sale : Positive tax for credit note Steps: - Install POS - Create Tax T : - Type : Sales - Computation : Fixed - Amount : x - Create a product P with price 0 - Go to POS and select P to sell it (qty = 1). Taxes = x - Now set qty = -1. Issue: - Taxes remain x where it would be expected to be -x. Cause: - The calculation of the price doesn't take the sign of the qty into account because it takes a "base amount" that takes it into account. - However, this base amount doesn't give any indication about the qty, which is necessary to determine which way the tax should be applied. Fix: - If the "base amount" is zero, return quantity * fixed tax. opw-2655317 closes odoo/odoo#80389 X-original-commit: 6a4f51f4254041229cf264d713f0d2b0db880601 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/static/src/js/models.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 9ff20fbc338..8274e6727b8 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2329,11 +2329,18 @@ exports.Orderline = Backbone.Model.extend({ else var price_include = !price_exclude; if (tax.amount_type === 'fixed') { - var sign_base_amount = Math.sign(base_amount) || 1; - // Since base amount has been computed with quantity - // we take the abs of quantity - // Same logic as bb72dea98de4dae8f59e397f232a0636411d37ce - return tax.amount * sign_base_amount * Math.abs(quantity); + // Use sign on base_amount and abs on quantity to take into account the sign of the base amount, + // which includes the sign of the quantity and the sign of the price_unit + // Amount is the fixed price for the tax, it can be negative + // Base amount included the sign of the quantity and the sign of the unit price and when + // a product is returned, it can be done either by changing the sign of quantity or by changing the + // sign of the price unit. + // When the price unit is equal to 0, the sign of the quantity is absorbed in base_amount then + // a "else" case is needed. + if (base_amount) + return Math.sign(base_amount) * Math.abs(quantity) * tax.amount; + else + return quantity * tax.amount; } if (tax.amount_type === 'percent' && !price_include){ return base_amount * tax.amount / 100;