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

Money field does not show up #3228

Closed
4 of 11 tasks
jasdeepsingh opened this issue Sep 6, 2024 · 5 comments
Closed
4 of 11 tasks

Money field does not show up #3228

jasdeepsingh opened this issue Sep 6, 2024 · 5 comments
Labels
Waiting on Reproduction Pending reproduction repository or detailed reproduction steps to proceed with issue resolution.

Comments

@jasdeepsingh
Copy link

Describe the bug

Using the avo money field on a resource as follows:

class Avo::Resources::Product < Avo::BaseResource
  def fields
    field :id, as: :id
    field :price, as: :money, currencies: %w[EUR USD]
  end
end

However, the field is not showing up or rendering in UI (create/edit forms). If I change the field type to number, it works fine. The actual field name in DB is price_cents

Steps to Reproduce

  1. Create a new Rails 7.2.1 project.
  2. Add a new Avo Resource
  3. Add a money field on the model/resource
  4. Try to render the money field in the Avo dashboard.

Expected behavior & Actual behavior

Expected result: Money field shows up in the create/edit form.
Actual result: Money field does not show up in create/edit form

Models and resource files

System configuration

Avo version: 3.12.0

Rails version: 7.2.1

Ruby version: 3.3.4

License type:

  • Community
  • Pro
  • Advanced

Are you using Avo monkey patches, overriding views or view components?

  • Yes. If so, please post code samples.
  • No

Screenshots or screen recordings

N/A

Additional context

gem "avo", ">= 3.12.0"
gem "money-rails", "~> 1.12"
gem "avo-money_field"

Impact

  • High impact (It makes my app un-usable.)
  • Medium impact (I'm annoyed, but I'll live.)
  • Low impact (It's really a tiny thing that I could live with.)

Urgency

  • High urgency (I can't continue development without it.)
  • Medium urgency (I found a workaround, but I'd love to have it fixed.)
  • Low urgency (It can wait. I just wanted you to know about it.)
@Paul-Bob
Copy link
Contributor

Paul-Bob commented Sep 9, 2024

Hello @jasdeepsingh it's working as expected on our demo https://main.avodemo.com/avo/resources/products/new

Please provide a minimal reproduction repository where we can reproduce it.

@Paul-Bob Paul-Bob added the Waiting on Reproduction Pending reproduction repository or detailed reproduction steps to proceed with issue resolution. label Sep 9, 2024
@butschi
Copy link

butschi commented Sep 11, 2024

I had the same. In my case it was because I had the database field configured to be nullable, meaning both the value and the currency could become null.

For me the solution was to default the value to 0 and the currency to my main currency. Then the Avo money fields would show up in the forms.

@jasdeepsingh
Copy link
Author

@butschi For me the field is not nullable and default is set to 0 already.

t.integer "price_cents", default: 0, null: false
t.string "price_currency", default: "USD", null: false

Still not able to see the field.

@Paul-Bob I will share a repo where this can be reproduced.

@jasdeepsingh
Copy link
Author

@Paul-Bob Here's a repo where this bug can be reproduced:

https://github.com/metaware/avo-money-bug

Steps to reproduce:

  1. Clone the repo
  2. Install all gems bundle install
  3. Migrate database rails db:create; rails db:migrate
  4. Launch the server: rails s
  5. Visit the Avo path: http://localhost:3000/avo

Try to create a new Product.

Expectation: Price field is rendered.
Actual result: Price field is not rendered.

image

class Avo::Resources::Product < Avo::BaseResource
  def fields
    field :id, as: :id
    field :name, as: :text
    field :description, as: :text
    field :upc_code, as: :number
    field :price, as: :money, currencies: [ "USD", "CAD" ]
  end
end

@Paul-Bob
Copy link
Contributor

Thanks for the reproduction repository, I was able to identify the issue. You're missing the monetize :price_cents on the model (metaware/avo-money-bug#1). I'm also updating the docs with this piece of information.

I'm closing as solved, please let me know if the issue persists.

@github-project-automation github-project-automation bot moved this to Done in Issues Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting on Reproduction Pending reproduction repository or detailed reproduction steps to proceed with issue resolution.
Projects
Status: Done
Development

No branches or pull requests

3 participants