Skip to content

Commit 3deb888

Browse files
committed
Tax rates persisted on order item level to avoid rounding issues (required for Debitoor, Accarda and Payone)
1 parent aae43a3 commit 3deb888

19 files changed

Lines changed: 469 additions & 205 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Feed plugins: product query now paged to reduce memory payload
1616
* #557 Localize MVC validation strings
1717
* Fixed rare bug "The length of the string exceeds the value set on the maxJsonLength property" (Controller: Order, Action: OrderNotesSelect)
1818
* Debitoor: Adding order notes can result in infinite order update event loop with thousands of order notes
19+
* Tax rates persisted on order item level to avoid rounding issues (required for Debitoor, Accarda and Payone)
1920

2021

2122
## SmartStore.NET 2.1.1

src/Libraries/SmartStore.Core/Domain/Orders/Order.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
187187
[DataMember]
188188
public decimal OrderShippingExclTax { get; set; }
189189

190+
/// <summary>
191+
/// Gets or sets the tax rate for order shipping
192+
/// </summary>
193+
[DataMember]
194+
public decimal OrderShippingTaxRate { get; set; }
195+
190196
/// <summary>
191197
/// Gets or sets the payment method additional fee (incl tax)
192198
/// </summary>
@@ -199,6 +205,12 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
199205
[DataMember]
200206
public decimal PaymentMethodAdditionalFeeExclTax { get; set; }
201207

208+
/// <summary>
209+
/// Gets or sets the tax rate for payment method additional fee
210+
/// </summary>
211+
[DataMember]
212+
public decimal PaymentMethodAdditionalFeeTaxRate { get; set; }
213+
202214
/// <summary>
203215
/// Gets or sets the tax rates
204216
/// </summary>

src/Libraries/SmartStore.Core/Domain/Orders/OrderItem.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public partial class OrderItem : BaseEntity
6161
[DataMember]
6262
public decimal PriceExclTax { get; set; }
6363

64+
/// <summary>
65+
/// Gets or sets the tax rate
66+
/// </summary>
67+
[DataMember]
68+
public decimal TaxRate { get; set; }
69+
6470
/// <summary>
6571
/// Gets or sets the discount amount (incl tax)
6672
/// </summary>

src/Libraries/SmartStore.Core/Extensions/DecimalExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ public static string FormatInvariant(this decimal value, int decimals = 2)
2121
/// </summary>
2222
/// <param name="inclTax">Gross value</param>
2323
/// <param name="exclTax">Net value</param>
24+
/// <param name="decimals">Rounding decimal number</param>
2425
/// <returns>Tax percentage</returns>
25-
public static decimal ToTaxPercentage(this decimal inclTax, decimal exclTax)
26+
public static decimal ToTaxPercentage(this decimal inclTax, decimal exclTax, int? decimals = null)
2627
{
2728
if (exclTax == decimal.Zero)
2829
return decimal.Zero;
2930

30-
return ((inclTax / exclTax) - 1.0M) * 100.0M;
31+
var result = ((inclTax / exclTax) - 1.0M) * 100.0M;
32+
33+
return (decimals.HasValue ? Math.Round(result, decimals.Value) : result);
3134
}
3235

3336
/// <summary>

src/Libraries/SmartStore.Data/Mapping/Orders/OrderItemMap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public OrderItemMap()
1717
this.Property(orderItem => orderItem.UnitPriceExclTax).HasPrecision(18, 4);
1818
this.Property(orderItem => orderItem.PriceInclTax).HasPrecision(18, 4);
1919
this.Property(orderItem => orderItem.PriceExclTax).HasPrecision(18, 4);
20+
this.Property(orderItem => orderItem.TaxRate).HasPrecision(18, 4);
2021
this.Property(orderItem => orderItem.DiscountAmountInclTax).HasPrecision(18, 4);
2122
this.Property(orderItem => orderItem.DiscountAmountExclTax).HasPrecision(18, 4);
2223
this.Property(orderItem => orderItem.ItemWeight).HasPrecision(18, 4);

