mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Order cycle-aware pickup time
This commit is contained in:
@@ -94,6 +94,14 @@ class OrderCycle < ActiveRecord::Base
|
||||
self.variants.include? variant
|
||||
end
|
||||
|
||||
def exchange_for_distributor(distributor)
|
||||
exchanges.outgoing.to_enterprises([distributor]).first
|
||||
end
|
||||
|
||||
def pickup_time_for(distributor)
|
||||
exchange_for_distributor(distributor).andand.pickup_time || distributor.next_collection_at
|
||||
end
|
||||
|
||||
|
||||
# -- Fees
|
||||
def create_adjustments_for(line_item)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
/ replace_contents "[data-hook='distributor-details']"
|
||||
%h2= distributor.name
|
||||
= distributor.distributor_info.andand.html_safe
|
||||
.next-collection-at= distributor.next_collection_at
|
||||
.next-collection-at
|
||||
- if current_order_cycle
|
||||
= current_order_cycle.pickup_time_for(distributor)
|
||||
- else
|
||||
= distributor.next_collection_at
|
||||
|
||||
@@ -27,7 +27,11 @@ Payment Details
|
||||
Collection / Delivery Details
|
||||
============================================================
|
||||
<%= raw strip_html @order.distributor.distributor_info %>
|
||||
<% if @order.order_cycle %>
|
||||
<%= @order.order_cycle.pickup_time_for(@order.distributor) %>
|
||||
<% else %>
|
||||
<%= @order.distributor.next_collection_at %>
|
||||
<% end %>
|
||||
|
||||
|
||||
Thanks for your support.
|
||||
|
||||
@@ -50,7 +50,7 @@ feature "enterprises distributor info as rich text" do
|
||||
page.should have_selector "tr[data-hook='distributor_info'] td", text: 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
|
||||
end
|
||||
|
||||
scenario "viewing distributor info", js: true do
|
||||
scenario "viewing distributor info with product distribution", js: true do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
d = create(:distributor_enterprise, distributor_info: 'Chu ge sai yubi dan <strong>bisento</strong> tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
|
||||
@@ -84,6 +84,46 @@ feature "enterprises distributor info as rich text" do
|
||||
email.body.should =~ /Thursday 2nd May/
|
||||
end
|
||||
|
||||
scenario "viewing distributor info with order cycle distribution", js: true do
|
||||
set_feature_toggle :order_cycles, true
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
d = create(:distributor_enterprise, name: 'Green Grass', distributor_info: 'Chu ge sai yubi dan <strong>bisento</strong> tobi ashi yubi ge omote.', next_collection_at: 'Thursday 2nd May')
|
||||
p = create(:product)
|
||||
oc = create(:simple_order_cycle, distributors: [d], variants: [p.master])
|
||||
ex = oc.exchanges.outgoing.last
|
||||
ex = Exchange.find ex.id
|
||||
ex.pickup_time = 'Friday 4th May'
|
||||
ex.save!
|
||||
|
||||
setup_shipping_details d
|
||||
|
||||
login_to_consumer_section
|
||||
click_link 'Green Grass'
|
||||
|
||||
# -- Product details page
|
||||
click_link p.name
|
||||
within '#product-distributor-details' do
|
||||
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
|
||||
page.should have_content 'Friday 4th May'
|
||||
end
|
||||
|
||||
# -- Checkout
|
||||
click_button 'Add To Cart'
|
||||
click_link 'Checkout'
|
||||
within 'fieldset#shipping' do
|
||||
page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.'
|
||||
page.should have_content 'Friday 4th May'
|
||||
end
|
||||
|
||||
# -- Purchase email
|
||||
complete_purchase_from_checkout_address_page
|
||||
wait_until { ActionMailer::Base.deliveries.length == 1 }
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
email.body.should =~ /Chu ge sai yubi dan bisento tobi ashi yubi ge omote./
|
||||
email.body.should =~ /Friday 4th May/
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def setup_shipping_details(distributor)
|
||||
|
||||
@@ -149,11 +149,11 @@ describe OrderCycle do
|
||||
@d1 = create(:enterprise)
|
||||
@d2 = create(:enterprise)
|
||||
|
||||
e0 = create(:exchange,
|
||||
@e0 = create(:exchange,
|
||||
order_cycle: @oc, sender: create(:enterprise), receiver: @oc.coordinator)
|
||||
e1 = create(:exchange,
|
||||
@e1 = create(:exchange,
|
||||
order_cycle: @oc, sender: @oc.coordinator, receiver: @d1)
|
||||
e2 = create(:exchange,
|
||||
@e2 = create(:exchange,
|
||||
order_cycle: @oc, sender: @oc.coordinator, receiver: @d2)
|
||||
|
||||
@p0 = create(:product)
|
||||
@@ -161,11 +161,11 @@ describe OrderCycle do
|
||||
@p2 = create(:product)
|
||||
@p2_v = create(:variant, product: @p2)
|
||||
|
||||
e0.variants << @p0.master
|
||||
e1.variants << @p1.master
|
||||
e1.variants << @p2.master
|
||||
e1.variants << @p2_v
|
||||
e2.variants << @p1.master
|
||||
@e0.variants << @p0.master
|
||||
@e1.variants << @p1.master
|
||||
@e1.variants << @p2.master
|
||||
@e1.variants << @p2_v
|
||||
@e2.variants << @p1.master
|
||||
end
|
||||
|
||||
it "reports on the variants exchanged" do
|
||||
@@ -185,6 +185,34 @@ describe OrderCycle do
|
||||
end
|
||||
end
|
||||
|
||||
describe "exchanges" do
|
||||
before(:each) do
|
||||
@oc = create(:simple_order_cycle)
|
||||
|
||||
@d1 = create(:enterprise)
|
||||
@d2 = create(:enterprise, next_collection_at: '2-8pm Friday')
|
||||
|
||||
@e0 = create(:exchange, order_cycle: @oc, sender: create(:enterprise), receiver: @oc.coordinator)
|
||||
@e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, pickup_time: '5pm Tuesday')
|
||||
@e2 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d2, pickup_time: nil)
|
||||
end
|
||||
|
||||
it "finds the exchange for a distributor" do
|
||||
@oc.exchange_for_distributor(@d1).should == @e1
|
||||
@oc.exchange_for_distributor(@d2).should == @e2
|
||||
end
|
||||
|
||||
describe "finding pickup time for a distributor" do
|
||||
it "looks up the pickup time on the exchange when present" do
|
||||
@oc.pickup_time_for(@d1).should == '5pm Tuesday'
|
||||
end
|
||||
|
||||
it "returns the distributor's default collection time otherwise" do
|
||||
@oc.pickup_time_for(@d2).should == '2-8pm Friday'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "clones itself" do
|
||||
oc = create(:order_cycle)
|
||||
occ = oc.clone!
|
||||
|
||||
Reference in New Issue
Block a user