Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amount and Currency refactor #44

Merged
merged 12 commits into from
Nov 19, 2019
Merged

Amount and Currency refactor #44

merged 12 commits into from
Nov 19, 2019

Conversation

Allann
Copy link

@Allann Allann commented Nov 6, 2019

Major refactor to introduce Currencies as a built-in list from NetStandard 2.0 which the amount data type uses to add context to the decimal value.

Don't make any assumptions when writing serialized amounts. Should read also fail if amount does not contain a currency?

Should the money project be made a module? I'm very new to Orchard so not sure. I am attempting to create a module too which uses money amounts and it would be good to standardize the money library.

allan added 2 commits November 6, 2019 09:27
…ndard 2.0 which the amount data type uses to add context to the decimal value.

Removed float and int constrcutors to reduce internal rounding issues.
…ad also fail if amount does not contain a currency?
@bleroy
Copy link
Member

bleroy commented Nov 6, 2019

Can you exclude the sln file?

Copy link
Member

@bleroy bleroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I made a bunch of suggestions.

MoneyDataType/Amount.cs Outdated Show resolved Hide resolved
MoneyDataType/Amount.cs Outdated Show resolved Hide resolved
MoneyDataType/Amount.cs Outdated Show resolved Hide resolved
MoneyDataType/AmountConverter.cs Outdated Show resolved Hide resolved
MoneyDataType/AmountConverter.cs Show resolved Hide resolved
MoneyDataType/KnownCurrencyTable.cs Outdated Show resolved Hide resolved
MoneyDataType/KnownCurrencyTable.cs Outdated Show resolved Hide resolved
Services/MoneyService.cs Outdated Show resolved Hide resolved
@Allann
Copy link
Author

Allann commented Nov 6, 2019

Updated most changes as requested. Do i need to create a new pull request? not sure how this works.

@Allann Allann requested a review from bleroy November 6, 2019 13:12
@Skrypt
Copy link
Contributor

Skrypt commented Nov 6, 2019

You add commits on top of your fork branch and it adds it on the PR. Simple as that 😄

@Allann
Copy link
Author

Allann commented Nov 6, 2019

ok thanks. hope this round goes better.

Should the MoneyDataType library be made into an orchard module so others can benefit from the work too? I am trying to write another module which needs money/currencies too and it would be good to leverage the same feature. Just not sure how to go about it and what it would need extra. Some guidance in that department would be good if that is the path we will take.

@bleroy
Copy link
Member

bleroy commented Nov 6, 2019

I really appreciate your patience and contribution. It's fairly normal for a first PR to a project to be generating a lot of feedback :) This is good stuff.

So about MoneyDataType, to me it's not an Orchard module, it's a library, useful independently of Orchard, and taking no dependency on Orchard. So the way to make it available to others, I think, is to package it in NuGet form. That means adding the necessary metadata to the project file (super-easy through the project properties dialog in VS, or by editing the project's XML), and then publishing the package on NuGet.org.

Long-term, we could move the code to a separate repo, or keep it here and continue to reference it as a project ref, either way is fine. Maybe keeping it around is a little more convenient for us, but then again I don't expect it to change a lot going forward.

I'm looking at your new changes and comments now.

allan added 2 commits November 8, 2019 15:59
…turn "foreign" currencies that don't appear in default table.

Updated IsoCode name to CurrentIsoCode where appropriate.
Introduced DefaultProvider internal property in Currency.
Fixed bug in CurrencyProvider whereby items not in dictionary would throw.
Ensure Unknown currencies can be serialised and deserialised
Changed Currency type to be struct for value comparison instead of reference comparison to aid serialisation.
@Allann
Copy link
Author

Allann commented Nov 15, 2019

Finally updated to support unknown currencies. I think this solves the issue of 2 step resolution of currencies. basically it alters the way a currency is serialised depending on the new IsKnownCurrency property. They many thing that aids this is that Currency is a Struct and equality is determined by value and not reference.
If this does not work can you please add a failing test and I'll fix.

MoneyDataType/AmountConverter.cs Show resolved Hide resolved
MoneyDataType/MoneyDataType.csproj Outdated Show resolved Hide resolved
OrchardCore.Commerce.Tests/AmountTests.cs Show resolved Hide resolved
@bleroy
Copy link
Member

bleroy commented Nov 18, 2019

Cool, thanks for the changes! I'm going to merge that in a few minutes unless there's anything more you want to do first.

@Allann
Copy link
Author

Allann commented Nov 18, 2019

All good, and thanks for all the great feedback. Really enjoyed the process, and I think we have a solid library to build on.

@bleroy bleroy merged commit bf42dad into OrchardCMS:master Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants