Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nuke/parameters.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "./build.schema.json",
"Solution": "VirtoCommerce.OrdersModule.sln"
}
}
41 changes: 41 additions & 0 deletions src/VirtoCommerce.OrdersModule.Core/Model/CustomerOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,47 @@ public virtual void ReduceDetails(string responseGroup)

}

public virtual void RestoreDetails(CustomerOrder order)
{
TaxPercentRate = order.TaxPercentRate;
ShippingTotalWithTax = order.ShippingTotalWithTax;
PaymentTotalWithTax = order.PaymentTotalWithTax;
DiscountAmount = order.DiscountAmount;
Total = order.Total;
SubTotal = order.SubTotal;
SubTotalWithTax = order.SubTotalWithTax;
ShippingTotal = order.ShippingTotal;
PaymentTotal = order.PaymentTotal;
DiscountTotal = order.DiscountTotal;
DiscountTotalWithTax = order.DiscountTotalWithTax;
TaxTotal = order.TaxTotal;
Sum = order.Sum;
Fee = order.Fee;
FeeTotalWithTax = order.FeeTotalWithTax;
FeeTotal = order.FeeTotal;
FeeWithTax = order.FeeWithTax;
HandlingTotal = order.HandlingTotal;
HandlingTotalWithTax = order.HandlingTotalWithTax;

foreach (var shipment in order.Shipments ?? Array.Empty<Shipment>())
{
var targetShipment = Shipments?.FirstOrDefault(x => x.Id == shipment.Id);
targetShipment?.RestoreDetails(shipment);
}

foreach (var payment in order.InPayments ?? Array.Empty<PaymentIn>())
{
var targetPayment = InPayments?.FirstOrDefault(x => x.Id == payment.Id);
targetPayment?.RestoreDetails(payment);
}

foreach (var item in order.Items ?? Array.Empty<LineItem>())
{
var targetItem = Items?.FirstOrDefault(x => x.Id == item.Id);
targetItem?.RestoreDetails(item);
}
}

#region ICloneable members

public override object Clone()
Expand Down
11 changes: 11 additions & 0 deletions src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public virtual void ReduceDetails(string responseGroup)
{
Discounts = null;
}

if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithPrices))
{
Price = 0m;
Expand All @@ -172,6 +173,16 @@ public virtual void ReduceDetails(string responseGroup)
}
}

public virtual void RestoreDetails(LineItem item)
{
Price = item.Price;
PriceWithTax = item.PriceWithTax;
DiscountAmount = item.DiscountAmount;
DiscountAmountWithTax = item.DiscountAmountWithTax;
TaxTotal = item.TaxTotal;
TaxPercentRate = item.TaxPercentRate;
}

#region ICloneable members

public virtual object Clone()
Expand Down
15 changes: 14 additions & 1 deletion src/VirtoCommerce.OrdersModule.Core/Model/PaymentIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public virtual void ReduceDetails(string responseGroup)
}
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithPrices))
{

Price = 0m;
PriceWithTax = 0m;
DiscountAmount = 0m;
Expand All @@ -124,6 +123,20 @@ public virtual void ReduceDetails(string responseGroup)

}

public virtual void RestoreDetails(PaymentIn payment)
{
Price = payment.Price;
PriceWithTax = payment.PriceWithTax;
DiscountAmount = payment.DiscountAmount;
DiscountAmountWithTax = payment.DiscountAmountWithTax;
Total = payment.Total;
TotalWithTax = payment.TotalWithTax;
TaxTotal = payment.TaxTotal;
TaxPercentRate = payment.TaxPercentRate;
Sum = payment.Sum;
}


#region ICloneable members

public override object Clone()
Expand Down
13 changes: 13 additions & 0 deletions src/VirtoCommerce.OrdersModule.Core/Model/Shipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ public virtual void ReduceDetails(string responseGroup)

}

public virtual void RestoreDetails(Shipment shipment)
{
Price = shipment.Price;
PriceWithTax = shipment.PriceWithTax;
DiscountAmount = shipment.DiscountAmount;
DiscountAmountWithTax = shipment.DiscountAmountWithTax;
Total = shipment.Total;
TotalWithTax = shipment.TotalWithTax;
TaxTotal = shipment.TaxTotal;
TaxPercentRate = shipment.TaxPercentRate;
Sum = shipment.Sum;
}

#region ICloneable members

public override object Clone()
Expand Down
47 changes: 20 additions & 27 deletions src/VirtoCommerce.OrdersModule.Data/Model/CustomerOrderEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,33 +346,26 @@ public override void Patch(OperationEntity target)
operation.LanguageCode = LanguageCode;
operation.IsAnonymous = IsAnonymous;

