Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of interventions doesn't appear in backend/activity_productions#show view #528

Closed
EmmaDorie opened this issue Mar 31, 2016 · 18 comments
Assignees
Milestone

Comments

@EmmaDorie
Copy link
Contributor

The list of interventions link to one production doesn't appear in the production view.
interventions_list

@EmmaDorie EmmaDorie changed the title List of interventions doesn't appear. List of interventions doesn't appear Mar 31, 2016
@burisu burisu modified the milestone: 2.0.0 Apr 2, 2016
@burisu burisu changed the title List of interventions doesn't appear List of interventions doesn't appear in backend/activity_productions#show view Apr 26, 2016
@ionosphere
Copy link
Member

The problem seems to be link with heritage in Rails.

For example, the scope :of_generic_role in InterventionParameter

scope :of_generic_role, lambda { |role|
    role = role.to_s
    unless %w(doer input output target tool).include?(role)
      raise ArgumentError, "Invalid role: #{role}"
    end
    where(type: "Intervention#{role.camelize}")
  }

produce

SELECT  "interventions".* FROM "interventions" 
WHERE "interventions"."id" 
IN (SELECT "intervention_parameters"."intervention_id" FROM "intervention_parameters" 
WHERE "intervention_parameters"."type" 
IN ('InterventionProductParameter') AND "intervention_parameters"."type" = 'InterventionOutput' AND "intervention_parameters"."product_id" = 586)  
ORDER BY "interventions"."id"
ASC LIMIT 1

the problem is link to WHERE "intervention_parameters"."type"
IN ('InterventionProductParameter') because all the childs are missing.

@burisu
Copy link
Collaborator

burisu commented May 3, 2016

From what line did you call of_generic_role scope?

After some tests, I can't reproduce your SQL query:

pry(main)> InterventionProductParameter.of_generic_role(:target)
  InterventionProductParameter Load (0.4ms)  SELECT "intervention_parameters".* FROM "intervention_parameters" WHERE "intervention_parameters"."type" IN ('InterventionProductParameter', 'InterventionTarget', 'InterventionAgent', 'InterventionDoer', 'InterventionTool') AND "intervention_parameters"."type" = $1  [["type", "InterventionTarget"]]

Or:

 pry(main)> i = Intervention.first
 pry(main)> i.product_parameters
  InterventionProductParameter Load (0.6ms)  SELECT "intervention_parameters".* FROM "intervention_parameters" WHERE "intervention_parameters"."type" IN ('InterventionProductParameter', 'InterventionTarget', 'InterventionAgent', 'InterventionDoer', 'InterventionTool') AND "intervention_parameters"."intervention_id" = 9

Or:

[8] pry(main)> Intervention.with_generic_cast(:target, Plant.first)
  Plant Load (0.8ms)  SELECT  "products".* FROM "products" WHERE "products"."type" IN ('Plant')  ORDER BY "products"."id" ASC LIMIT 1
  Intervention Load (0.5ms)  SELECT "interventions".* FROM "interventions" WHERE "interventions"."id" IN (SELECT "intervention_parameters"."intervention_id" FROM "intervention_parameters" WHERE "intervention_parameters"."type" IN ('InterventionProductParameter', 'InterventionTarget', 'InterventionAgent', 'InterventionDoer', 'InterventionTool') AND "intervention_parameters"."type" = $1 AND "intervention_parameters"."product_id" = $2)  [["type", "InterventionTarget"], ["product_id", 90]]

@ionosphere
Copy link
Member

The last one.
in my case, i haven't got exactly the same thing near WHERE "intervention_parameters"."type" IN ('InterventionProductParameter')

[7] pry(main)> i = Intervention.with_generic_cast(:output, p)
  Intervention Load (0.4ms)  SELECT "interventions".* FROM "interventions" WHERE "interventions"."id" IN (SELECT "intervention_parameters"."intervention_id" FROM "intervention_parameters" WHERE "intervention_parameters"."type" IN ('InterventionProductParameter') AND "intervention_parameters"."type" = $1 AND "intervention_parameters"."product_id" = $2)  [["type", "InterventionOutput"], ["product_id", 537]]
