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

[RFC] Direct/Inverse Exchange Rates #10075

Open
vntw opened this issue Jan 7, 2019 · 4 comments
Open

[RFC] Direct/Inverse Exchange Rates #10075

vntw opened this issue Jan 7, 2019 · 4 comments
Labels
Do not stale Important issues and PRs, that should not be stalled by Stale Bot RFC Discussions about potential changes or new features.

Comments

@vntw
Copy link
Contributor

vntw commented Jan 7, 2019

After reading the documentation and working on the code (fixture to create exchange rates automatically based on currencies), I'm not sure how to handle Exchange Rates. From my standpoint, I'd like to have full control over every exchange rate and their ratios. For example:

  • EUR (source) -> USD (target) 1.14675
  • USD (source) -> EUR (target) 0.8080
  • EUR (source) -> SEK (target) 10.208 (omit SEK -> EUR for inverse calculation)

Currently this is limited to EUR->USD 1.14675 and Sylius won't allow USD->EUR to be specified (The currency pair must be unique), it will always calculate the inverse exchange rate to calculate the price USD -> EUR. From what I read this isn't always the case since the bank may offer different ratios for a currency relation.

From a data schema point of view, it's not a problem to store (which is why I didn't see a problem in the beginning, since creating/inserting models works nicely), but this came up while I was testing my code and got a More than one result was found for query although one row or none was expected. in ExchangeRateRepository::findOneWithCurrencyPair.

I found the PR (#6781) this was originally built (the way I imagined it), which was changed shortly after without (visible) discussion based on a single review comment #6781 (comment).

So my question is: Is the current solution how it was/is intended and everything else should be customized?

Based on the answer, we should either

  • change the feature to be more flexible...
    • Return direct exchange rate relation first in repository and if it doesn't exist, use the inverse one
    • UniqueCurrencyPairValidator checks only source -> target and not inverse
    • TBD maybe something I'm missing?
  • and/or make it clear in the documentation how Sylius handles exchange rates.

But before I change anything, I'd like to hear your opinion on this.

@Zales0123 Zales0123 added the RFC Discussions about potential changes or new features. label Jan 8, 2019
@stale
Copy link

stale bot commented Apr 8, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues and PRs with no recent activity, about to be closed soon. label Apr 8, 2019
@vvasiloi
Copy link
Contributor

vvasiloi commented Apr 8, 2019

@venyii I think this limitation is redundand.
The following behavior is better in my opinion:

  • can create a source -> target exchange rate
  • can create a target -> source exchange rate
  • if the direct one is not available, then fallback to the reverse one

And it will not introduce a BC break.

@stale stale bot removed the Stale Issues and PRs with no recent activity, about to be closed soon. label Apr 8, 2019
@stale
Copy link

stale bot commented Jul 7, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues and PRs with no recent activity, about to be closed soon. label Jul 7, 2019
@pamil pamil added Do not stale Important issues and PRs, that should not be stalled by Stale Bot and removed Stale Issues and PRs with no recent activity, about to be closed soon. labels Jul 11, 2019
@pamil
Copy link
Contributor

pamil commented Jul 11, 2019

Thanks for your patience!

I'd go for dropping the unique constraint for inversed exchange rates. It should be possible to have both EUR/USD and USD/EUR exchange rates. To preserve backwards compatibility, when doing the conversion from EUR to USD, it should first look up for EUR/USD and then fallback to USD/EUR.

I would be happy to merge a PR that does that and includes tests for the added behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do not stale Important issues and PRs, that should not be stalled by Stale Bot RFC Discussions about potential changes or new features.
Projects
None yet
Development

No branches or pull requests

4 participants