This fixes the discount_ calculation logic and promotion tax inclusiveness calculation (#12960)

* This fixes the discount_ calculation logic

* This fixes the adjustment to be handled as a subtotal value in every calculation and applies the tax inclusive logic on the promotion value itself

* Added some testcases and revoked some changes to improve testing output

* Fixed a test case based on feedback

* Corrected promotion/admin test cases

* Corrected cart/store test case

* Improved cart/store test cases for more robust promotion testing considering tax inclusion flags

* Remove unnessary changes as adjustments now automatically are subtotals and therefore the tax inclusive flag does not need to be applied again

* Remove adjustments->is_tax_inclusive usage everywhere

* Migration script to remove is_tax_inclusive in cart line item adjustment

* Forgot to adjust one more testcase

* Corrections based on fPolic feedback

* Refactored PR to consider feedback from oliver

* Added more testcases for promotion in cart

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
scherddel
2025-07-31 13:27:43 +02:00
committed by GitHub
parent 75320e744f
commit 1bdf602f1c
11 changed files with 1076 additions and 119 deletions

View File

@@ -103,24 +103,29 @@ function applyPromotionToItems(
? 1
: applicationMethod?.max_quantity!
let lineItemsTotal = MathBN.convert(0)
let lineItemsAmount = MathBN.convert(0)
if (allocation === ApplicationMethodAllocation.ACROSS) {
lineItemsTotal = applicableItems.reduce(
lineItemsAmount = applicableItems.reduce(
(acc, item) =>
MathBN.sub(
MathBN.add(acc, item.subtotal),
MathBN.add(
acc,
promotion.is_tax_inclusive ? item.total : item.subtotal
),
appliedPromotionsMap.get(item.id) ?? 0
),
MathBN.convert(0)
)
if (MathBN.lte(lineItemsTotal, 0)) {
if (MathBN.lte(lineItemsAmount, 0)) {
return computedActions
}
}
for (const item of applicableItems) {
if (MathBN.lte(item.subtotal, 0)) {
if (
MathBN.lte(promotion.is_tax_inclusive ? item.total : item.subtotal, 0)
) {
continue
}
@@ -135,11 +140,12 @@ function applyPromotionToItems(
{
value: promotionValue,
applied_value: appliedPromoValue,
is_tax_inclusive: promotion.is_tax_inclusive,
max_quantity: maxQuantity,
type: applicationMethod?.type!,
allocation,
},
lineItemsTotal
lineItemsAmount
)
if (MathBN.lte(amount, 0)) {