Merge branch 'master' of github.com:eaterprises/openfoodweb

This commit is contained in:
alexs
2013-08-21 10:50:08 +10:00
13 changed files with 46 additions and 13 deletions

View File

@@ -49,7 +49,7 @@ module Admin
end
def collection
super.order('enterprise_id', 'fee_type', 'name')
EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
end
end
end

View File

@@ -13,6 +13,13 @@ class EnterpriseFee < ActiveRecord::Base
scope :for_enterprise, lambda { |enterprise| where(enterprise_id: enterprise) }
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped
else
where('enterprise_id IN (?)', user.enterprises)
end
}
def self.clear_all_adjustments_for(line_item)
line_item.order.adjustments.where(originator_type: 'EnterpriseFee', source_id: line_item, source_type: 'Spree::LineItem').destroy_all

View File

@@ -24,7 +24,7 @@ class OrderCycle < ActiveRecord::Base
if user.has_spree_role?('admin')
scoped
else
where('coordinator_id IN (?)', user.enterprises.map {|enterprise| enterprise.id })
where('coordinator_id IN (?)', user.enterprises)
end
}

View File

@@ -40,7 +40,10 @@ class AbilityDecorator
can [:create], OrderCycle
can [:index, :read], EnterpriseFee
can [:admin, :index, :read], EnterpriseFee do |enterprise_fee|
user.enterprises.include? enterprise_fee.enterprise
end
can [:admin, :index, :read, :create, :edit, :update], ExchangeVariant
can [:admin, :index, :read, :create, :edit, :update], Exchange
can [:admin, :index, :read, :create, :edit, :update], ExchangeFee

View File

@@ -20,7 +20,7 @@ Spree::Order.class_eval do
if user.has_spree_role?('admin')
scoped
else
where('distributor_id IN (?)', user.enterprises.map {|enterprise| enterprise.id })
where('distributor_id IN (?)', user.enterprises)
end
}

View File

@@ -10,7 +10,7 @@ Spree::PaymentMethod.class_eval do
if user.has_spree_role?('admin')
scoped
else
where('distributor_id IN (?)', user.enterprises.map {|enterprise| enterprise.id })
where('distributor_id IN (?)', user.enterprises)
end
}
end
@@ -18,4 +18,4 @@ end
# Ensure that all derived classes also allow distributor_id
Spree::Gateway.providers.each do |p|
p.attr_accessible :distributor_id
end
end

View File

@@ -61,7 +61,7 @@ Spree::Product.class_eval do
if user.has_spree_role?('admin')
scoped
else
where('supplier_id IN (?)', user.enterprises.map {|enterprise| enterprise.id })
where('supplier_id IN (?)', user.enterprises)
end
}

View File

@@ -0,0 +1,8 @@
/ replace_contents 'tfoot#order-charges'
- checkout_adjustments_for_summary(@order).each do |adjustment|
%tr.total
%td{:colspan => "4"}
%strong= adjustment.label
%td.total
%span= adjustment.display_amount.to_html

View File

@@ -11,7 +11,7 @@ Order for: <%= @order.bill_address.full_name %>
<% end %>
============================================================
Subtotal: <%= @order.display_item_total %>
<% @order.adjustments.eligible.each do |adjustment| %>
<% checkout_adjustments_for_summary(@order).each do |adjustment| %>
<%= raw(adjustment.label) %> <%= adjustment.display_amount %>
<% end %>
Order Total: <%= @order.display_total %>

View File

@@ -7,6 +7,8 @@ module EnterprisesDistributorInfoRichTextFeature
initializer 'enterprises_distributor_info_rich_text_feature.mailer', :after => :load_config_initializers do |app|
if OpenFoodWeb::FeatureToggle.enabled? :enterprises_distributor_info_rich_text
::Spree::OrderMailer.class_eval do
helper CheckoutHelper
def confirm_email(order, resend = false)
find_order(order)
subject = (resend ? "[#{t(:resend).upcase}] " : '')

View File

@@ -349,7 +349,7 @@ feature %q{
let(:supplier2) { create(:supplier_enterprise, name: 'Another Supplier') }
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') }
let!(:distributor1_fee) { create(:enterprise_fee, enterprise: distributor1, name: 'First Distributor Fee') }
before(:each) do
product = create(:product, supplier: supplier1)
product.distributors << distributor1
@@ -384,6 +384,8 @@ feature %q{
click_button 'Add supplier'
select 'First Distributor', from: 'order_cycle_coordinator_id'
click_button 'Add coordinator fee'
select 'First Distributor Fee', from: 'order_cycle_coordinator_fee_0_id'
select 'First Distributor', from: 'new_distributor_id'
click_button 'Add distributor'

View File

@@ -63,7 +63,8 @@ feature %q{
@zone = create(:zone)
c = Spree::Country.find_by_name('Australia')
Spree::ZoneMember.create(:zoneable => c, :zone => @zone)
create(:shipping_method, zone: @zone)
sm = create(:shipping_method, zone: @zone, calculator: Spree::Calculator::FlatRate.new)
sm.calculator.set_preference(:amount, 0); sm.calculator.save!
@payment_method_all = create(:payment_method, :name => 'Cheque payment method', :description => 'Cheque payment method') #valid for any distributor
@payment_method_distributor = create(:payment_method, :name => 'Edible Garden payment method', :distributor => @distributor)
@@ -324,13 +325,19 @@ feature %q{
click_checkout_continue_button
# -- Checkout: Order complete
page.should have_content('Your order has been processed successfully')
page.should have_content(@payment_method_all.description)
page.should have_content 'Your order has been processed successfully'
page.should have_content @payment_method_all.description
page.should have_selector 'tfoot#order-charges tr.total td', text: 'Distribution'
page.should have_selector 'tfoot#order-charges tr.total td', text: '$3.00'
# page.should have_content('Your order will be available on:')
# page.should have_content('On Tuesday, 4 PM')
# page.should have_content('12 Bungee Rd, Carion')
# -- Checkout: Email
email = ActionMailer::Base.deliveries.last
email.body.should =~ /Distribution \$3.00/
end

View File

@@ -136,6 +136,10 @@ module Spree
it "should be able to create OrderCycles" do
should have_ability([:create], for: OrderCycle)
end
it "should be able to read EnterpriseFees" do
should have_ability([:admin, :index, :read], for: EnterpriseFee)
end
end
context 'Enterprise manager' do
@@ -160,4 +164,4 @@ module Spree
end
end
end
end
end