Skip to content

Commit b1aeb78

Browse files
authored
VCST-3736: Explicit taxrate change to 0 is not applied on orders (#462)
1 parent c9a4b3f commit b1aeb78

File tree

14 files changed

+141
-82
lines changed

14 files changed

+141
-82
lines changed

.nuke/parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "./build.schema.json",
33
"Solution": "VirtoCommerce.OrdersModule.sln"
4-
}
4+
}

src/VirtoCommerce.OrdersModule.Core/Model/CustomerOrder.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,47 @@ public virtual void ReduceDetails(string responseGroup)
323323

324324
}
325325

326+
public virtual void RestoreDetails(CustomerOrder order)
327+
{
328+
TaxPercentRate = order.TaxPercentRate;
329+
ShippingTotalWithTax = order.ShippingTotalWithTax;
330+
PaymentTotalWithTax = order.PaymentTotalWithTax;
331+
DiscountAmount = order.DiscountAmount;
332+
Total = order.Total;
333+
SubTotal = order.SubTotal;
334+
SubTotalWithTax = order.SubTotalWithTax;
335+
ShippingTotal = order.ShippingTotal;
336+
PaymentTotal = order.PaymentTotal;
337+
DiscountTotal = order.DiscountTotal;
338+
DiscountTotalWithTax = order.DiscountTotalWithTax;
339+
TaxTotal = order.TaxTotal;
340+
Sum = order.Sum;
341+
Fee = order.Fee;
342+
FeeTotalWithTax = order.FeeTotalWithTax;
343+
FeeTotal = order.FeeTotal;
344+
FeeWithTax = order.FeeWithTax;
345+
HandlingTotal = order.HandlingTotal;
346+
HandlingTotalWithTax = order.HandlingTotalWithTax;
347+
348+
foreach (var shipment in order.Shipments ?? Array.Empty<Shipment>())
349+
{
350+
var targetShipment = Shipments?.FirstOrDefault(x => x.Id == shipment.Id);
351+
targetShipment?.RestoreDetails(shipment);
352+
}
353+
354+
foreach (var payment in order.InPayments ?? Array.Empty<PaymentIn>())
355+
{
356+
var targetPayment = InPayments?.FirstOrDefault(x => x.Id == payment.Id);
357+
targetPayment?.RestoreDetails(payment);
358+
}
359+
360+
foreach (var item in order.Items ?? Array.Empty<LineItem>())
361+
{
362+
var targetItem = Items?.FirstOrDefault(x => x.Id == item.Id);
363+
targetItem?.RestoreDetails(item);
364+
}
365+
}
366+
326367
#region ICloneable members
327368

328369
public override object Clone()

src/VirtoCommerce.OrdersModule.Core/Model/LineItem.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public virtual void ReduceDetails(string responseGroup)
161161
{
162162
Discounts = null;
163163
}
164+
164165
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithPrices))
165166
{
166167
Price = 0m;
@@ -172,6 +173,16 @@ public virtual void ReduceDetails(string responseGroup)
172173
}
173174
}
174175

176+
public virtual void RestoreDetails(LineItem item)
177+
{
178+
Price = item.Price;
179+
PriceWithTax = item.PriceWithTax;
180+
DiscountAmount = item.DiscountAmount;
181+
DiscountAmountWithTax = item.DiscountAmountWithTax;
182+
TaxTotal = item.TaxTotal;
183+
TaxPercentRate = item.TaxPercentRate;
184+
}
185+
175186
#region ICloneable members
176187

177188
public virtual object Clone()

src/VirtoCommerce.OrdersModule.Core/Model/PaymentIn.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public virtual void ReduceDetails(string responseGroup)
110110
}
111111
if (!orderResponseGroup.HasFlag(CustomerOrderResponseGroup.WithPrices))
112112
{
113-
114113
Price = 0m;
115114
PriceWithTax = 0m;
116115
DiscountAmount = 0m;
@@ -124,6 +123,20 @@ public virtual void ReduceDetails(string responseGroup)
124123

125124
}
126125

126+
public virtual void RestoreDetails(PaymentIn payment)
127+
{
128+
Price = payment.Price;
129+
PriceWithTax = payment.PriceWithTax;
130+
DiscountAmount = payment.DiscountAmount;
131+
DiscountAmountWithTax = payment.DiscountAmountWithTax;
132+
Total = payment.Total;
133+
TotalWithTax = payment.TotalWithTax;
134+
TaxTotal = payment.TaxTotal;
135+
TaxPercentRate = payment.TaxPercentRate;
136+
Sum = payment.Sum;
137+
}
138+
139+
127140
#region ICloneable members
128141

129142
public override object Clone()

src/VirtoCommerce.OrdersModule.Core/Model/Shipment.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ public virtual void ReduceDetails(string responseGroup)
141141

142142
}
143143

