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 copying with overwritten costs (#8862)

ulferts8268e30edf36
diff --git a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
index 449055c1661..6657db3398b 100644
--- a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
+++ b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
@@ -84,8 +84,8 @@ See docs/COPYRIGHT.rdoc for more details.
<% if User.current.allowed_to?(:view_cost_rates, @project) %>
<td class="currency budget-table--fields">
<%# Keep current budget as hidden field because otherwise they will be overridden %>
- <% if templated == false && !labor_budget_item.new_record? && labor_budget_item.overridden_costs? %>
- <%= cost_form.hidden_field :amount, value: unitless_currency_number(labor_budget_item.amount) %>
+ <% if templated == false && labor_budget_item.overridden_costs? %>
+ <%= cost_form.hidden_field :amount, index: id_or_index, value: unitless_currency_number(labor_budget_item.amount) %>
<% end %>
<% cost_value = labor_budget_item.amount || labor_budget_item.calculated_costs(@budget.fixed_date, @budget.project_id) %>
diff --git a/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb b/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb
index 4109616486a..c3a4dab16f9 100644
--- a/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb
+++ b/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb
@@ -86,8 +86,8 @@ See docs/COPYRIGHT.rdoc for more details.
<% if User.current.allowed_to? :view_cost_rates, @project %>
<td class="currency budget-table--fields">
<%# Keep current budget as hidden field because otherwise they will be overridden %>
- <% if templated == false && !material_budget_item.new_record? && material_budget_item.overridden_costs? %>
- <%= cost_form.hidden_field :amount, value: unitless_currency_number(material_budget_item.amount) %>
+ <% if templated == false && material_budget_item.overridden_costs? %>
+ <%= cost_form.hidden_field :amount, index: id_or_index, value: unitless_currency_number(material_budget_item.amount) %>
<% end %>
<% cost_value = material_budget_item.amount || material_budget_item.calculated_costs(@budget.fixed_date) %>
diff --git a/modules/budgets/spec/features/budgets/copy_budget_spec.rb b/modules/budgets/spec/features/budgets/copy_budget_spec.rb
index 6b25a20dc2b..106b11a34e3 100644
--- a/modules/budgets/spec/features/budgets/copy_budget_spec.rb
+++ b/modules/budgets/spec/features/budgets/copy_budget_spec.rb
@@ -56,6 +56,13 @@ describe 'Copying a budget', type: :feature, js: true do
cost_type: cost_type,
budget: budget
end
+ let!(:overwritten_material_budget_item) do
+ FactoryBot.create :material_budget_item,
+ units: 10,
+ cost_type: cost_type,
+ budget: budget,
+ amount: 60.00
+ end
let!(:labor_budget_item) do
FactoryBot.create :labor_budget_item,
@@ -78,6 +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')
click_button 'Create'