redmine_custom_workflows icon indicating copy to clipboard operation
redmine_custom_workflows copied to clipboard

how i calculate the total Number of tasks depend the value from KEY/VALUE list

Open ashrafalzyoud opened this issue 4 years ago • 7 comments

i have tow tracker Traker Result id[1] --> cfs [1] tybe integer = total number of Tasks if ( cfs[10] tybe key/value list =A) --> cfs [2] tybe float = total values cfs [20] if ( cfs[10] tybe key/value list =A)

--> cfs [3] tybe integer = total number of Tasks if ( cfs[10] tybe key/value list =B) --> cfs [4] tybe float = total values cfs [20] if ( cfs[10] tybe key/value list =B)

Traker company [2] CFS [10] tybe (KEY/VALUE LIST ) the values A,B,C Rate the company CFS[20] TYBE FLOAT = The value of the bill

like this if i have in company total Tasks 950, total bill 1000$ Traker Result its will look cfs[1] = 400 number of Tasks cfs[2]= 300 $ total bills

cfs[3]= 550 number of Tasks cfs[4]= 700 $ total bills

i hope if u can help me

ashrafalzyoud avatar Aug 13 '20 16:08 ashrafalzyoud

cfs[1] = Issue.where(traker_id: 2,custom_field_id: 10, value: "A").all.size cfs[2]= total cfs[20(traker_id: 2,custom_field_id: 10, value: "A")].to_f.round(2)

cfs[3] = Issue.where(traker_id: 2,custom_field_id: 10, value: "B").all.size cfs[4]= total cfs[20(traker_id: 2,custom_field_id: 10, value: "B")].to_f.round(2)

ashrafalzyoud avatar Aug 13 '20 20:08 ashrafalzyoud

@AirTibu
I hope you will help me with appreciation and respect

ashrafalzyoud avatar Aug 13 '20 21:08 ashrafalzyoud

Hi,

There some contradictions in your first and second post, but as far as I understand, you need this code:

BEFORE SAVE

if tracker_id ==2
    @cf_key_value = CustomFieldEnumeration.where(:id=> custom_field_value(10).to_s,:custom_field_id => '10').first.to_s
    @issues_id_list = Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10'AND value = '#{custom_field_value(10).to_s}'").pluck(:id)
    @float_value = CustomValue.where("customized_id IN (#{@issues_id_list.join(',').to_s}) AND custom_field_id = '20'").pluck(:value)
    
    if @cf_key_value =="A"
        @issue.custom_field_values = { '1' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '2' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    elsif @cf_key_value =="B"
        @issue.custom_field_values = { '3' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '4' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    end
end

If you submit (save) an issue which is in tracker(2), then the code running. If I understand well, all custom_field is in tracker(2). Is it right?

But I'm pretty sure, that is not good solution, because in this case you should use hard coded company names.

In your second post you refer to tracker_id == 2 at all fields. Is it right?

cfs[1] = Issue.where( traker_id: 2 ,custom_field_id: 10, value: "A").all.size cfs[2]= total cfs[20( traker_id: 2 ,custom_field_id: 10, value: "A")].to_f.round(2) cfs[3] = Issue.where( traker_id: 2 ,custom_field_id: 10, value: "B").all.size cfs[4]= total cfs[20( traker_id: 2,custom_field_id: 10, value: "B")].to_f.round(2)

AirTibu avatar Aug 16 '20 21:08 AirTibu

when i Execute this formula tracker_id=2 its configure for three project ids( 1,2,3) my question is, the effect formula only for what im choose project id (1)

ashrafalzyoud avatar Sep 16 '20 20:09 ashrafalzyoud

Hi,

In this case you need this code:



if tracker_id ==2 && project_id==1
    @cf_key_value = CustomFieldEnumeration.where(:id=> custom_field_value(10).to_s,:custom_field_id => '10').first.to_s
    @issues_id_list = Issue.joins(:custom_values).where("tracker_id = '2' AND project_id = '1' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").pluck(:id)
    @float_value = CustomValue.where("customized_id IN (#{@issues_id_list.join(',').to_s}) AND custom_field_id = '20'").pluck(:value)
    
    if @cf_key_value =="A"
        @issue.custom_field_values = { '1' => Issue.joins(:custom_values).where("tracker_id = '2' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '2' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    elsif @cf_key_value =="B"
        @issue.custom_field_values = { '3' => Issue.joins(:custom_values).where("tracker_id = '2' AND project_id='1' AND custom_field_id = '10' AND value = '#{custom_field_value(10).to_s}'").all.size.to_s }
        @issue.custom_field_values = { '4' => @float_value.inject { |sum, n| sum.to_f + n.to_f }.round(2).to_f }
    end
end


AirTibu avatar Sep 16 '20 22:09 AirTibu

@float_value sum just only for tracker_id ==2 && project_id==1 or i will do somthings??

ashrafalzyoud avatar Sep 16 '20 23:09 ashrafalzyoud

@AirTibu #321

ashrafalzyoud avatar Sep 06 '23 23:09 ashrafalzyoud