From e6b9be54c992ccfabd3d7a26ae68a86f108a86e6 Mon Sep 17 00:00:00 2001 From: Filip Kuksov Date: Thu, 5 Aug 2021 11:28:21 +0200 Subject: [PATCH 1/3] 3.21.0 --- Directory.Build.props | 2 +- src/VirtoCommerce.CoreModule.Web/module.manifest | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3715c229..cbe2fff2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 3.20.0 + 3.21.0 $(VersionSuffix)-$(BuildNumber) diff --git a/src/VirtoCommerce.CoreModule.Web/module.manifest b/src/VirtoCommerce.CoreModule.Web/module.manifest index b12197c0..b436f8e4 100644 --- a/src/VirtoCommerce.CoreModule.Web/module.manifest +++ b/src/VirtoCommerce.CoreModule.Web/module.manifest @@ -1,7 +1,7 @@  VirtoCommerce.Core - 3.20.0 + 3.21.0 3.66.0 Commerce core module From 2fb6baa24b9957c6f9f908226eb39b9e83ef4059 Mon Sep 17 00:00:00 2001 From: vc-ci Date: Thu, 19 Aug 2021 13:58:00 +0000 Subject: [PATCH 2/3] Updating Github Action workflows. --- .github/workflows/main.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 036cdef7..daad3767 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,11 +38,6 @@ jobs: with: java-version: 1.11 - - name: Set up .net Core 3.1.x for vc-build #GitHib Actions migrates to .net Core 5.x. To vc-build work properly need to manually install .net Core 3.1.x - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '3.1.x' - - uses: actions/checkout@v2 with: fetch-depth: 0 From 3f299be82dd7c56699e08989469001d5340e7f39 Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Tue, 24 Aug 2021 08:25:05 +0200 Subject: [PATCH 3/3] PT-1924: Fix Rounding policy (#191) * PT-1924: Increase the length of MidpointRounding to 18 * PT-1924: Fix rounding for Rounding01 up and down types * PT-1924: Update docs --- docs/How-to override rounding policy.md | 21 +++ .../Currency/DefaultMoneyRoundingPolicy.cs | 8 +- .../Currency/CurrencyEntity.cs | 2 +- ...64242_ExtendedMidpointRounding.Designer.cs | 139 ++++++++++++++++++ ...20210819064242_ExtendedMidpointRounding.cs | 33 +++++ .../Migrations/CoreDbContextModelSnapshot.cs | 4 +- .../DefaultMoneyRoundingPolicyTests.cs | 3 + 7 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 docs/How-to override rounding policy.md create mode 100644 src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.Designer.cs create mode 100644 src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.cs diff --git a/docs/How-to override rounding policy.md b/docs/How-to override rounding policy.md new file mode 100644 index 00000000..2973bf1e --- /dev/null +++ b/docs/How-to override rounding policy.md @@ -0,0 +1,21 @@ +# How-to extend rounding policy +## 1. Implement the intefrace VirtoCommerce.CoreModule.Core.Currency.IMoneyRoundingPolicy +```csharp +public class CustomMoneyRoundingPolicy : IMoneyRoundingPolicy +{ + public decimal RoundMoney(decimal amount, Currency currency) + { + // Some rounding logic + } +} +``` +## 2. Register it with the DI container in Module.cs +```csharp +public void Initialize(IServiceCollection serviceCollection) +{ + ... + + // Money rounding + serviceCollection.AddTransient(); +} +``` diff --git a/src/VirtoCommerce.CoreModule.Core/Currency/DefaultMoneyRoundingPolicy.cs b/src/VirtoCommerce.CoreModule.Core/Currency/DefaultMoneyRoundingPolicy.cs index b01de3ff..14d30517 100644 --- a/src/VirtoCommerce.CoreModule.Core/Currency/DefaultMoneyRoundingPolicy.cs +++ b/src/VirtoCommerce.CoreModule.Core/Currency/DefaultMoneyRoundingPolicy.cs @@ -58,9 +58,10 @@ protected decimal Round(decimal value, int decimals, RoundingType roundingType, if (roundingType == RoundingType.Rounding01Down && fractionPart == 5) fractionPart = -5; - else - fractionPart = fractionPart < 5 ? fractionPart * -1 : 10 - fractionPart; - + else if (roundingType == RoundingType.Rounding01Up) + fractionPart = 10 - fractionPart; + else if (roundingType == RoundingType.Rounding01Down) + fractionPart = fractionPart * -1; result += fractionPart / 100; break; //rounding with 0.50 intervals @@ -81,6 +82,7 @@ protected decimal Round(decimal value, int decimals, RoundingType roundingType, result = fractionPart < 50 ? Math.Truncate(result) : Math.Truncate(result) + 1; break; + case RoundingType.Rounding001: default: break; diff --git a/src/VirtoCommerce.CoreModule.Data/Currency/CurrencyEntity.cs b/src/VirtoCommerce.CoreModule.Data/Currency/CurrencyEntity.cs index 0013548f..86e0c3a8 100644 --- a/src/VirtoCommerce.CoreModule.Data/Currency/CurrencyEntity.cs +++ b/src/VirtoCommerce.CoreModule.Data/Currency/CurrencyEntity.cs @@ -24,7 +24,7 @@ public class CurrencyEntity : AuditableEntity [StringLength(64)] public string CustomFormatting { get; set; } - [StringLength(16)] + [StringLength(18)] public string MidpointRounding { get; set; } [StringLength(16)] public string RoundingType { get; set; } diff --git a/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.Designer.cs b/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.Designer.cs new file mode 100644 index 00000000..78b401fb --- /dev/null +++ b/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.Designer.cs @@ -0,0 +1,139 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using VirtoCommerce.CoreModule.Data.Repositories; + +namespace VirtoCommerce.CoreModule.Data.Migrations +{ + [DbContext(typeof(CoreDbContext))] + [Migration("20210819064242_ExtendedMidpointRounding")] + partial class ExtendedMidpointRounding + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("VirtoCommerce.CoreModule.Data.Currency.CurrencyEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(128)") + .HasMaxLength(128); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(16)") + .HasMaxLength(16); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(64)") + .HasMaxLength(64); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("CustomFormatting") + .HasColumnType("nvarchar(64)") + .HasMaxLength(64); + + b.Property("ExchangeRate") + .HasColumnType("Money"); + + b.Property("IsPrimary") + .HasColumnType("bit"); + + b.Property("MidpointRounding") + .HasColumnType("nvarchar(18)") + .HasMaxLength(18); + + b.Property("ModifiedBy") + .HasColumnType("nvarchar(64)") + .HasMaxLength(64); + + b.Property("ModifiedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("RoundingType") + .HasColumnType("nvarchar(16)") + .HasMaxLength(16); + + b.Property("Symbol") + .HasColumnType("nvarchar(16)") + .HasMaxLength(16); + + b.HasKey("Id"); + + b.HasIndex("Code") + .HasName("IX_Code"); + + b.ToTable("Currency"); + }); + + modelBuilder.Entity("VirtoCommerce.CoreModule.Data.Model.SequenceEntity", b => + { + b.Property("ObjectType") + .HasColumnType("nvarchar(256)") + .HasMaxLength(256); + + b.Property("ModifiedDate") + .HasColumnType("datetime2"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("Value") + .HasColumnType("int"); + + b.HasKey("ObjectType"); + + b.ToTable("Sequence"); + }); + + modelBuilder.Entity("VirtoCommerce.CoreModule.Data.Package.PackageTypeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("nvarchar(128)") + .HasMaxLength(128); + + b.Property("Height") + .HasColumnType("decimal(18,2)"); + + b.Property("Length") + .HasColumnType("decimal(18,2)"); + + b.Property("MeasureUnit") + .HasColumnType("nvarchar(16)") + .HasMaxLength(16); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(254)") + .HasMaxLength(254); + + b.Property("Width") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.ToTable("PackageType"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.cs b/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.cs new file mode 100644 index 00000000..5f57ebc2 --- /dev/null +++ b/src/VirtoCommerce.CoreModule.Data/Migrations/20210819064242_ExtendedMidpointRounding.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace VirtoCommerce.CoreModule.Data.Migrations +{ + public partial class ExtendedMidpointRounding : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "MidpointRounding", + table: "Currency", + maxLength: 18, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(16)", + oldMaxLength: 16, + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "MidpointRounding", + table: "Currency", + type: "nvarchar(16)", + maxLength: 16, + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 18, + oldNullable: true); + } + } +} diff --git a/src/VirtoCommerce.CoreModule.Data/Migrations/CoreDbContextModelSnapshot.cs b/src/VirtoCommerce.CoreModule.Data/Migrations/CoreDbContextModelSnapshot.cs index b7beeb33..a1d9bfab 100644 --- a/src/VirtoCommerce.CoreModule.Data/Migrations/CoreDbContextModelSnapshot.cs +++ b/src/VirtoCommerce.CoreModule.Data/Migrations/CoreDbContextModelSnapshot.cs @@ -49,8 +49,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bit"); b.Property("MidpointRounding") - .HasColumnType("nvarchar(16)") - .HasMaxLength(16); + .HasColumnType("nvarchar(18)") + .HasMaxLength(18); b.Property("ModifiedBy") .HasColumnType("nvarchar(64)") diff --git a/tests/VirtoCommerce.CoreModule.Tests/DefaultMoneyRoundingPolicyTests.cs b/tests/VirtoCommerce.CoreModule.Tests/DefaultMoneyRoundingPolicyTests.cs index e1d2d313..4174ac71 100644 --- a/tests/VirtoCommerce.CoreModule.Tests/DefaultMoneyRoundingPolicyTests.cs +++ b/tests/VirtoCommerce.CoreModule.Tests/DefaultMoneyRoundingPolicyTests.cs @@ -44,8 +44,11 @@ public void CanRound(decimal amount, decimal expected, RoundingType roundingType new object[] { 1.105m, 1.1m, RoundingType.Rounding01Down, MidpointRounding.AwayFromZero}, new object[] { 1.599m, 1.6m, RoundingType.Rounding01Down, MidpointRounding.AwayFromZero}, new object[] { 1.999m, 2m, RoundingType.Rounding01Down, MidpointRounding.AwayFromZero}, + new object[] { 78.36m, 78.3m, RoundingType.Rounding01Down, MidpointRounding.AwayFromZero}, new object[] { 1.09m, 1.1m, RoundingType.Rounding01Up, MidpointRounding.AwayFromZero}, + new object[] { 26.12m, 26.2m, RoundingType.Rounding01Up, MidpointRounding.AwayFromZero}, + new object[] { 1.04m, 1m, RoundingType.Rounding05, MidpointRounding.AwayFromZero}, new object[] { 1.400009m, 1.5m, RoundingType.Rounding05, MidpointRounding.AwayFromZero},