src/Libraries/SmartStore.Data/Mapping/Orders/OrderMap.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public OrderMap()
1616
this.Property(o => o.OrderSubTotalDiscountExclTax).HasPrecision(18, 4);
1717
this.Property(o => o.OrderShippingInclTax).HasPrecision(18, 4);
1818
this.Property(o => o.OrderShippingExclTax).HasPrecision(18, 4);
19+
this.Property(o => o.OrderShippingTaxRate).HasPrecision(18, 4);
1920
this.Property(o => o.PaymentMethodAdditionalFeeInclTax).HasPrecision(18, 4);
2021
this.Property(o => o.PaymentMethodAdditionalFeeExclTax).HasPrecision(18, 4);
22+
this.Property(o => o.PaymentMethodAdditionalFeeTaxRate).HasPrecision(18, 4);
2123
this.Property(o => o.OrderTax).HasPrecision(18, 4);
2224
this.Property(o => o.OrderDiscount).HasPrecision(18, 4);
2325
this.Property(o => o.OrderTotal).HasPrecision(18, 4);

src/Libraries/SmartStore.Data/Migrations/201501291549546_OrderItemTaxRate.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace SmartStore.Data.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
using SmartStore.Data.Setup;
6+
7+
public partial class OrderItemTaxRate : DbMigration, ILocaleResourcesProvider, IDataSeeder<SmartObjectContext>
8+
{
9+
public override void Up()
10+
{
11+
AddColumn("dbo.Order", "OrderShippingTaxRate", c => c.Decimal(nullable: false, precision: 18, scale: 4));
12+
AddColumn("dbo.Order", "PaymentMethodAdditionalFeeTaxRate", c => c.Decimal(nullable: false, precision: 18, scale: 4));
13+
AddColumn("dbo.OrderItem", "TaxRate", c => c.Decimal(nullable: false, precision: 18, scale: 4));
14+
}
15+
16+
public override void Down()
17+
{
18+
DropColumn("dbo.OrderItem", "TaxRate");
19+
DropColumn("dbo.Order", "PaymentMethodAdditionalFeeTaxRate");
20+
DropColumn("dbo.Order", "OrderShippingTaxRate");
21+
}
22+
23+
public bool RollbackOnFailure
24+
{
25+
get { return false; }
26+
}
27+
28+
public void Seed(SmartObjectContext context)
29+
{
30+
context.MigrateLocaleResources(MigrateLocaleResources);
31+
}
32+
33+
public void MigrateLocaleResources(LocaleResourcesBuilder builder)
34+
{
35+
builder.AddOrUpdate("Admin.Orders.Products.AddNew.TaxRate",
36+
"Tax rate",
37+
"Steuersatz",
38+
"The tax rate for the product",
39+
"Die Steuerrate des Produktes");
40+
}
41+
}
42+
}

src/Libraries/SmartStore.Data/Migrations/201501291549546_OrderItemTaxRate.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/SmartStore.Data/SmartStore.Data.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
<Compile Include="Migrations\201501221417371_DefaultViewModeForCategories.Designer.cs">
216216
<DependentUpon>201501221417371_DefaultViewModeForCategories.cs</DependentUpon>
217217
</Compile>
218+
<Compile Include="Migrations\201501291549546_OrderItemTaxRate.cs" />
219+
<Compile Include="Migrations\201501291549546_OrderItemTaxRate.Designer.cs">
220+
<DependentUpon>201501291549546_OrderItemTaxRate.cs</DependentUpon>
221+
</Compile>
218222
<Compile Include="Setup\Builder\SettingsBuilder.cs" />
219223
<Compile Include="Setup\Builder\SettingsMigrator.cs" />
220224
<Compile Include="Setup\DbMigrationContext.cs" />
@@ -431,6 +435,9 @@
431435
<EmbeddedResource Include="Migrations\201501221417371_DefaultViewModeForCategories.resx">
432436
<DependentUpon>201501221417371_DefaultViewModeForCategories.cs</DependentUpon>
433437
</EmbeddedResource>
438+
<EmbeddedResource Include="Migrations\201501291549546_OrderItemTaxRate.resx">
439+
<DependentUpon>201501291549546_OrderItemTaxRate.cs</DependentUpon>
440+
</EmbeddedResource>
434441
<EmbeddedResource Include="Sql\Indexes.sql" />
435442
<EmbeddedResource Include="Sql\StoredProcedures.sql" />
436443
</ItemGroup>

0 commit comments

Comments
 (0)