144+
public virtual void RestoreDetails(Shipment shipment)
145+
{
146+
Price = shipment.Price;
147+
PriceWithTax = shipment.PriceWithTax;
148+
DiscountAmount = shipment.DiscountAmount;
149+
DiscountAmountWithTax = shipment.DiscountAmountWithTax;
150+
Total = shipment.Total;
151+
TotalWithTax = shipment.TotalWithTax;
152+
TaxTotal = shipment.TaxTotal;
153+
TaxPercentRate = shipment.TaxPercentRate;
154+
Sum = shipment.Sum;
155+
}
156+
144157
#region ICloneable members
145158

146159
public override object Clone()

src/VirtoCommerce.OrdersModule.Data/Model/CustomerOrderEntity.cs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,33 +346,26 @@ public override void Patch(OperationEntity target)
346346
operation.LanguageCode = LanguageCode;
347347
operation.IsAnonymous = IsAnonymous;
348348

349-
// Checks whether calculation of sum is needed to pass the result to the property of base class before calling of base.Patch
350-
var needPatchPrices = !(GetNonCalculatablePrices().All(x => x == 0m) &&
351-
operation.GetNonCalculatablePrices().Any(x => x != 0m));
352-
353-
if (needPatchPrices)
354-
{
355-
operation.Total = Total;
356-
operation.SubTotal = SubTotal;
357-
operation.SubTotalWithTax = SubTotalWithTax;
358-
operation.ShippingTotal = ShippingTotal;
359-
operation.ShippingTotalWithTax = ShippingTotalWithTax;
360-
operation.PaymentTotal = PaymentTotal;
361-
operation.PaymentTotalWithTax = PaymentTotalWithTax;
362-
operation.HandlingTotal = HandlingTotal;
363-
operation.HandlingTotalWithTax = HandlingTotalWithTax;
364-
operation.DiscountTotal = DiscountTotal;
365-
operation.DiscountTotalWithTax = DiscountTotalWithTax;
366-
operation.DiscountAmount = DiscountAmount;
367-
operation.TaxTotal = TaxTotal;
368-
operation.TaxPercentRate = TaxPercentRate;
369-
operation.Fee = Fee;
370-
operation.FeeWithTax = FeeWithTax;
371-
operation.FeeTotal = FeeTotal;
372-
operation.FeeTotalWithTax = FeeTotalWithTax;
373-
operation.HandlingTotal = HandlingTotal;
374-
operation.HandlingTotalWithTax = HandlingTotalWithTax;
375-
}
349+
operation.Total = Total;
350+
operation.SubTotal = SubTotal;
351+
operation.SubTotalWithTax = SubTotalWithTax;
352+
operation.ShippingTotal = ShippingTotal;
353+
operation.ShippingTotalWithTax = ShippingTotalWithTax;
354+
operation.PaymentTotal = PaymentTotal;
355+
operation.PaymentTotalWithTax = PaymentTotalWithTax;
356+
operation.HandlingTotal = HandlingTotal;
357+
operation.HandlingTotalWithTax = HandlingTotalWithTax;
358+
operation.DiscountTotal = DiscountTotal;
359+
operation.DiscountTotalWithTax = DiscountTotalWithTax;
360+
operation.DiscountAmount = DiscountAmount;
361+
operation.TaxTotal = TaxTotal;
362+
operation.TaxPercentRate = TaxPercentRate;
363+
operation.Fee = Fee;
364+
operation.FeeWithTax = FeeWithTax;
365+
operation.FeeTotal = FeeTotal;
366+
operation.FeeTotalWithTax = FeeTotalWithTax;
367+
operation.HandlingTotal = HandlingTotal;
368+
operation.HandlingTotalWithTax = HandlingTotalWithTax;
376369