// Checks whether calculation of sum is needed to pass the result to the property of base class before calling of base.Patch
var needPatchPrices = !(GetNonCalculatablePrices().All(x => x == 0m) &&
operation.GetNonCalculatablePrices().Any(x => x != 0m));

if (needPatchPrices)
{
operation.Total = Total;
operation.SubTotal = SubTotal;
operation.SubTotalWithTax = SubTotalWithTax;
operation.ShippingTotal = ShippingTotal;
operation.ShippingTotalWithTax = ShippingTotalWithTax;
operation.PaymentTotal = PaymentTotal;
operation.PaymentTotalWithTax = PaymentTotalWithTax;
operation.HandlingTotal = HandlingTotal;
operation.HandlingTotalWithTax = HandlingTotalWithTax;
operation.DiscountTotal = DiscountTotal;
operation.DiscountTotalWithTax = DiscountTotalWithTax;
operation.DiscountAmount = DiscountAmount;
operation.TaxTotal = TaxTotal;
operation.TaxPercentRate = TaxPercentRate;
operation.Fee = Fee;
operation.FeeWithTax = FeeWithTax;
operation.FeeTotal = FeeTotal;
operation.FeeTotalWithTax = FeeTotalWithTax;
operation.HandlingTotal = HandlingTotal;
operation.HandlingTotalWithTax = HandlingTotalWithTax;
}
operation.Total = Total;
operation.SubTotal = SubTotal;
operation.SubTotalWithTax = SubTotalWithTax;
operation.ShippingTotal = ShippingTotal;
operation.ShippingTotalWithTax = ShippingTotalWithTax;
operation.PaymentTotal = PaymentTotal;
operation.PaymentTotalWithTax = PaymentTotalWithTax;
operation.HandlingTotal = HandlingTotal;
operation.HandlingTotalWithTax = HandlingTotalWithTax;
operation.DiscountTotal = DiscountTotal;
operation.DiscountTotalWithTax = DiscountTotalWithTax;
operation.DiscountAmount = DiscountAmount;
operation.TaxTotal = TaxTotal;
operation.TaxPercentRate = TaxPercentRate;
operation.Fee = Fee;
operation.FeeWithTax = FeeWithTax;
operation.FeeTotal = FeeTotal;
operation.FeeTotalWithTax = FeeTotalWithTax;
operation.HandlingTotal = HandlingTotal;
operation.HandlingTotalWithTax = HandlingTotalWithTax;

if (!Addresses.IsNullCollection())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;

