[FIX] point_of_sale: correctly add Global Discount with fiscal position

Previously, it was not possible to apply the Global Discount in cases
where there was a fiscal position with tax included in the price. This
was because of using in the `get_taxes` function, which do not return
taxes after fiscal position.

opw-3267243

closes odoo/odoo#123612

X-original-commit: cb5a1eae7502c140fed09a9471f4d5a97429df74
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Pedram Bi Ria (pebr) <pebr@odoo.com>
This commit is contained in:
pedrambiria
2023-06-05 11:49:58 +02:00
parent ea35602ff2
commit ae17a588a7
+19 -4
View File
@@ -2392,9 +2392,13 @@ export class Orderline extends PosModel {
* @returns {Number} the total amount of price included taxes
*/
get_total_taxes_included_in_price() {
return this.get_taxes()
.filter((tax) => tax.price_include)
.reduce((sum, tax) => sum + this.get_tax_details()[tax.id], 0);
const productTaxes = this._getProductTaxesAfterFiscalPosition();
const taxDetails = this.get_tax_details();
return productTaxes
.filter(tax => tax.price_include)
.reduce((sum, tax) => sum + taxDetails[tax.id],
0
);
}
_map_tax_fiscal_position(tax, order = false) {
return this.pos._map_tax_fiscal_position(tax, order);
@@ -2421,6 +2425,17 @@ export class Orderline extends PosModel {
handle_price_include
);
}
/**
* Calculates the taxes for a product, and converts the taxes based on the fiscal position of the order.
*
* @returns {Object} The calculated product taxes after filtering and fiscal position conversion.
*/
_getProductTaxesAfterFiscalPosition() {
const product = this.get_product();
let taxesIds = this.tax_ids || product.taxes_id;
taxesIds = _.filter(taxesIds, t => t in this.pos.taxes_by_id);
return this.pos.get_taxes_after_fp(taxesIds, this.order.fiscal_position);
}
get_all_prices(qty = this.get_quantity()) {
var price_unit = this.get_unit_price() * (1.0 - this.get_discount() / 100.0);
var taxtotal = 0;
@@ -3291,7 +3306,7 @@ export class Order extends PosModel {
}
_get_tax_group_key(line) {
return line
.get_taxes()
._getProductTaxesAfterFiscalPosition()
.map((tax) => tax.id)
.join(",");
}