Skip to content

Commit 75b5b52

Browse files
committed
Merge remote-tracking branch 'origin/main' into issue/OCC-121
2 parents 9b39a89 + 88731d9 commit 75b5b52

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/Modules/OrchardCore.Commerce/Handlers/TaxPartAndPricePartHandler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ public override async Task UpdatedAsync(UpdateContentContext context, PricePart
4141
var isGrossPricePresent = taxPart.GrossPrice?.Amount.IsValid == true;
4242
var isTaxRatePresent = taxRate > 0;
4343

44-
if (isGrossPricePresent && isTaxRatePresent)
44+
if (taxRate < 0)
45+
{
46+
_updateModelAccessor.ModelUpdater.ModelState.AddModelError(
47+
nameof(TaxPart.TaxRate),
48+
T["Tax Rate can't be negative."]);
49+
}
50+
else if (isGrossPricePresent)
4551
{
4652
await UpdatePricePartAsync(part.ContentItem, taxPart.GrossPrice.Amount, taxRate);
4753
}
48-
else if (isGrossPricePresent ^ isTaxRatePresent)
54+
else if (isTaxRatePresent)
4955
{
5056
await InvalidateUnevenStateAsync();
5157
}
52-
53-
return;
5458
}
5559

5660
private Task UpdatePricePartAsync(ContentItem contentItem, Amount grossPrice, decimal taxRate)

src/Modules/OrchardCore.Commerce/Services/LocalTaxProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public Task<PromotionAndTaxProviderContext> UpdateAsync(PromotionAndTaxProviderC
4040
public Task<bool> IsApplicableAsync(PromotionAndTaxProviderContext model) =>
4141
ITaxProvider.AllOrNoneAsync(model, items => items
4242
.Select(item => item.Content.ContentItem.As<TaxPart>())
43-
.Count(taxPart => taxPart?.GrossPrice?.Amount.IsValid == true && taxPart.TaxRate.Value > 0));
43+
.Count(taxPart => taxPart?.GrossPrice?.Amount.IsValid == true && taxPart.TaxRate.Value >= 0));
4444
}

src/Modules/OrchardCore.Commerce/Services/TaxRateTaxProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public async Task<PromotionAndTaxProviderContext> UpdateAsync(PromotionAndTaxPro
3636
item.Content.As<TaxPart>()?.ProductTaxCode?.Text,
3737
model.VatNumber,
3838
model.IsCorporation);
39+
40+
if (taxRate <= 0) return item;
41+
3942
var multiplier = (taxRate / 100m) + 1;
4043
return item with { UnitPrice = item.UnitPrice * multiplier };
4144
})
@@ -57,7 +60,7 @@ public Task<bool> IsApplicableAsync(PromotionAndTaxProviderContext model) =>
5760
model.ShippingAddress,
5861
item.Content.As<TaxPart>()?.ProductTaxCode?.Text,
5962
model.VatNumber,
60-
model.IsCorporation) > 0);
63+
model.IsCorporation) >= 0);
6164
});
6265

6366
private static bool IsMatchingOrEmptyPattern(string pattern, string text) =>
@@ -93,6 +96,6 @@ private static decimal MatchTaxRate(
9396
IsMatchingOrEmptyPattern(rate.TaxCode, taxCode);
9497
});
9598

96-
return matchingTaxRate?.TaxRate ?? 0;
99+
return matchingTaxRate == null ? -1 : matchingTaxRate.TaxRate;
97100
}
98101
}

0 commit comments

Comments
 (0)