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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#66093] Add general error for missing attributes
Tobias Dillmanne346628f4e25
diff --git a/app/models/acts_as_customizable/calculated_value.rb b/app/models/acts_as_customizable/calculated_value.rbindex 2ce6e858eff..06b8c99c026 100644--- a/app/models/acts_as_customizable/calculated_value.rb+++ b/app/models/acts_as_customizable/calculated_value.rb@@ -48,14 +48,14 @@ module ActsAsCustomizable::CalculatedValueendenabled_ids = enabled_custom_field_ids-+ given = calculated_value_fields_given(custom_fields:, enabled_ids:)result = calculate_custom_fields_result(- given: calculated_value_fields_given(custom_fields:, enabled_ids:),+ given:,to_compute: calculated_value_fields_to_compute(custom_fields:, enabled_ids:))self.custom_field_values = custom_fields.to_h { [it.id, result[it.column_name]] }- refresh_calculation_errors!(result)+ refresh_calculation_errors!(given, custom_fields.map(&:id), result)endprivate@@ -86,7 +86,7 @@ module ActsAsCustomizable::CalculatedValuecf_id.sub("cf_", "").to_iend- def refresh_calculation_errors!(result)+ def refresh_calculation_errors!(referenced_values, calculated_field_ids, result)return unless is_a?(Project)failed_calculations, successful_calculations = result.partition do |_, calculation_result|@@ -96,6 +96,8 @@ module ActsAsCustomizable::CalculatedValuesuccessfully_calculated_cfs = successful_calculations.map { |cf_id, _| to_id(cf_id) }remove_calculated_value_errors(successfully_calculated_cfs)+ create_errors_for_missing_attributes(referenced_values, calculated_field_ids)+failed_calculations.to_h.each_key do |cf_id|create_calculated_value_error(to_id(cf_id), "ERROR_MATHEMATICAL")end@@ -105,7 +107,19 @@ module ActsAsCustomizable::CalculatedValueCalculatedValueError.create(project: self, custom_field_id:, error_code:)end+ def create_errors_for_missing_attributes(referenced_values, calculated_field_ids)+ cf_ids_with_missing_values = referenced_values.filter_map { |k, v| to_id(k) if v.nil? }+ cf_ids_with_missing_values.each do |_missing_cf_id|+ calculated_field_ids.each do |calculated_cf_id|+ # TODO: insert missing custom field name into the error message:+ create_calculated_value_error(calculated_cf_id, "ERROR_MISSING_VALUE")+ end+ end+ end+def remove_calculated_value_errors(custom_field_ids = [])+ return if custom_field_ids.empty?+CalculatedValueError.where(project: self, custom_field_id: custom_field_ids).delete_allendenddiff --git a/app/models/calculated_value_error.rb b/app/models/calculated_value_error.rbindex 493ba9041c9..aff056e975e 100644--- a/app/models/calculated_value_error.rb+++ b/app/models/calculated_value_error.rb@@ -33,7 +33,8 @@ class CalculatedValueError < ApplicationRecordbelongs_to :custom_fieldERROR_TRANSLATIONS = {- "ERROR_MATHEMATICAL" => "calculated_values.errors.mathematical"+ "ERROR_MATHEMATICAL" => "calculated_values.errors.mathematical",+ "ERROR_MISSING_VALUE" => "calculated_values.errors.missing_value"}.freezeVALID_ERROR_CODES = ERROR_TRANSLATIONS.keys.freezediff --git a/config/locales/en.yml b/config/locales/en.ymlindex 6a1d79be5df..41df72858bb 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -363,7 +363,8 @@ en:calculated_values:errors:unknown: "An unknown error occurred during calculation. Please review the formula and try again."- mathematical: "A mathematical error occurred. Please review the formula and try again."+ mathematical: "A mathematical error occurred during calculation. Please review the formula and try again."+ missing_value: "The attribute TODO is not set. Please set all attributes required for the calculation."concatenation:single: "or"