Skip to content

Commit

Permalink
Merge pull request #12797 from rioug/report-fix-supplier
Browse files Browse the repository at this point in the history
Fix supplier loading on Product & inventory report
  • Loading branch information
filipefurtad0 authored Nov 11, 2024
2 parents 9afd545 + ef6e37e commit 7b67779
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/reporting/frontend_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def my_suppliers
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
Expand Down
5 changes: 0 additions & 5 deletions lib/reporting/reports/xero_invoices/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def query_result

private

def line_item_includes
[:bill_address, :adjustments,
{ line_items: { variant: { product: :supplier } } }]
end

def detail_rows_for_order(order, invoice_number, opts)
rows = []

Expand Down
48 changes: 48 additions & 0 deletions spec/lib/reports/frontend_data_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7b67779

Please sign in to comment.