Skip to content

Commit

Permalink
Add ListTotal to LineItem
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev committed Dec 10, 2024
1 parent 6d7a511 commit 4d7108a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// Resulting price with discount for one unit
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.CartModule.Core" Version="3.823.0-alpha.717-vcst-2305" />
<PackageReference Include="VirtoCommerce.CartModule.Core" Version="3.823.0-alpha.718-vcst-2305" />
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.813.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.817.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.Core" Version="3.811.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.OrdersModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<platformVersion>3.867.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Cart" version="3.823.0-alpha.717-vcst-2305" />
<dependency id="VirtoCommerce.Cart" version="3.823.0-alpha.718-vcst-2305" />
<dependency id="VirtoCommerce.Catalog" version="3.822.0" />
<dependency id="VirtoCommerce.Core" version="3.813.0" />
<dependency id="VirtoCommerce.Customer" version="3.817.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4d7108a

Please sign in to comment.