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:
Luis Ramos
2020-03-06 12:10:21 +00:00
parent 0c8635403a
commit 7c367da904
2 changed files with 6 additions and 7 deletions

View File

@@ -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, -> {

View File

@@ -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