[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) <jcb@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2021-11-25 17:53:50 +00:00
parent 15a62b155b
commit 162fadd48e
+12 -5
View File
@@ -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;