mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #12797 from rioug/report-fix-supplier
Fix supplier loading on Product & inventory report
This commit is contained in:
@@ -21,8 +21,9 @@ module Reporting
|
||||
end
|
||||
|
||||
def suppliers_of_products_distributed_by(distributors)
|
||||
supplier_ids = Spree::Product.in_distributors(distributors.select('enterprises.id')).
|
||||
select('spree_products.supplier_id')
|
||||
supplier_ids = Spree::Variant.joins(exchange_variants: { exchange: :order_cycle }).
|
||||
where(exchanges: { incoming: false, receiver: distributors } )
|
||||
.select("spree_variants.supplier_id")
|
||||
|
||||
Enterprise.where(id: supplier_ids)
|
||||
end
|
||||
|
||||
@@ -60,11 +60,6 @@ module Reporting
|
||||
|
||||
private
|
||||
|
||||
def line_item_includes
|
||||
[:bill_address, :adjustments,
|
||||
{ line_items: { variant: { product: :supplier } } }]
|
||||
end
|
||||
|
||||
def detail_rows_for_order(order, invoice_number, opts)
|
||||
rows = []
|
||||
|
||||
|
||||
48
spec/lib/reports/frontend_data_spec.rb
Normal file
48
spec/lib/reports/frontend_data_spec.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Reporting::FrontendData do
|
||||
subject { described_class.new(user) }
|
||||
|
||||
let(:user) { create(:user, enterprises: [distributor1, distributor2]) }
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:distributor2) { create(:distributor_enterprise) }
|
||||
|
||||
let(:supplier1) { create(:supplier_enterprise) }
|
||||
let(:supplier2) { create(:supplier_enterprise) }
|
||||
let(:supplier3) { create(:supplier_enterprise) }
|
||||
|
||||
let(:product1) { create(:simple_product, name: "Product Supplier 1", supplier_id: supplier1.id) }
|
||||
let(:product2) { create(:simple_product, name: "Product Supplier 2", supplier_id: supplier2.id) }
|
||||
let(:product3) { create(:simple_product, name: "Product Supplier 3", supplier_id: supplier3.id) }
|
||||
|
||||
let(:order_cycle1) {
|
||||
create(:simple_order_cycle, coordinator: distributor1,
|
||||
distributors: [distributor1],
|
||||
variants: [product1.variants.first, product2.variants.first])
|
||||
}
|
||||
|
||||
let(:order_cycle2) {
|
||||
create(:simple_order_cycle, coordinator: distributor2,
|
||||
distributors: [distributor2],
|
||||
variants: [product3.variants.first])
|
||||
}
|
||||
|
||||
let!(:order1) {
|
||||
create(:order, order_cycle: order_cycle1, distributor: distributor1)
|
||||
}
|
||||
let!(:order2) {
|
||||
create(:order, order_cycle: order_cycle2, distributor: distributor2)
|
||||
}
|
||||
|
||||
describe "#suppliers_of_products_distributed_by" do
|
||||
it "returns supplier of products for the given distributors" do
|
||||
distributors = Enterprise.where(id: [distributor1, distributor2])
|
||||
|
||||
expect(subject.suppliers_of_products_distributed_by(distributors)).to match_array(
|
||||
[supplier1, supplier2, supplier3]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user