Skip to content

Commit

Permalink
Merge pull request #7015 from andrewpbrett/shopfront-producers
Browse files Browse the repository at this point in the history
Only show primary producers on shopfront list of producers (fix #4218)
  • Loading branch information
Matt-Yorkley committed Mar 17, 2021
2 parents 8503e3c + 0125b5f commit 751b934
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def relatives

def plus_relatives_and_oc_producers(order_cycles)
oc_producer_ids = Exchange.in_order_cycle(order_cycles).incoming.pluck :sender_id
Enterprise.relatives_of_one_union_others(id, oc_producer_ids | [id])
Enterprise.is_primary_producer.relatives_of_one_union_others(id, oc_producer_ids | [id])
end

def relatives_including_self
Expand Down
15 changes: 15 additions & 0 deletions spec/models/enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,19 @@ def should_have_enterprise_relationship(opts = {})
end
end
end

describe "#plus_relatives_and_oc_producers" do
it "does not find non-produders " do
supplier = create(:supplier_enterprise)
distributor = create(:distributor_enterprise, is_primary_producer: false)
product = create(:product)
order_cycle = create(
:simple_order_cycle,
suppliers: [supplier],
distributors: [distributor],
variants: [product.master]
)
expect(distributor.plus_relatives_and_oc_producers(order_cycle)).to eq([supplier])
end
end
end

0 comments on commit 751b934

Please sign in to comment.