From 4d7108acc8569bf2ac4e7f1e5af0b5cdd77b7474 Mon Sep 17 00:00:00 2001 From: Artem Dudarev Date: Tue, 10 Dec 2024 12:42:17 +0200 Subject: [PATCH] Add ListTotal to LineItem --- src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs | 3 +++ .../VirtoCommerce.OrdersModule.Core.csproj | 2 +- .../Services/DefaultCustomerOrderTotalsCalculator.cs | 8 +++++--- src/VirtoCommerce.OrdersModule.Web/module.manifest | 2 +- .../OrderTotalsCalculationTest.cs | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs b/src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs index b0b5c641..e0f30983 100644 --- a/src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs +++ b/src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs @@ -27,6 +27,9 @@ public class LineItem : AuditableEntity, IHasTaxDetalization, ISupportCancellati public virtual decimal PriceWithTax { get; set; } + public decimal ListTotal { get; set; } + public decimal ListTotalWithTax { get; set; } + /// /// Resulting price with discount for one unit /// diff --git a/src/VirtoCommerce.OrdersModule.Core/VirtoCommerce.OrdersModule.Core.csproj b/src/VirtoCommerce.OrdersModule.Core/VirtoCommerce.OrdersModule.Core.csproj index caddc985..46e63e98 100644 --- a/src/VirtoCommerce.OrdersModule.Core/VirtoCommerce.OrdersModule.Core.csproj +++ b/src/VirtoCommerce.OrdersModule.Core/VirtoCommerce.OrdersModule.Core.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/VirtoCommerce.OrdersModule.Data/Services/DefaultCustomerOrderTotalsCalculator.cs b/src/VirtoCommerce.OrdersModule.Data/Services/DefaultCustomerOrderTotalsCalculator.cs index 79630edf..b5c4fd77 100644 --- a/src/VirtoCommerce.OrdersModule.Data/Services/DefaultCustomerOrderTotalsCalculator.cs +++ b/src/VirtoCommerce.OrdersModule.Data/Services/DefaultCustomerOrderTotalsCalculator.cs @@ -70,8 +70,8 @@ public virtual void CalculateTotals(CustomerOrder order) if (order.Items != null) { - order.SubTotal = order.Items.Sum(x => x.Price * x.Quantity); - order.SubTotalWithTax = order.Items.Sum(x => x.PriceWithTax * x.Quantity); + order.SubTotal = order.Items.Sum(x => x.ListTotal); + order.SubTotalWithTax = order.Items.Sum(x => x.ListTotalWithTax); order.SubTotalTaxTotal += order.Items.Sum(x => x.TaxTotal); order.SubTotalDiscount = order.Items.Sum(x => x.DiscountTotal); order.SubTotalDiscountWithTax = order.Items.Sum(x => x.DiscountTotalWithTax); @@ -205,13 +205,15 @@ protected virtual void CalculateLineItemTotals(LineItem lineItem) var quantity = Math.Max(1, lineItem.Quantity); var currency = _currencyService.GetAllCurrenciesAsync().GetAwaiter().GetResult().First(c => c.Code == lineItem.Currency); + lineItem.ListTotal = lineItem.Price * quantity; lineItem.PlacedPrice = lineItem.Price - lineItem.DiscountAmount; lineItem.DiscountTotal = currency.RoundingPolicy.RoundMoney(lineItem.DiscountAmount * quantity, currency); - lineItem.ExtendedPrice = lineItem.Price * quantity - lineItem.DiscountTotal; + lineItem.ExtendedPrice = lineItem.ListTotal - lineItem.DiscountTotal; var taxFactor = 1 + lineItem.TaxPercentRate; lineItem.PriceWithTax = lineItem.Price * taxFactor; + lineItem.ListTotalWithTax = lineItem.ListTotal * taxFactor; lineItem.PlacedPriceWithTax = lineItem.PlacedPrice * taxFactor; lineItem.ExtendedPriceWithTax = lineItem.ExtendedPrice * taxFactor; lineItem.DiscountAmountWithTax = lineItem.DiscountAmount * taxFactor; diff --git a/src/VirtoCommerce.OrdersModule.Web/module.manifest b/src/VirtoCommerce.OrdersModule.Web/module.manifest index 6fa8a55e..9ffcd120 100644 --- a/src/VirtoCommerce.OrdersModule.Web/module.manifest +++ b/src/VirtoCommerce.OrdersModule.Web/module.manifest @@ -6,7 +6,7 @@ 3.867.0 - + diff --git a/tests/VirtoCommerce.OrdersModule.Tests/OrderTotalsCalculationTest.cs b/tests/VirtoCommerce.OrdersModule.Tests/OrderTotalsCalculationTest.cs index eb550931..0e1bbc94 100644 --- a/tests/VirtoCommerce.OrdersModule.Tests/OrderTotalsCalculationTest.cs +++ b/tests/VirtoCommerce.OrdersModule.Tests/OrderTotalsCalculationTest.cs @@ -70,6 +70,7 @@ public void CalculateTotals_LineItemDiscountTotal_MustBeRounded( Assert.Equal(expectedDiscountTotal, cart.DiscountTotal); Assert.Equal(expectedCartTotal, cart.Total); + Assert.Equal(expectedCartSubTotal, lineItem.ListTotal); Assert.Equal(expectedDiscountTotal, lineItem.DiscountTotal); Assert.Equal(expectedCartTotal, lineItem.ExtendedPrice); }