mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 04:35:45 +08:00
fix: issue changed about version callback
This commit is contained in:
@@ -75,7 +75,7 @@ class Issue < ApplicationRecord
|
||||
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
||||
scope :closed, ->{where(status_id: 5)}
|
||||
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||
after_update :change_versions_count
|
||||
after_save :change_versions_count
|
||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
|
||||
|
||||
def incre_project_common
|
||||
@@ -170,11 +170,25 @@ class Issue < ApplicationRecord
|
||||
end
|
||||
|
||||
def change_versions_count
|
||||
if self.version.present? && self.saved_change_to_status_id?
|
||||
if self.saved_change_to_fixed_version_id?
|
||||
before_version = Version.find_by_id(self.fixed_version_id_before_last_save)
|
||||
Rails.logger.info self.fixed_version_id_before_last_save
|
||||
if before_version.present?
|
||||
Rails.logger.info self.status_id
|
||||
Rails.logger.info self.status_id_before_last_save
|
||||
# 更改前状态为完成 或者 更改前后都为完成状态
|
||||
if self.status_id_before_last_save == 5
|
||||
percent = before_version.issues_count == 0 ? 0.0 : ((before_version.closed_issues_count - 1).to_f / before_version.issues_count)
|
||||
before_version.update_attributes(closed_issues_count: (before_version.closed_issues_count - 1), percent: percent)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.version.present? && (self.saved_change_to_status_id? || self.saved_change_to_fixed_version_id?)
|
||||
if self.status_id == 5
|
||||
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count + 1).to_f / self.version.issues_count)
|
||||
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count + 1), percent: percent)
|
||||
elsif self.status_id_before_last_save == 5
|
||||
elsif self.status_id_before_last_save == 5 && !self.saved_change_to_fixed_version_id?
|
||||
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count - 1).to_f / self.version.issues_count)
|
||||
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count - 1), percent: percent)
|
||||
end
|
||||
@@ -182,7 +196,7 @@ class Issue < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_closed_issues_count_in_project!
|
||||
self.project.decrement!(:closed_issues_count)
|
||||
self.project.decrement!(:closed_issues_count) if self.status_id == 5
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user