-
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
Changes from all commits
765ee82
023f454
f82d70e
e844e0b
43ce448
56d0669
5c6adc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
defmodule AdminAppWeb.GeneralSettingsView do | ||
use AdminAppWeb, :view | ||
alias Snitch.Data.Model.ProductBrand | ||
alias Snitch.Data.Model.GeneralConfiguration, as: GCModel | ||
|
||
def get_image_url(image, general_settings) do | ||
ProductBrand.image_url(image.name, general_settings) | ||
end | ||
|
||
def get_currency() do | ||
GCModel.get_currency_list() | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,21 @@ defmodule Snitch.Data.Model.GeneralConfiguration do | |
alias Snitch.Tools.Helper.ImageUploader | ||
alias Ecto.Multi | ||
|
||
@currency_list ["USD", "INR", "GDP", "EUR"] | ||
|
||
@spec fetch_currency() :: String.t() | ||
def fetch_currency do | ||
case Repo.one(GC) do | ||
nil -> "USD" | ||
gc -> gc.currency | ||
end | ||
end | ||
|
||
@spec get_currency_list() :: List.t() | ||
def get_currency_list do | ||
@currency_list | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This is more succinct way. |
||
@spec build_general_configuration(map) :: Ecto.Changeset.t() | ||
def build_general_configuration(attrs \\ %{}) do | ||
%GC{} |> GC.create_changeset(attrs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ defmodule Snitch.Domain.Order do | |
import Ecto.Query | ||
alias Snitch.Data.Schema.{Order, Package, Payment} | ||
alias Snitch.Data.Model.Product | ||
alias Snitch.Tools.Defaults | ||
alias Snitch.Data.Model.GeneralConfiguration, as: GCModel | ||
|
||
@spec validate_change(Ecto.Changeset.t()) :: Ecto.Changeset.t() | ||
def validate_change(%{valid?: false} = changeset), do: changeset | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I would really prefer to have There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
|
||
query = | ||
from( | ||
|
@@ -76,7 +76,7 @@ defmodule Snitch.Domain.Order do | |
|
||
def total_amount(%Order{} = order) do | ||
order = Repo.preload(order, [:line_items, packages: :items]) | ||
{:ok, currency} = Defaults.fetch(:currency) | ||
currency = GCModel.fetch_currency() | ||
|
||
total = | ||
Money.add!( | ||
|
@@ -88,7 +88,7 @@ defmodule Snitch.Domain.Order do | |
end | ||
|
||
def line_item_total(order) do | ||
{:ok, currency} = Defaults.fetch(:currency) | ||
currency = GCModel.fetch_currency() | ||
|
||
order.line_items | ||
|> Enum.reduce(Money.new(currency, 0), fn line_item, acc -> | ||
|
@@ -130,7 +130,7 @@ defmodule Snitch.Domain.Order do | |
end | ||
|
||
def total_tax(packages) do | ||
{:ok, currency} = Defaults.fetch(:currency) | ||
currency = GCModel.fetch_currency() | ||
|
||
packages | ||
|> Enum.reduce(Money.new(currency, 0), fn %{ | ||
|
@@ -146,7 +146,7 @@ defmodule Snitch.Domain.Order do | |
end | ||
|
||
def shipping_total(packages) do | ||
{:ok, currency} = Defaults.fetch(:currency) | ||
currency = GCModel.fetch_currency() | ||
|
||
packages | ||
|> Enum.reduce(Money.new(currency, 0), fn %{cost: cost}, acc -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Snitch.Seed.GeneralConfiguration do | ||
alias Snitch.Data.Schema.GeneralConfiguration, as: GCSchema | ||
alias Snitch.Core.Tools.MultiTenancy.Repo | ||
|
||
def seed!() do | ||
Repo.delete_all(GCSchema) | ||
%GCSchema{currency: "USD"} |> Repo.insert() | ||
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.
@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.