diff --git a/config/locales/en.yml b/config/locales/en.yml index 1eeea38..5d24fb0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -104,7 +104,7 @@ en: permission_view_customer_appointments: "View customer appointments" text_default_tracker_info: "Pre-selected for each proposed issue. Leave blank to use the project's first tracker." text_estimate_issue_fields_info: "Entered once and applied to every created issue whose tracker uses the field. Fields marked * are required by the selected trackers." - text_estimate_issues_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. Edit anything before creating." - text_estimate_issues_template_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. A template supplies the issue's description." + text_estimate_issues_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. Edit anything before creating. Issues created together are related to each other." + text_estimate_issues_template_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. A template supplies the issue's description. Issues created together are related to each other." text_estimate_item_codes_info: "QBO item names that can become issues, one per line (e.g. Labor, Alignments). Matches the full item name or any part of a Category:Item name, ignoring case." title_customer_appointments: Customer Appointments \ No newline at end of file diff --git a/lib/redmine_qbo_calendar/estimate_issue_builder.rb b/lib/redmine_qbo_calendar/estimate_issue_builder.rb index c1549c5..d647dff 100644 --- a/lib/redmine_qbo_calendar/estimate_issue_builder.rb +++ b/lib/redmine_qbo_calendar/estimate_issue_builder.rb @@ -16,6 +16,7 @@ module RedmineQboCalendar # - Subject = the line's description; estimated hours = the line's quantity # - Lines already turned into issues are shown but can't be created again # - Creation is all-or-nothing: if any issue fails validation, none are saved + # - Issues created together are all related to each other class EstimateIssueBuilder include Redmine::I18n @@ -105,6 +106,8 @@ module RedmineQboCalendar issue: issue ) end + + relate_issues(built.map(&:last)) end @errors.any? ? [] : built.map(&:last) @@ -154,6 +157,20 @@ module RedmineQboCalendar key.to_s end + # Relates every issue in the batch to every other one ("Related to"), since they're work on the + # same estimate done at the same time. New issues have no open journal, so this adds no history + # entries and sends no "issue updated" emails. A failed relation is logged, not fatal. + def relate_issues(issues) + issues.combination(2).each do |issue_from, issue_to| + relation = IssueRelation.new(issue_from: issue_from, issue_to: issue_to, + relation_type: IssueRelation::TYPE_RELATES) + next if relation.save + + Rails.logger.warn "[EstimateIssueBuilder] Could not relate ##{issue_from.id} and ##{issue_to.id}: " \ + "#{relation.errors.full_messages.join(', ')}" + end + end + def build_issue(proposal, row, project, author, allowed_trackers, custom_field_values) issue = Issue.new(project: project, author: author) issue.tracker = allowed_trackers.detect { |t| t.id == row['tracker_id'].to_i }