Forums » Development »
Auto-Close parent after his children are closed.
Added by Matt Daemow about 11 years ago
Like in topic.
How to make parent issue autoclose after all his sub-issues are closed/resolved.
Regards.
//Solved
issue_helper
def parent_close
roots = Issue.root
a = Issue.find(roots).descendants.count
b = Issue.find(roots).descendants.where(:status_id == 5).count
if (a = = b)
roots.update_attribute(:status_id, 5)
end
end
issue_controller
before_filter :parent_close, :only =>[:index]
Replies (5)
RE: Auto-Close parent after his children are closed. - Added by Steven Wong about 11 years ago
Nice, could you make a patch or plugin?
Thanks so much.
RE: Auto-Close parent after his children are closed. - Added by Matt Daemow about 11 years ago
nooope, not interested in :P
but little update
def parent_close
Issue.roots.each do |root|
all = root.descendants.count
closed = root.descendants.select{|hash| hash["status_id"] == ((5) || (6))}.count
opened = root.descendants.select{|hash| hash["status_id"] == 1}.count
opened = root.descendants.select{|hash| hash["status_id"] == 3}.count
various = root.descendants.select{|hash| hash["status_id"] == ((2) || (4))}.count
if (all == closed)
root.update_attribute(:status_id, 5)
elsif (all == opened)
root.update_attribute(:status_id, 1)
elsif (all == resolved)
root.update_attribute(:status_id, 3)
elsif (various > 0)
root.update_attribute(:status_id, 1)
end
end
end
cool if someone could refactor it.
Peace.
RE: Auto-Close parent after his children are closed. - Added by Eelco V almost 7 years ago
Can't get it to work. When I copy the 'def parent_close' code into the issues_helper file Redmine won't start anymore...
Redmine version: 3.3.0
RE: Auto-Close parent after his children are closed. - Added by Kun Zhang over 6 years ago
I've did a little hack in issue.rb to resolve this at version: 3.4.4.
# app/models/issue.rb # in method "recalculate_attributes_for" # after line: p.done_ratio = progress.floor # append 5 lines. progress = done / (average * children.count) p.done_ratio = progress.floor status_array = [] children.each{|c| status_array.push(c.status) unless status_array.include?(c.status) } p.status = status_array.first unless status_array.length > 1
RE: Auto-Close parent after his children are closed. - Added by Lukas Profit 12 months ago
Anyone know how to change parent status when only one of child status have example in progress (not all child have in progress, but only one of them)