=> []

@burisu
Copy link
Collaborator

burisu commented May 4, 2016

On my side, I got that:

[10] pry(main)> i = Intervention.with_generic_cast(:target, Plant.first)
  Plant Load (0.5ms)  SELECT  "products".* FROM "products" WHERE "products"."type" IN ('Plant')  ORDER BY "products"."id" ASC LIMIT 1
  Intervention Load (0.4ms)  SELECT "interventions".* FROM "interventions" WHERE "interventions"."id" IN (SELECT "intervention_parameters"."intervention_id" FROM "intervention_parameters" WHERE "intervention_parameters"."type" IN ('InterventionProductParameter', 'InterventionOutput', 'InterventionInput') AND "intervention_parameters"."type" = $1 AND "intervention_parameters"."product_id" = $2)  [["type", "InterventionTarget"], ["product_id", 90]]

@burisu burisu closed this as completed May 4, 2016
@burisu burisu reopened this May 4, 2016
@burisu
Copy link
Collaborator

burisu commented May 4, 2016

Maybe you have a example in the app, in the terminal if you load wanted models you'll have what you want.

@Nyxelio
Copy link
Contributor

Nyxelio commented Jun 3, 2016

I agree it works if models are loaded.

@Nyxelio Nyxelio closed this as completed Jun 3, 2016
@EmmaDorie
Copy link
Contributor Author

The issue still exists in v 2.0.0. rc23

@Nicephore17
Copy link

Nicephore17 commented Jun 16, 2016

The issue still exists in v.2.0.0rc24.
FYI @clegris

@Nyxelio
Copy link
Contributor

Nyxelio commented Jun 23, 2016

It occurs when you start the server and you call a product show page. The associated interventions don't appear because of malformed sql. This is due to STI of InterventionProductParameter model. To manually force inheritance, you need to go to the interventions page and come back to product show page.

@Nyxelio
Copy link
Contributor

Nyxelio commented Jun 24, 2016

Fixed by 1abdaf0 and b2ec808

@Nyxelio Nyxelio closed this as completed Jun 24, 2016
@Nicephore17
Copy link

Sorry but it is not working with v2.0.0rc24 on SaaS.
Same problem on demo.

:(

@burisu @Nyxelio @ionosphere

@PH64 PH64 reopened this Jul 4, 2016
@Nicephore17
Copy link

Nicephore17 commented Jul 4, 2016

I'm investigation. It works on some production: https://demo.ekylibre.farm/backend/activity_productions/51

@Nicephore17
Copy link

Does it take only intervention made in 2016 as there is no year selector ??

@Nicephore17
Copy link

I try to create 2 interventions today (to be in 2016 then) one targeting the crop and the other targeting the parcel. None of them show up in Intervention list.

@burisu
Copy link
Collaborator

burisu commented Jul 4, 2016

No filters on campaign (https://github.com/ekylibre/ekylibre/blob/2.0.0.rc25/app/controllers/backend/activity_productions_controller.rb#L34).
You need to distribute your intervention targets on yours activity_productions. See "Distribute" button on https://demo.ekylibre.farm/backend/campaigns/current or directly on https://demo.ekylibre.farm/backend/target_distributions/distribute

@Nicephore17
Copy link

OK. Working then. Can you explain what it is not automatic ?

May I warn you: with many intervention, it is hard to read. Will probably be better with the jalons or with consolidating intervention by type (= one graph entry for all fertilization).

costchart

(My price a not all set so human work can seems to be really "cheap").
Intervention list so not show individual price like in production/interventions.

Anyway: thank you !

@burisu
Copy link
Collaborator

burisu commented Jul 4, 2016

It's not automatic for now, but it will be. As long as, interventions cannot set these distributions automatically, we'll need the user to do that distribution manually

@Nicephore17
Copy link

The pre-selection look good I had just to validate it. I will check consistency but it looks fine.

@PH64 PH64 closed this as completed Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants