anteo / redmine_custom_workflows

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

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

Open ashrafalzyoud opened 3 years ago

ashrafalzyoud commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

AirTibu commented 3 years ago

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)

ashrafalzyoud commented 3 years ago

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)

AirTibu commented 3 years ago

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
ashrafalzyoud commented 3 years ago

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

ashrafalzyoud commented 10 months ago

@AirTibu #321