-
Notifications
You must be signed in to change notification settings - Fork 113
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
list for currency selection in general settings #329
Conversation
Changes: Adding a dropdown on create general settings form to choose a currency from a given list of currencies.
2cc163e
to
765ee82
Compare
Codecov Report
@@ Coverage Diff @@
## develop #329 +/- ##
===========================================
+ Coverage 67.06% 67.08% +0.02%
===========================================
Files 134 134
Lines 1497 1498 +1
===========================================
+ Hits 1004 1005 +1
Misses 493 493
Continue to review full report at Codecov.
|
501b3d3
to
518bfd8
Compare
518bfd8
to
023f454
Compare
@@ -22,7 +22,15 @@ | |||
<%= input f, :hosted_payment_url, nil, is_horizontal: true, description: "Payment URL for the store." %> | |||
</div> | |||
<div class="form-group row "> | |||
<%= input f, :currency, nil, is_horizontal: true, description: "Default currency for the store." %> | |||
<label class="col-sm-3 col-form-label"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is not correct
general_config = Repo.all(GC) |> List.first() | ||
if general_config != nil, do: general_config.currency, else: "USD" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def fetch_currency do
case Repo.one(GC)
nil -> "USD"
gc -> gc.currency
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more succinct way.
@@ -38,7 +38,7 @@ defmodule Snitch.Domain.Order do | |||
""" | |||
@spec payments_total(Order.t(), String.t()) :: Money.t() | |||
def payments_total(order, payment_state) do | |||
{:ok, currency} = Defaults.fetch(:currency) | |||
currency = GCModel.fetch_currency() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really prefer to have {:ok, currency}
or {:error, msg}
rather than returning just as currency. this way matching becomes easier. @SagarKarwande thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use just the return value since we will be using a Repo.one
query, which either gives a value or nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes returning tuples with success and error will help.
@ashish173 As per the definition of GeneralConfiguration.fetch_currency()
we would never be able to get the error case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's okay @SagarKarwande for now. Since we always start/provision a store with a currency. I think now I agree with what @pkrawat1 is saying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there would be no {:error, msg} scenario, it will always return a string.
@@ -2,7 +2,13 @@ defmodule AdminAppWeb.GeneralSettingsView do | |||
use AdminAppWeb, :view | |||
alias Snitch.Data.Model.ProductBrand | |||
|
|||
@currencies ["USD", "INR", "GDP", "EUR"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in the core rather than in the admin application IMO. @pkrawat1 @SagarKarwande ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, valid currencies should be a part of core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I know the idea behind this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any application would always depend on core and can easily access the valid currencies.
@@ -36,7 +37,8 @@ defmodule AdminAppWeb.LayoutView do | |||
end | |||
|
|||
def check_general_settings() do | |||
Repo.all(GeneralConfiguration) |> List.first() | |||
count = Repo.aggregate(from(g in "snitch_general_configurations"), :count, :id) | |||
if count == 1, do: true, else: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is too complex to identify the presence of GC or not, please simplify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def check_general_settings do
case Repo.one(GC)
nil -> false
_ -> true
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sure
@@ -2,7 +2,13 @@ defmodule AdminAppWeb.GeneralSettingsView do | |||
use AdminAppWeb, :view | |||
alias Snitch.Data.Model.ProductBrand | |||
|
|||
@currencies ["USD", "INR", "GDP", "EUR"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking if any other app in the umbrella would be needing the list of currencies. If it does then it will be required to move to some other place. So how about keeping it at a place in app that can expose this to all other apps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think core
should contain list of valid currencies
@@ -10,6 +10,12 @@ defmodule Snitch.Data.Model.GeneralConfiguration do | |||
alias Snitch.Tools.Helper.ImageUploader | |||
alias Ecto.Multi | |||
|
|||
@spec fetch_currency() :: String.t() | |||
def fetch_currency do | |||
general_config = Repo.all(GC) |> List.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Repo.all()
when we can use Repo.one()
? That way you also won't have to do List.first()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, then I have to handle the error raised if multiple results of Repo.one(GC) could be returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repo.one
only returns just one result. In any case my assumption is that we can only have one general setting with the way how the code is written.
@jyotigautam move the currency list to the core application. This is an important change. |
@ashish173 @pkrawat1 Should the currency change be allowed after General Setting is created? |
@@ -51,7 +51,7 @@ | |||
<div class="col-sm-9 input-group"> | |||
<%= text_input :selling_price, :amount, value: get_amount(f.data.selling_price), class: "form-control", name: "product[selling_price][amount]" %> | |||
<div class="input-group-append"> | |||
<%= select :selling_price, :currency, get_currency(),value: get_currency_value(f.data.selling_price), class: "form-control", name: "product[selling_price][currency]" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyotigautam
As we will be using currency from GeneralSetting. Does showing currency selection to user makes sense?
Currency for product prices can be set in changeset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the currency selected only shows one value i.e, from the general settings or "usd" if no general setting is set. So, the user can't choose from this list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyotigautam @SagarKarwande I would say we remove the select altogether and just show a label of the currency. Just like it is done with etsy store. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is no point of showing it as select input when we have just one option.
@SagarKarwande we are provisioning the general settings with a currency "USD" for now. So all the products which get created happen with the currency. Currency change is another issue in itself we will revisit it at a later phase. #330 |
|
||
@spec get_currency_list() :: List.t() | ||
def get_currency_list do | ||
["USD", "INR", "GDP", "EUR"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyotigautam let's make this array a module attribute, I see this as a constant what do you think?
Changes: Adding a dropdown on create general settings form to choose a currency from a given list of currencies.
Changes: Adding a dropdown on create general settings form to choose a currency from a given list of currencies.
Since we need a common currency globally set for a store, hence the currency is fetched from the store settings at every place where currency is used. Changes:- Added a list of currencies to choose from in general settings form. Used the currency set in general config everywhere as default currency.
Adding a dropdown on create general settings form to choose a currency from a given list of currencies.
Motivation and Context
Since we need a common currency globally set for a store, hence the currency is fetched from the store settings at every place where currency is used.
Describe your changes
Checklist
credo
and compile-time warnings.Dear Gatekeeper,
Please make sure that the commits that will be merged or rebased into the base
branch are formatted according to our standards.