glamorous-napkin-23111
10/01/2025, 12:53 PMdefault option on the field and set it using a Money object but it doesn't work. The form only displays 0.00 in the field. I've also tried setting the default value with the _cents field or with a static value such as 1000.00. Nothing works, the value loaded in the form is always 0.00.
This is the code:
field :labor, as: :money, currencies: [ "EUR" ], name: "Labor", required: true, default: project&.default_phase_labor
Any idea what is wrong here? Thanks for the support!miniature-optician-85831
10/01/2025, 12:53 PMlemon-wall-20836
10/01/2025, 1:08 PMlemon-wall-20836
10/01/2025, 1:09 PMglamorous-napkin-23111
10/01/2025, 1:09 PMlemon-wall-20836
10/01/2025, 1:09 PMglamorous-napkin-23111
10/01/2025, 1:09 PMlemon-wall-20836
10/01/2025, 1:10 PMglamorous-napkin-23111
10/01/2025, 1:38 PMdef fields
project = params[:via_record_id] ? Project.find(params[:via_record_id]) : nil
field :id, as: :id
field :company_id, as: :hidden, default: Avo::Current.tenant_id
field :project, as: :belongs_to
field :name, as: :text, hide_on: :show
field :h_phase_timeline, as: :heading, label: "Phase Timeline"
field :start_date, as: :date, default: project&.default_phase_start_date
field :end_date, as: :date, default: project&.default_phase_end_date
field :duration, as: :number, format_show_using: -> { "#{value} months" }
field :status, as: :select, enum: ::Phase.statuses, default: 0, required: true
panel name: "Phase Financials" do
field :labor, as: :money, currencies: [ "EUR" ], name: "Labor", required: true, help: "Remaining labor budget: #{project&.remaining_labor} #{project&.remaining_labor&.currency}"
field :direct_costs, as: :money, currencies: [ "EUR" ], required: true, help: "Remaining direct costs budget: #{project&.remaining_direct_costs} #{project&.remaining_direct_costs&.currency}", default: -> { project&.default_phase_direct_costs }
end
panel name: "Financial Objectives" do
field :labor_margin_objective_pc, as: :number, format_show_using: -> { "#{value}%" }, name: "Labor Margin (%)", help: -> { "Contract labor objective: #{project&.default_phase_labor_margin_objective_pc}%" }
field :labor_margin_objective_val, as: :money, currencies: [ "EUR" ], name: "Labor Margin", only_on: :show
field :labor_execution_budget, as: :money, currencies: [ "EUR" ], name: "Labor Execution Budget", only_on: :show
end
field :project_reports, as: :has_many
field :time_entries, as: :has_many
endglamorous-napkin-23111
10/01/2025, 1:39 PMlemon-wall-20836
10/01/2025, 1:54 PMlemon-wall-20836
10/01/2025, 1:54 PMlemon-wall-20836
10/01/2025, 1:54 PMlemon-wall-20836
10/01/2025, 1:55 PMlemon-wall-20836
10/01/2025, 1:55 PMlemon-wall-20836
10/01/2025, 1:56 PMloud-jewelry-99127
10/01/2025, 3:23 PMproject&.default_phase_labor returning ?glamorous-napkin-23111
10/01/2025, 3:53 PMloud-jewelry-99127
10/01/2025, 4:04 PMloud-jewelry-99127
10/01/2025, 4:04 PMloud-jewelry-99127
10/01/2025, 4:05 PMYourModelName.new.labor
It will probably return #<Money fractional:0 currency:USD> which is not nil so default is not appliedloud-jewelry-99127
10/01/2025, 4:09 PMloud-jewelry-99127
10/01/2025, 4:09 PMnil values on the monetized attributeloud-jewelry-99127
10/01/2025, 4:11 PMloud-jewelry-99127
10/01/2025, 4:13 PMnilglamorous-napkin-23111
10/01/2025, 4:46 PMglamorous-napkin-23111
10/01/2025, 4:46 PMloud-jewelry-99127
10/01/2025, 4:54 PMglamorous-napkin-23111
10/01/2025, 6:32 PMminiature-optician-85831
10/01/2025, 6:33 PM