Skip to content

Commit

Permalink
Merge branch 'release/3.21.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro committed Aug 24, 2021
2 parents bb8aa36 + 3f299be commit afadde7
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 13 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?><Project>
<!-- These properties will be shared for all projects -->
<PropertyGroup>
<VersionPrefix>3.20.0</VersionPrefix>
<VersionPrefix>3.21.0</VersionPrefix>
<VersionSuffix>
</VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
Expand Down
21 changes: 21 additions & 0 deletions docs/How-to override rounding policy.md
Original file line number Diff line number Diff line change
@@ -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<IMoneyRoundingPolicy, CustomMoneyRoundingPolicy>();
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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<string>(
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<string>(
name: "MidpointRounding",
table: "Currency",
type: "nvarchar(16)",
maxLength: 16,
nullable: true,
oldClrType: typeof(string),
oldMaxLength: 18,
oldNullable: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bit");

b.Property<string>("MidpointRounding")
.HasColumnType("nvarchar(16)")
.HasMaxLength(16);
.HasColumnType("nvarchar(18)")
.HasMaxLength(18);

b.Property<string>("ModifiedBy")
.HasColumnType("nvarchar(64)")
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.CoreModule.Web/module.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>VirtoCommerce.Core</id>
<version>3.20.0</version>
<version>3.21.0</version>
<version-tag />
<platformVersion>3.66.0</platformVersion>
<title>Commerce core module</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit afadde7

Please sign in to comment.