377370
if (!Addresses.IsNullCollection())
378371
{

src/VirtoCommerce.OrdersModule.Data/Model/ISupportPartialPriceUpdate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace VirtoCommerce.OrdersModule.Data.Model
45
{
6+
[Obsolete("This interface is deprecated and will be removed in future versions.", DiagnosticId = "VC0011", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions/")]
57
public interface ISupportPartialPriceUpdate
68
{
79
void ResetPrices();

src/VirtoCommerce.OrdersModule.Data/Model/LineItemEntity.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,14 @@ public virtual void Patch(LineItemEntity target)
317317
target.IsConfigured = IsConfigured;
318318
target.IsDiscountAmountRounded = IsDiscountAmountRounded;
319319

320-
// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
321-
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || target.GetNonCalculatablePrices().All(x => x == 0m);
322-
323-
if (isNeedPatch)
324-
{
325-
target.TaxPercentRate = TaxPercentRate;
326-
target.Price = Price;
327-
target.DiscountAmount = DiscountAmount;
328-
target.PriceWithTax = PriceWithTax;
329-
target.DiscountAmountWithTax = DiscountAmountWithTax;
330-
target.TaxTotal = TaxTotal;
331-
target.Fee = Fee;
332-
target.FeeWithTax = FeeWithTax;
333-
}
320+
target.TaxPercentRate = TaxPercentRate;
321+
target.Price = Price;
322+
target.DiscountAmount = DiscountAmount;
323+
target.PriceWithTax = PriceWithTax;
324+
target.DiscountAmountWithTax = DiscountAmountWithTax;
325+
target.TaxTotal = TaxTotal;
326+
target.Fee = Fee;
327+
target.FeeWithTax = FeeWithTax;
334328

335329
if (!Discounts.IsNullCollection())
336330
{

src/VirtoCommerce.OrdersModule.Data/Model/PaymentInEntity.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ public override void Patch(OperationEntity target)
268268
if (payment == null)
269269
throw new ArgumentException(@"target argument must be of type PaymentInEntity", nameof(target));
270270

271-
// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
272-
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || payment.GetNonCalculatablePrices().All(x => x == 0m);
273-
274-
NeedPatchSum = isNeedPatch;
275271
base.Patch(payment);
276272

277273
payment.TaxType = TaxType;
@@ -291,19 +287,15 @@ public override void Patch(OperationEntity target)
291287
payment.CancelReason = CancelReason;
292288
payment.VendorId = VendorId;
293289

294-
if (isNeedPatch)
295-
{
296-
payment.Price = Price;
297-
payment.PriceWithTax = PriceWithTax;
298-
payment.DiscountAmount = DiscountAmount;
299-
payment.DiscountAmountWithTax = DiscountAmountWithTax;
300-
payment.TaxPercentRate = TaxPercentRate;
301-
payment.TaxTotal = TaxTotal;
302-
payment.Total = Total;
303-
payment.TotalWithTax = TotalWithTax;
304-
payment.Sum = Sum;
305-
}
306-
290+
payment.Price = Price;
291+
payment.PriceWithTax = PriceWithTax;
292+
payment.DiscountAmount = DiscountAmount;
293+
payment.DiscountAmountWithTax = DiscountAmountWithTax;
294+
payment.TaxPercentRate = TaxPercentRate;
295+
payment.TaxTotal = TaxTotal;
296+
payment.Total = Total;
297+
payment.TotalWithTax = TotalWithTax;
298+
payment.Sum = Sum;
307299

308300
if (!Addresses.IsNullCollection())
309301
{

src/VirtoCommerce.OrdersModule.Data/Model/ShipmentEntity.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ public override void Patch(OperationEntity target)
292292
throw new ArgumentException(@"operation argument must be of type ShipmentEntity", nameof(target));
293293
}
294294

295-
// Patch prices if there are non 0 prices in the patching entity, or all patched entity prices are 0
296-
var isNeedPatch = GetNonCalculatablePrices().Any(x => x != 0m) || shipmentEntity.GetNonCalculatablePrices().All(x => x == 0m);
297-
298-
NeedPatchSum = isNeedPatch;
299295
base.Patch(target);
300296

301297
shipmentEntity.FulfillmentCenterId = FulfillmentCenterId;
@@ -321,19 +317,16 @@ public override void Patch(OperationEntity target)
321317
shipmentEntity.VendorId = VendorId;
322318
shipmentEntity.PickupLocationId = PickupLocationId;
323319

324-
if (isNeedPatch)
325-
{
326-
shipmentEntity.Price = Price;
327-
shipmentEntity.PriceWithTax = PriceWithTax;
328-
shipmentEntity.DiscountAmount = DiscountAmount;
329-
shipmentEntity.DiscountAmountWithTax = DiscountAmountWithTax;
330-
shipmentEntity.TaxPercentRate = TaxPercentRate;
331-
shipmentEntity.TaxTotal = TaxTotal;
332-
shipmentEntity.Total = Total;
333-
shipmentEntity.TotalWithTax = TotalWithTax;
334-
shipmentEntity.Fee = Fee;
335-
shipmentEntity.FeeWithTax = FeeWithTax;
336-
}
320+
shipmentEntity.Price = Price;
321+
shipmentEntity.PriceWithTax = PriceWithTax;
322+
shipmentEntity.DiscountAmount = DiscountAmount;
323+
shipmentEntity.DiscountAmountWithTax = DiscountAmountWithTax;
324+
shipmentEntity.TaxPercentRate = TaxPercentRate;
325+
shipmentEntity.TaxTotal = TaxTotal;
326+
shipmentEntity.Total = Total;
327+
shipmentEntity.TotalWithTax = TotalWithTax;
328+
shipmentEntity.Fee = Fee;
329+
shipmentEntity.FeeWithTax = FeeWithTax;
337330

338331
if (!InPayments.IsNullCollection())
339332
{

0 commit comments

Comments
 (0)