mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Adding a small display on the distributor page indicating when the next order cycle is, if any - BugHerd#127
This commit is contained in:
@@ -26,9 +26,14 @@ class OrderCycle < ActiveRecord::Base
|
||||
}
|
||||
|
||||
scope :most_recently_closed, lambda {
|
||||
where('orders_close_at < ?', Time.now).order('orders_close_at DESC')
|
||||
where('order_cycles.orders_close_at < ?', Time.now).order('order_cycles.orders_close_at DESC')
|
||||
}
|
||||
|
||||
scope :soonest_opening, lambda {
|
||||
where('order_cycles.orders_open_at > ?', Time.now).order('order_cycles.orders_open_at ASC')
|
||||
}
|
||||
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
@@ -53,6 +58,9 @@ class OrderCycle < ActiveRecord::Base
|
||||
joins('LEFT OUTER JOIN enterprises ON (enterprises.id = exchanges.sender_id OR enterprises.id = exchanges.receiver_id)')
|
||||
}
|
||||
|
||||
def self.first_opening_for(distributor)
|
||||
with_distributor(distributor).soonest_opening.first
|
||||
end
|
||||
|
||||
def clone!
|
||||
oc = self.dup
|
||||
@@ -116,6 +124,8 @@ class OrderCycle < ActiveRecord::Base
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
# -- Fees
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
= distance_of_time_in_words_to_now OrderCycle.most_recently_closed.first.orders_close_at
|
||||
ago.
|
||||
Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens.
|
||||
|
||||
- if next_oc = OrderCycle.first_opening_for(@enterprise)
|
||||
%p
|
||||
The next order cycle opens in
|
||||
= distance_of_time_in_words_to_now next_oc.orders_open_at
|
||||
|
||||
%p
|
||||
= "Email: #{current_distributor.email}" if current_distributor.email
|
||||
%br/
|
||||
|
||||
@@ -46,24 +46,39 @@ feature %q{
|
||||
page.should have_content 'Your order will be ready on'
|
||||
end
|
||||
|
||||
scenario "when there are no available order cycles" do
|
||||
Timecop.freeze do
|
||||
d = create(:distributor_enterprise, name: 'Green Grass')
|
||||
context "when there are no available order cycles" do
|
||||
let(:d) { create(:distributor_enterprise, name: 'Green Grass') }
|
||||
before do
|
||||
create_enterprise_group_for d
|
||||
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d], orders_close_at: 5.minutes.ago)
|
||||
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
end
|
||||
it "indicates there are no current order cycles" do
|
||||
Timecop.freeze do
|
||||
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d], orders_close_at: 5.minutes.ago)
|
||||
click_link d.name
|
||||
|
||||
page.should have_content "Orders are currently closed for this hub"
|
||||
page.should have_content "The last cycle closed 5 minutes ago."
|
||||
page.should have_content "Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens."
|
||||
page.should have_content d.email
|
||||
page.should have_content d.phone
|
||||
page.should have_content "Orders are currently closed for this hub"
|
||||
page.should have_content "The last cycle closed 5 minutes ago."
|
||||
page.should have_content "Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens."
|
||||
page.should have_content d.email
|
||||
page.should have_content d.phone
|
||||
end
|
||||
end
|
||||
context "displaying future order cycles" do
|
||||
it "should show the time until the next order cycle opens" do
|
||||
create(:simple_order_cycle, name: 'oc 1', distributors: [d], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
|
||||
|
||||
click_link d.name
|
||||
page.should have_content "The next order cycle opens in 10 days"
|
||||
end
|
||||
|
||||
it "should show nothing when there is no next order cycle" do
|
||||
click_link d.name
|
||||
page.should_not have_content "The next order cycle opens"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
scenario "changing order cycle", js: true do
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise, name: 'Green Grass')
|
||||
|
||||
@@ -89,6 +89,14 @@ describe OrderCycle do
|
||||
OrderCycle.most_recently_closed.should == [oc2, oc1]
|
||||
end
|
||||
|
||||
it "finds the soonest opening order cycles" do
|
||||
oc1 = create(:order_cycle, orders_open_at: 1.weeks.from_now)
|
||||
oc2 = create(:order_cycle, orders_open_at: 2.hours.from_now)
|
||||
oc3 = create(:order_cycle, orders_open_at: 1.hour.ago)
|
||||
|
||||
OrderCycle.soonest_opening.should == [oc2, oc1]
|
||||
end
|
||||
|
||||
describe "finding order cycles with a particular distributor" do
|
||||
let(:c) { create(:supplier_enterprise) }
|
||||
let(:d) { create(:distributor_enterprise) }
|
||||
@@ -305,4 +313,17 @@ describe OrderCycle do
|
||||
oc.send(:adjustment_label_for, line_item, enterprise_fee, 'distributor').should == "Bananas - packing fee by distributor Ballantyne"
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding order cycles opening in the future" do
|
||||
it "should give the soonest opening order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
|
||||
OrderCycle.first_opening_for(distributor).should == oc
|
||||
end
|
||||
|
||||
it "should return no order cycle when none are impending" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
OrderCycle.first_opening_for(distributor).should == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user