anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

change status id depend in def function for level in issue #313

Closed ashrafalzyoud closed 1 year ago

ashrafalzyoud commented 1 year ago

depend in solution for @airtibu in #267

def total_value(from_cf,to_cf,issue_level)

    children_ids = Issue.where(:parent_id =>issue_level.id.to_i).pluck(:id) { |m| m.to_s }

    cfv = CustomValue.where("customized_id IN (?) AND custom_field_id = ?",children_ids, (from_cf)).pluck(:value)

    cv = CustomValue.where("customized_type = ? AND customized_id = ? AND custom_field_id = ?","Issue", issue_level.id.to_i, (to_cf)).first

    cv.value = (cfv.inject(0){|sum,x| sum.to_i + x.to_i }).to_i

    cv.save(:validate => false)
end

# Change the tracker_id number to your bill tracker_id:
if tracker_id==3 && @issue

@company_issue = @issue.parent if @issue.parent
@tender_issue = @company_issue.parent if @company_issue.parent
@budget_issue = @tender_issue.parent if @tender_issue.parent

total_value(1,2,@company_issue) if @company_issue
total_value(2,3,@tender_issue) if @tender_issue
total_value(3,4,@budget_issue) if @budget_issue

end

how i can change status_id for each level when i compare the value of custom field value =0 im try but its not working

def total_value(from_cf,to_cf,issue_level)

    children_ids = Issue.where(:parent_id =>issue_level.id.to_i).pluck(:id) { |m| m.to_s }

    cfv = CustomValue.where("customized_id IN (?) AND custom_field_id = ?",children_ids, (from_cf)).pluck(:value)

    cv = CustomValue.where("customized_type = ? AND customized_id = ? AND custom_field_id = ?","Issue", issue_level.id.to_i, (to_cf)).first

    cv.value = (cfv.inject(0){|sum,x| sum.to_i + x.to_i }).to_i

    cv.save(:validate => false)
end

# Change the tracker_id number to your bill tracker_id:
if tracker_id==3 && @issue

@company_issue = @issue.parent if @issue.parent
@tender_issue = @company_issue.parent if @company_issue.parent
@budget_issue = @tender_issue.parent if @tender_issue.parent

total_value(1,2,@company_issue) if @company_issue
total_value(2,3,@tender_issue) if @tender_issue
total_value(3,4,@budget_issue) if @budget_issue

 if @budget_issue && self.parent&.custom_field_value(293).to_f == 0 
self..status_id=21
self.save.status.values
end
if @tender_issue && self.parent&.custom_field_value(293).to_f == 0 
self.status_id=6
self.save.status.values
end
if @company_issue && self.parent&.custom_field_value(293).to_f == 0 
self.status_id=7
self.save.status.values
end
end
ashrafalzyoud commented 1 year ago

Screenshot_20230427-204834.jpg

AirTibu commented 1 year ago

Hi,

You change status_id in BEFORE_SAVE section:

@issue.status_id=(5)

In AFTER_SAVE section:

@issue.update_columns(status_id: '1')

I hope it helps!

ashrafalzyoud commented 1 year ago

Thx for replying me And we Miss your answers I'm try same your answer before But I want also in each level Subtask Check the cfs[1]=cfs[2] And then update status id @AirTibu