diff --git a/lib/open_project/costs/patches/work_package_patch.rb b/lib/open_project/costs/patches/work_package_patch.rb index 2b08d59e91..6f425ee3ac 100644 --- a/lib/open_project/costs/patches/work_package_patch.rb +++ b/lib/open_project/costs/patches/work_package_patch.rb @@ -99,9 +99,9 @@ module OpenProject::Costs::Patches::WorkPackagePatch end def validate_cost_object - if cost_object && cost_object.changed? - unless (cost_object.blank? || project.cost_object_ids.include?(cost_object.id)) - errors.add :cost_object, :invalid + if changed.include? 'cost_object_id' + unless (cost_object_id.blank? || project.cost_object_ids.include?(cost_object_id)) + errors.add :cost_object, :inclusion end end end