Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix/decimal separator in overwritten costs (#8874)

ulferts511ab615fc8f
diff --git a/modules/budgets/app/models/budget.rb b/modules/budgets/app/models/budget.rb
index a81994b024d..560d7d7d0eb 100644
--- a/modules/budgets/app/models/budget.rb
+++ b/modules/budgets/app/models/budget.rb
@@ -192,7 +192,9 @@ class Budget < ApplicationRecord
material_budget_item_attributes.each do |_index, attributes|
correct_material_attributes!(attributes)
- material_budget_items.build(attributes) if attributes[:units].to_f.positive?
+ if valid_material_budget_attributes?(attributes)
+ material_budget_items.build(attributes)
+ end
end
end
@@ -233,12 +235,14 @@ class Budget < ApplicationRecord
return unless attributes
attributes[:hours] = Rate.parse_number_string_to_number(attributes[:hours])
+ attributes[:amount] = Rate.parse_number_string(attributes[:amount])
end
def correct_material_attributes!(attributes)
return unless attributes
attributes[:units] = Rate.parse_number_string_to_number(attributes[:units])
+ attributes[:amount] = Rate.parse_number_string(attributes[:amount])
end
def update_budget_item_attributes(budget_item_attributes, type:)
@@ -251,7 +255,7 @@ class Budget < ApplicationRecord
send("correct_#{type}_attributes!", attributes)
if send("valid_#{type}_budget_attributes?", attributes)
- budget_item.attributes = attributes.merge(amount: Rate.parse_number_string(attributes[:amount]))
+ budget_item.attributes = attributes
else
# This is surprising as it will delete right away compared to the
# update of the attributes that requires a save afterwards to take effect.
diff --git a/modules/budgets/spec/features/budgets/copy_budget_spec.rb b/modules/budgets/spec/features/budgets/copy_budget_spec.rb
index 106b11a34e3..b76817ace09 100644
--- a/modules/budgets/spec/features/budgets/copy_budget_spec.rb
+++ b/modules/budgets/spec/features/budgets/copy_budget_spec.rb
@@ -61,7 +61,7 @@ describe 'Copying a budget', type: :feature, js: true do
units: 10,
cost_type: cost_type,
budget: budget,
- amount: 60.00
+ amount: 600000.00
end
let!(:labor_budget_item) do
@@ -85,7 +85,7 @@ describe 'Copying a budget', type: :feature, js: true do
budget_page.expect_planned_costs!(type: :labor, row: 1, expected: '125.00 EUR')
budget_page.expect_planned_costs!(type: :material, row: 1, expected: '150.00 EUR')
- budget_page.expect_planned_costs!(type: :material, row: 2, expected: '60.00 EUR')
+ budget_page.expect_planned_costs!(type: :material, row: 2, expected: '600,000.00 EUR')
click_button 'Create'