mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Adapt LineItem#supplied_by_any scope to include deleted variants and deleted products (both not included in the respective default scopes) and use it in Permissions::Order so that variants of deleted products are seen in reports
This commit is contained in:
@@ -47,8 +47,11 @@ Spree::LineItem.class_eval do
|
||||
}
|
||||
|
||||
scope :supplied_by_any, lambda { |enterprises|
|
||||
joins(:product).
|
||||
where('spree_products.supplier_id IN (?)', enterprises)
|
||||
joins("LEFT OUTER JOIN spree_variants
|
||||
ON spree_line_items.variant_id = spree_variants.id
|
||||
LEFT OUTER JOIN spree_products
|
||||
ON spree_variants.product_id = spree_products.id").
|
||||
where("spree_products.supplier_id IN (?)", enterprises)
|
||||
}
|
||||
|
||||
scope :with_tax, -> {
|
||||
|
||||
@@ -90,11 +90,7 @@ module Permissions
|
||||
# Any from visible orders, where the product is produced by one of my managed producers
|
||||
def produced_line_items
|
||||
Spree::LineItem.where(order_id: visible_orders.select("DISTINCT spree_orders.id")).
|
||||
joins(:product).
|
||||
where(spree_products:
|
||||
{
|
||||
supplier_id: @permissions.managed_enterprises.is_primary_producer.select("enterprises.id")
|
||||
})
|
||||
supplied_by_any(@permissions.managed_enterprises.is_primary_producer.select("enterprises.id"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user