namespace VirtoCommerce.OrdersModule.Data.Model
{
[Obsolete("This interface is deprecated and will be removed in future versions.", DiagnosticId = "VC0011", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")]
public interface ISupportPartialPriceUpdate
{
void ResetPrices();
Expand Down
22 changes: 8 additions & 14 deletions src/VirtoCommerce.OrdersModule.Data/Model/LineItemEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,14 @@ public virtual void Patch(LineItemEntity target)
target.IsConfigured = IsConfigured;
target.IsDiscountAmountRounded = IsDiscountAmountRounded;

// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || target.GetNonCalculatablePrices().All(x => x == 0m);

if (isNeedPatch)
{
target.TaxPercentRate = TaxPercentRate;
target.Price = Price;
target.DiscountAmount = DiscountAmount;
target.PriceWithTax = PriceWithTax;
target.DiscountAmountWithTax = DiscountAmountWithTax;
target.TaxTotal = TaxTotal;
target.Fee = Fee;
target.FeeWithTax = FeeWithTax;
}
target.TaxPercentRate = TaxPercentRate;
target.Price = Price;
target.DiscountAmount = DiscountAmount;
target.PriceWithTax = PriceWithTax;
target.DiscountAmountWithTax = DiscountAmountWithTax;
target.TaxTotal = TaxTotal;
target.Fee = Fee;
target.FeeWithTax = FeeWithTax;

if (!Discounts.IsNullCollection())
{
Expand Down
26 changes: 9 additions & 17 deletions src/VirtoCommerce.OrdersModule.Data/Model/PaymentInEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ public override void Patch(OperationEntity target)
if (payment == null)
throw new ArgumentException(@"target argument must be of type PaymentInEntity", nameof(target));

// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || payment.GetNonCalculatablePrices().All(x => x == 0m);

NeedPatchSum = isNeedPatch;
base.Patch(payment);

payment.TaxType = TaxType;
Expand All @@ -291,19 +287,15 @@ public override void Patch(OperationEntity target)
payment.CancelReason = CancelReason;
payment.VendorId = VendorId;

if (isNeedPatch)
{
payment.Price = Price;
payment.PriceWithTax = PriceWithTax;
payment.DiscountAmount = DiscountAmount;
payment.DiscountAmountWithTax = DiscountAmountWithTax;
payment.TaxPercentRate = TaxPercentRate;
payment.TaxTotal = TaxTotal;
payment.Total = Total;
payment.TotalWithTax = TotalWithTax;
payment.Sum = Sum;
}

payment.Price = Price;
payment.PriceWithTax = PriceWithTax;
payment.DiscountAmount = DiscountAmount;
payment.DiscountAmountWithTax = DiscountAmountWithTax;
payment.TaxPercentRate = TaxPercentRate;
payment.TaxTotal = TaxTotal;
payment.Total = Total;
payment.TotalWithTax = TotalWithTax;
payment.Sum = Sum;

if (!Addresses.IsNullCollection())
{
Expand Down
27 changes: 10 additions & 17 deletions src/VirtoCommerce.OrdersModule.Data/Model/ShipmentEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ public override void Patch(OperationEntity target)
throw new ArgumentException(@"operation argument must be of type ShipmentEntity", nameof(target));
}

// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || shipmentEntity.GetNonCalculatablePrices().All(x => x == 0m);

NeedPatchSum = isNeedPatch;
base.Patch(target);

shipmentEntity.FulfillmentCenterId = FulfillmentCenterId;
Expand All @@ -321,19 +317,16 @@ public override void Patch(OperationEntity target)
shipmentEntity.VendorId = VendorId;
shipmentEntity.PickupLocationId = PickupLocationId;

if (isNeedPatch)
{
shipmentEntity.Price = Price;
shipmentEntity.PriceWithTax = PriceWithTax;
shipmentEntity.DiscountAmount = DiscountAmount;
shipmentEntity.DiscountAmountWithTax = DiscountAmountWithTax;
shipmentEntity.TaxPercentRate = TaxPercentRate;
shipmentEntity.TaxTotal = TaxTotal;
shipmentEntity.Total = Total;
shipmentEntity.TotalWithTax = TotalWithTax;
shipmentEntity.Fee = Fee;
shipmentEntity.FeeWithTax = FeeWithTax;
}
shipmentEntity.Price = Price;
shipmentEntity.PriceWithTax = PriceWithTax;
shipmentEntity.DiscountAmount = DiscountAmount;
shipmentEntity.DiscountAmountWithTax = DiscountAmountWithTax;
shipmentEntity.TaxPercentRate = TaxPercentRate;
shipmentEntity.TaxTotal = TaxTotal;
shipmentEntity.Total = Total;
shipmentEntity.TotalWithTax = TotalWithTax;
shipmentEntity.Fee = Fee;
shipmentEntity.FeeWithTax = FeeWithTax;

if (!InPayments.IsNullCollection())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<noWarn>1591</noWarn>
<noWarn>1591,VC0011</noWarn>
<IsPackable>True</IsPackable>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using VirtoCommerce.Platform.Core.ChangeLog;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Json;
using VirtoCommerce.Platform.Core.Security;
using VirtoCommerce.Platform.Core.Settings;
using VirtoCommerce.StoreModule.Core.Model;
using VirtoCommerce.StoreModule.Core.Services;
Expand Down Expand Up @@ -368,6 +369,12 @@ public async Task<ActionResult> UpdateOrder([FromBody] CustomerOrder customerOrd
});
}

if (!User.HasGlobalPermission(ModuleConstants.Security.Permissions.ReadPrices))
{
// Restore prices from order if user has no ReadPrices permission and receive the order without prices
customerOrder.RestoreDetails(order);
}

try
{
await customerOrderService.SaveChangesAsync(new[] { customerOrder });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DinkToPdfCopy" Version="1.0.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.TemplateLoader.FileSystem" Version="3.809.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.TemplateLoader.FileSystem" Version="3.811.0" />
<PackageReference Include="VirtoCommerce.PaymentModule.Data" Version="3.804.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void PatchPrices_Shipment_NotNeeded(decimal sourcePrice, decimal patchedP
sourceOperation.Patch(patchedOperation);

// Assert
patchedOperation.Price.Should().Be(patchedPrice);
patchedOperation.Price.Should().Be(sourcePrice);
}

[Theory]
Expand Down Expand Up @@ -94,7 +94,7 @@ public void PatchPrices_Payment_NotNeeded(decimal sourcePrice, decimal patchedPr
sourceOperation.Patch(patchedOperation);

// Assert
patchedOperation.Price.Should().Be(patchedPrice);
patchedOperation.Price.Should().Be(sourcePrice);
}

[Theory]
Expand Down Expand Up @@ -139,7 +139,7 @@ public void PatchPrices_LineItem_NotNeeded(decimal sourcePrice, decimal patchedP
sourceOperation.Patch(patchedOperation);

// Assert
patchedOperation.Price.Should().Be(patchedPrice);
patchedOperation.Price.Should().Be(sourcePrice);
}
}
}
Loading