Auto-Close parent after his children are closed.

Added by Matt Daemow over 4 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 (3)

RE: Auto-Close parent after his children are closed. - Added by Steven Wong over 4 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 over 4 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 about 1 month 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

(1-3/3)