From ffc2fed9b5174f759c227df6202bb8cead34e746 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 20 Aug 2024 16:43:22 +1000 Subject: [PATCH 1/2] Remove unused code --- lib/reporting/reports/xero_invoices/base.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/reporting/reports/xero_invoices/base.rb b/lib/reporting/reports/xero_invoices/base.rb index 49d9fad4a65..ae5a1eb5dec 100644 --- a/lib/reporting/reports/xero_invoices/base.rb +++ b/lib/reporting/reports/xero_invoices/base.rb @@ -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 = [] From ef6e37e7cabda8400d6d8427ce1d3f72942f2f90 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 20 Aug 2024 16:43:58 +1000 Subject: [PATCH 2/2] Fix `suppliers_of_products_distributed_by` Plus spec Left over from product refactor, it was missed because it's not covered by unit or integration test --- lib/reporting/frontend_data.rb | 5 +-- spec/lib/reports/frontend_data_spec.rb | 48 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 spec/lib/reports/frontend_data_spec.rb diff --git a/lib/reporting/frontend_data.rb b/lib/reporting/frontend_data.rb index 09eda3782ff..5a1152d4a2d 100644 --- a/lib/reporting/frontend_data.rb +++ b/lib/reporting/frontend_data.rb @@ -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 diff --git a/spec/lib/reports/frontend_data_spec.rb b/spec/lib/reports/frontend_data_spec.rb new file mode 100644 index 00000000000..42ba84e92fa --- /dev/null +++ b/spec/lib/reports/frontend_data_spec.rb @@ -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