Permalink
Browse files

Added scope to ensure we only display products of the intended campaign.

  • Loading branch information...
Aquaj committed Jan 24, 2019
1 parent 5140ea4 commit cc85f06ecc4d5fece362684334d7e2c7a92cc97a
Showing with 8 additions and 1 deletion.
  1. +7 −0 app/models/product.rb
  2. +1 −1 config/aggregators/land_parcel_register.xml
@@ -228,6 +228,13 @@ class Product < Ekylibre::Record::Base

scope :generic_supports, -> { where(type: %w[Animal AnimalGroup Plant LandParcel Equipment EquipmentFleet]) }

scope :with_campaign, lambda { |campaign|
through_production = joins(activity_production: :campaign).where("campaigns.id = #{campaign.id}").select(:id)
through_productions = joins(activity_productions: :campaigns).where("campaigns.id = #{campaign.id}").select(:id)
where(arel_table[:id].in(through_productions.arel)
.or(arel_table[:id].in(through_production.arel)))
}

scope :supports_of_campaign, lambda { |campaign|
joins(:supports).merge(ActivityProduction.of_campaign(campaign))
}
@@ -14,7 +14,7 @@
<!-- looking for all CultivableZone in current campaign -->
<sections for="zone" in="CultivableZone.all.reorder(:work_number)" of-type="record">
<title name="name" of="zone"/>
<variable name="targets" value="Product.of_variety(:plant, :land_parcel).shape_intersecting(zone.shape)"/>
<variable name="targets" value="Product.of_variety(:plant, :land_parcel).shape_intersecting(zone.shape).with_campaign(campaign)"/>
<property name="work_number" of="zone"/>
<property name="uuid" of="zone"/>
<property name="islet_number" if="CapIslet.of_campaign(campaign).shape_intersecting(zone.shape)" value="CapIslet.of_campaign(campaign).shape_intersecting(zone.shape).pluck(:islet_number).to_sentence"/>

0 comments on commit cc85f06

Please sign in to comment.