mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-12 18:36:49 +00:00
Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cb5ac95ff | ||
|
|
076c64f7b0 | ||
|
|
580486a347 | ||
|
|
9a9bef5304 | ||
|
|
b4120b1028 | ||
|
|
a15f96aa68 | ||
|
|
0f68ddcf01 | ||
|
|
5f07df9316 | ||
|
|
9e4edd5da0 | ||
|
|
80159e1ea7 | ||
|
|
3d2572c628 | ||
|
|
3a116dc13d | ||
|
|
c2133d70ac | ||
|
|
a7a8b8490b | ||
|
|
8748a65031 | ||
|
|
6d84cf7613 | ||
|
|
13d6f7213e | ||
|
|
d89945bbb2 | ||
|
|
78bdbcbe6f | ||
|
|
682c09f516 | ||
|
|
34588e6141 | ||
|
|
d927906934 | ||
|
|
58d227e76a | ||
|
|
fb9f59213f | ||
|
|
f8c2c8bbed | ||
|
|
7dd42b7feb | ||
|
|
1b89331aa4 | ||
|
|
309179096b | ||
|
|
9d5c127f0d | ||
|
|
a8f4178894 | ||
|
|
f03d9b66f0 | ||
|
|
b9a072b61a | ||
|
|
1d1c27701d | ||
|
|
5dcba7403b | ||
|
|
926440a978 | ||
|
|
9b32579bd6 | ||
|
|
5ac904005b | ||
|
|
077098e6c1 | ||
|
|
04d8648c6d | ||
|
|
4c2debba7e | ||
|
|
abe3feb996 | ||
|
|
c700d9e71b | ||
|
|
ff24149195 | ||
|
|
03610c93de | ||
|
|
c5941d6cb5 | ||
|
|
773adca838 | ||
|
|
13317347bb | ||
|
|
f960cc44ba | ||
|
|
a9293709d8 | ||
|
|
a3042118c7 | ||
|
|
ede4649fbf | ||
|
|
4dd5e12968 | ||
|
|
d74591afe6 | ||
|
|
09b60908b8 | ||
|
|
d1b9ce92f6 | ||
|
|
784969097d | ||
|
|
15e91f7743 | ||
|
|
c46019d68c | ||
|
|
aa336d9b9f | ||
|
|
ff029b8903 | ||
|
|
a362dd5161 | ||
|
|
51850be83e | ||
|
|
41d547ac2d | ||
|
|
81b33772fe | ||
|
|
32db258db0 | ||
|
|
3b855a866a | ||
|
|
eb7d69fe6b | ||
|
|
4c0109bccc | ||
|
|
f83a5b0ba8 | ||
|
|
ddb01e4ccb | ||
|
|
87a89324d9 | ||
|
|
4fc7295b97 | ||
|
|
5b025a6cba | ||
|
|
9166829930 | ||
|
|
8c7a02ec10 | ||
|
|
f4f250675c | ||
|
|
394a269df2 | ||
|
|
41dcc85ad1 | ||
|
|
9be9d75cb5 | ||
|
|
11483a77e8 | ||
|
|
ba895ed486 | ||
|
|
36d342f216 | ||
|
|
d09123eb22 | ||
|
|
642f58551c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,4 +27,5 @@ public/stylesheets
|
||||
public/images
|
||||
public/spree
|
||||
config/abr.yml
|
||||
config/heroku_env.rb
|
||||
NERD_tree*
|
||||
|
||||
6
Gemfile
6
Gemfile
@@ -6,7 +6,7 @@ gem 'rails', '3.2.8'
|
||||
gem 'pg'
|
||||
gem 'spree', :git => 'git://github.com/spree/spree.git', :branch => '1-1-stable'
|
||||
gem 'spree_i18n', :git => 'git://github.com/spree/spree_i18n.git'
|
||||
gem 'spree_paypal_express', :git => 'git://github.com/spree/spree_paypal_express.git', :branch => '1-1-stable'
|
||||
gem 'spree_paypal_express', :git => 'git://github.com/eaterprises/spree_paypal_express.git', :branch => '1-1-stable'
|
||||
gem 'spree_last_address', :git => 'git://github.com/dancinglightning/spree-last-address.git'
|
||||
|
||||
gem 'comfortable_mexican_sofa'
|
||||
@@ -17,9 +17,9 @@ gem 'simple_form', :git => 'git://github.com/RohanM/simple_form.git'
|
||||
|
||||
gem 'unicorn'
|
||||
gem 'bugsnag'
|
||||
gem 'spree_heroku', :git => 'git://github.com/joneslee85/spree-heroku.git'
|
||||
gem 'spree_heroku', :git => 'git://github.com/eaterprises/spree-heroku.git'
|
||||
gem 'haml'
|
||||
gem 'aws-s3'
|
||||
gem 'aws-sdk'
|
||||
gem 'andand'
|
||||
gem 'truncate_html'
|
||||
|
||||
|
||||
70
Gemfile.lock
70
Gemfile.lock
@@ -14,16 +14,25 @@ GIT
|
||||
spree_core (>= 1.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/joneslee85/spree-heroku.git
|
||||
revision: 63f0cfa47089cae50365e226ec7dd1eccde0ac05
|
||||
remote: git://github.com/eaterprises/spree-heroku.git
|
||||
revision: a1e07bf7a22fc0c07a1be9148f477d20b557dbf6
|
||||
specs:
|
||||
spree_heroku (1.0)
|
||||
aws-sdk (~> 1.3.4)
|
||||
spree_core (>= 0.70.0)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/eaterprises/spree_paypal_express.git
|
||||
revision: 7dd46e6e549d82c4d603f685a7cb7fbb4af0d973
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree_paypal_express (1.1.0)
|
||||
spree_auth (>= 1.0.0)
|
||||
spree_core (>= 1.0.0)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/spree/spree.git
|
||||
revision: d66ffac9088d0d5d0b0d146f305044ce619f0464
|
||||
revision: 46691e075129fd3d7b59e296d73149a9066c1b9d
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree (1.1.3)
|
||||
@@ -54,7 +63,7 @@ GIT
|
||||
jquery-rails (~> 2.0)
|
||||
kaminari (= 0.13.0)
|
||||
nested_set (= 1.7.0)
|
||||
paperclip (~> 2.7)
|
||||
paperclip (~> 2.8)
|
||||
rails (~> 3.2.8)
|
||||
ransack (~> 0.6.0)
|
||||
state_machine (= 1.1.2)
|
||||
@@ -77,15 +86,6 @@ GIT
|
||||
i18n (~> 0.5)
|
||||
spree (~> 1.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/spree/spree_paypal_express.git
|
||||
revision: 2c61f1700ef853e3d4f39739793dc3308422e94b
|
||||
branch: 1-1-stable
|
||||
specs:
|
||||
spree_paypal_express (1.1.0)
|
||||
spree_auth (>= 1.0.0)
|
||||
spree_core (>= 1.0.0)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
@@ -129,36 +129,32 @@ GEM
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
acts_as_list (0.1.4)
|
||||
addressable (2.2.8)
|
||||
addressable (2.3.2)
|
||||
andand (1.3.3)
|
||||
ansi (1.4.2)
|
||||
arel (3.0.2)
|
||||
awesome_print (1.0.2)
|
||||
aws-s3 (0.6.3)
|
||||
builder
|
||||
mime-types
|
||||
xml-simple
|
||||
aws-sdk (1.3.9)
|
||||
httparty (~> 0.7)
|
||||
json (~> 1.4)
|
||||
nokogiri (>= 1.4.4)
|
||||
uuidtools (~> 2.1)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bugsnag (1.1.2)
|
||||
httparty (~> 0.8.3)
|
||||
multi_json (~> 1.3.4)
|
||||
builder (3.0.3)
|
||||
bugsnag (1.2.4)
|
||||
httparty (>= 0.5, < 1.0)
|
||||
multi_json (~> 1.0)
|
||||
builder (3.0.4)
|
||||
cancan (1.6.7)
|
||||
capybara (1.1.2)
|
||||
capybara (1.1.3)
|
||||
mime-types (>= 1.16)
|
||||
nokogiri (>= 1.3.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (~> 2.0)
|
||||
xpath (~> 0.1.4)
|
||||
childprocess (0.3.2)
|
||||
ffi (~> 1.0.6)
|
||||
cocaine (0.3.0)
|
||||
childprocess (0.3.6)
|
||||
ffi (~> 1.0, >= 1.0.6)
|
||||
cocaine (0.4.2)
|
||||
coderay (1.0.7)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
@@ -200,7 +196,7 @@ GEM
|
||||
faker (1.0.1)
|
||||
i18n (~> 0.4)
|
||||
ffaker (1.12.1)
|
||||
ffi (1.0.11)
|
||||
ffi (1.1.5)
|
||||
haml (3.1.6)
|
||||
highline (1.6.11)
|
||||
hike (1.2.1)
|
||||
@@ -209,7 +205,7 @@ GEM
|
||||
multi_xml
|
||||
i18n (0.6.1)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.1.2)
|
||||
jquery-rails (2.1.3)
|
||||
railties (>= 3.1.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
json (1.7.5)
|
||||
@@ -219,7 +215,7 @@ GEM
|
||||
railties (>= 3.0.0)
|
||||
kgio (2.7.4)
|
||||
libv8 (3.3.10.4)
|
||||
libwebsocket (0.1.3)
|
||||
libwebsocket (0.1.5)
|
||||
addressable
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
@@ -237,7 +233,7 @@ GEM
|
||||
railties (>= 3.0.0)
|
||||
nokogiri (1.5.5)
|
||||
orm_adapter (0.0.7)
|
||||
paperclip (2.7.0)
|
||||
paperclip (2.8.0)
|
||||
activerecord (>= 2.3.0)
|
||||
activesupport (>= 2.3.2)
|
||||
cocaine (>= 0.0.2)
|
||||
@@ -261,7 +257,7 @@ GEM
|
||||
rack (>= 0.4)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.1)
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rails (3.2.8)
|
||||
actionmailer (= 3.2.8)
|
||||
@@ -299,15 +295,14 @@ GEM
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec (~> 2.10.0)
|
||||
rubyzip (0.9.8)
|
||||
rubyzip (0.9.9)
|
||||
sass (3.1.19)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
selenium-webdriver (2.22.2)
|
||||
selenium-webdriver (2.25.0)
|
||||
childprocess (>= 0.2.5)
|
||||
ffi (~> 1.0)
|
||||
libwebsocket (~> 0.1.3)
|
||||
multi_json (~> 1.0)
|
||||
rubyzip
|
||||
@@ -325,13 +320,13 @@ GEM
|
||||
libv8 (~> 3.3.10)
|
||||
thor (0.16.0)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.10)
|
||||
treetop (1.4.12)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
truncate_html (0.5.5)
|
||||
turn (0.8.3)
|
||||
ansi
|
||||
tzinfo (0.3.33)
|
||||
tzinfo (0.3.34)
|
||||
uglifier (1.2.4)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
@@ -342,7 +337,6 @@ GEM
|
||||
uuidtools (2.1.3)
|
||||
warden (1.1.1)
|
||||
rack (>= 1.0)
|
||||
xml-simple (1.1.1)
|
||||
xpath (0.1.4)
|
||||
nokogiri (~> 1.3)
|
||||
|
||||
@@ -352,7 +346,7 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
andand
|
||||
awesome_print
|
||||
aws-s3
|
||||
aws-sdk
|
||||
bugsnag
|
||||
capybara
|
||||
coffee-rails (~> 3.2.1)
|
||||
|
||||
@@ -20,11 +20,11 @@ hosted at GitHub.
|
||||
|
||||
You can view the code at:
|
||||
|
||||
https://github.com/andrewspinks/openfoodweb
|
||||
https://github.com/eaterprises/openfoodweb
|
||||
|
||||
You can download the source with the command:
|
||||
|
||||
git clone git@github.com:andrewspinks/openfoodweb
|
||||
git clone git@github.com:eaterprises/openfoodweb
|
||||
|
||||
|
||||
## Get it running
|
||||
@@ -80,6 +80,7 @@ speak to Andrew Spinks.
|
||||
|
||||
* Andrew Spinks (http://github.com/andrewspinks)
|
||||
* Rohan Mitchell (http://github.com/rohanm)
|
||||
* Rob Harrington (http://github.com/oeoeaio)
|
||||
|
||||
|
||||
## Licence
|
||||
|
||||
@@ -10,6 +10,15 @@ $(document).ready(function() {
|
||||
|
||||
// Product page with master price only
|
||||
$(".add-to-cart input.title:not(#quantity):not(.max_quantity)").change(products_update_price_without_variant).change();
|
||||
|
||||
// Product page other
|
||||
$("#distributor_id").change(function() {
|
||||
var distributor_html = distributors[$(this).val()];
|
||||
if(!distributor_html) {
|
||||
distributor_html = 'When you select a distributor for your order, their address and pickup times will be displayed here.';
|
||||
}
|
||||
$("#product-distributor-details .distributor-details").html(distributor_html);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -128,8 +128,8 @@ ul.product-listing {
|
||||
}
|
||||
|
||||
|
||||
/* Supplier and distributor description */
|
||||
.supplier-description, .distributor-description {
|
||||
/* Enterprise description */
|
||||
.enterprise-description {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
@@ -144,6 +144,19 @@ ul.product-listing {
|
||||
}
|
||||
|
||||
|
||||
/* Distributor details on product details page */
|
||||
fieldset#product-distributor-details {
|
||||
float: right;
|
||||
margin-top: 0;
|
||||
width: 250px;
|
||||
@extend #shipping;
|
||||
}
|
||||
|
||||
#product-variants {
|
||||
float: none;
|
||||
}
|
||||
|
||||
|
||||
/* Add to cart form on product details page */
|
||||
#cart-form {
|
||||
.error-distributor {
|
||||
|
||||
30
app/controllers/admin/enterprises_controller.rb
Normal file
30
app/controllers/admin/enterprises_controller.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module Admin
|
||||
class EnterprisesController < ResourceController
|
||||
before_filter :load_enterprise_set, :only => :index
|
||||
before_filter :load_countries, :except => :index
|
||||
|
||||
helper 'spree/products'
|
||||
|
||||
def bulk_update
|
||||
@enterprise_set = EnterpriseSet.new(params[:enterprise_set])
|
||||
if @enterprise_set.save
|
||||
redirect_to main_app.admin_enterprises_path, :notice => 'Distributor collection times updated.'
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_enterprise_set
|
||||
@enterprise_set = EnterpriseSet.new :enterprises => collection
|
||||
end
|
||||
|
||||
def load_countries
|
||||
@countries = Spree::Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order('is_primary_producer DESC, is_distributor ASC, name')
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/controllers/admin/resource_controller.rb
Normal file
42
app/controllers/admin/resource_controller.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
module Admin
|
||||
class ResourceController < Spree::Admin::ResourceController
|
||||
def model_class
|
||||
"#{controller_name.classify}".constantize
|
||||
end
|
||||
|
||||
|
||||
# URL helpers
|
||||
def new_object_url(options = {})
|
||||
if parent_data.present?
|
||||
main_app.new_polymorphic_url([:admin, parent, model_class], options)
|
||||
else
|
||||
main_app.new_polymorphic_url([:admin, model_class], options)
|
||||
end
|
||||
end
|
||||
|
||||
def edit_object_url(object, options = {})
|
||||
if parent_data.present?
|
||||
main_app.send "edit_admin_#{model_name}_#{object_name}_url", parent, object, options
|
||||
else
|
||||
main_app.send "edit_admin_#{object_name}_url", object, options
|
||||
end
|
||||
end
|
||||
|
||||
def object_url(object = nil, options = {})
|
||||
target = object ? object : @object
|
||||
if parent_data.present?
|
||||
main_app.send "admin_#{model_name}_#{object_name}_url", parent, target, options
|
||||
else
|
||||
main_app.send "admin_#{object_name}_url", target, options
|
||||
end
|
||||
end
|
||||
|
||||
def collection_url(options = {})
|
||||
if parent_data.present?
|
||||
main_app.polymorphic_url([:admin, parent, model_class], options)
|
||||
else
|
||||
main_app.polymorphic_url([:admin, model_class], options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,10 +9,9 @@ class ApplicationController < ActionController::Base
|
||||
@cms_site = Cms::Site.where(:identifier => 'open-food-web').first
|
||||
end
|
||||
|
||||
|
||||
def load_data_for_sidebar
|
||||
@suppliers = Spree::Supplier.all
|
||||
@distributors = Spree::Distributor.with_active_products_on_hand.by_name
|
||||
@suppliers = Enterprise.is_primary_producer
|
||||
@distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
10
app/controllers/base_controller.rb
Normal file
10
app/controllers/base_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class BaseController < ApplicationController
|
||||
include Spree::Core::ControllerHelpers
|
||||
include Spree::Core::RespondWith
|
||||
|
||||
helper 'spree/base'
|
||||
|
||||
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
|
||||
# include Spree::ProductsHelper so that method is available on the controller
|
||||
include Spree::ProductsHelper
|
||||
end
|
||||
53
app/controllers/enterprises_controller.rb
Normal file
53
app/controllers/enterprises_controller.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
class EnterprisesController < BaseController
|
||||
def index
|
||||
@enterprises = Enterprise.all
|
||||
end
|
||||
|
||||
def suppliers
|
||||
@suppliers = Enterprise.is_primary_producer
|
||||
end
|
||||
|
||||
def distributors
|
||||
@distributors = Enterprise.is_distributor
|
||||
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
@distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'enterprises/distributor_details', :locals => {:distributor => d})] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:enterprise_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@enterprise = Enterprise.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select_distributor
|
||||
distributor = Enterprise.is_distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect_distributor
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
@@ -1,30 +0,0 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class DistributorsController < ResourceController
|
||||
before_filter :load_distributor_set, :only => :index
|
||||
before_filter :load_countries, :except => :index
|
||||
|
||||
def bulk_update
|
||||
@distributor_set = DistributorSet.new(params[:distributor_set])
|
||||
if @distributor_set.save
|
||||
redirect_to admin_distributors_path, :notice => 'Distributor collection times updated.'
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_distributor_set
|
||||
@distributor_set = Spree::DistributorSet.new :distributors => collection
|
||||
end
|
||||
|
||||
def load_countries
|
||||
@countries = Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,29 @@
|
||||
require 'csv'
|
||||
require 'open_food_web/order_and_distributor_report'
|
||||
require 'open_food_web/group_buy_report'
|
||||
require 'open_food_web/order_grouper'
|
||||
|
||||
Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:orders_and_distributors => {:name => "Orders And Distributors", :description => "Orders with distributor details"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:group_buys => {:name => "Group Buys", :description => "Orders by supplier and variant"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:bulk_coop => {:name => "Bulk Co-Op", :description => "Reports for Bulk Co-Op orders"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:payments => {:name => "Payment Reports", :description => "Reports for Payments"}})
|
||||
Spree::Admin::ReportsController::AVAILABLE_REPORTS.merge!({:order_cycles => {:name => "Order Cycle Reports", :description => "Reports for Order Cycles"}})
|
||||
|
||||
def orders_and_distributors
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
if params[:q][:completed_at_gt].blank?
|
||||
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
if params[:q] && !params[:q][:completed_at_lt].blank?
|
||||
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
@@ -39,21 +43,21 @@ Spree::Admin::ReportsController.class_eval do
|
||||
def group_buys
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.now.beginning_of_month
|
||||
if params[:q][:completed_at_gt].blank?
|
||||
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
if params[:q] && !params[:q][:completed_at_lt].blank?
|
||||
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "created_at.desc"
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
|
||||
@distributors = Spree::Distributor.all
|
||||
@distributors = Enterprise.is_distributor
|
||||
|
||||
@report = OpenFoodWeb::GroupBuyReport.new orders
|
||||
unless params[:csv]
|
||||
@@ -67,4 +71,458 @@ Spree::Admin::ReportsController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
def bulk_coop
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:completed_at_gt].blank?
|
||||
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:completed_at_lt].blank?
|
||||
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
line_items = orders.map { |o| o.line_items }.flatten
|
||||
|
||||
@distributors = Enterprise.is_distributor
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "bulk_coop_supplier_report"
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Units Required", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| (li.quantity || 0) * (li.variant.weight || 0) } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * (li.variant.weight || 0) } },
|
||||
proc { |lis| ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max) * (li.variant.weight || 0) } - ( ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "bulk_coop_allocation"
|
||||
|
||||
header = ["Customer", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Total Allocated", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * (li.variant.weight || 0) } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * (li.variant.weight || 0) } },
|
||||
proc { |lis| ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } - ( ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
|
||||
when "bulk_coop_packing_sheets"
|
||||
|
||||
header = ["Customer", "Product", "Variant", "Sum Total"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.sum { |li| li.quantity } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
|
||||
when "bulk_coop_customer_payments"
|
||||
|
||||
header = ["Customer", "Date of Order", "Total Cost", "Amount Owing", "Amount Paid"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.order.completed_at.to_s },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.outstanding_balance } },
|
||||
proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.payment_total } } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.completed_at } } ]
|
||||
|
||||
else # List all line items
|
||||
|
||||
header = ["Supplier", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Units Required", "Remainder"]
|
||||
|
||||
columns = [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| lis.first.variant.options_text },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |li| li.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| lis.first.variant.product.supplier.name },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy_unit_size || 0.0 },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * (li.variant.weight || 0) } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * (li.variant.weight || 0) } },
|
||||
proc { |lis| ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } - ( ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(line_items)
|
||||
csv_file_name = "bulk_coop.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
end
|
||||
|
||||
def payments
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:completed_at_gt].blank?
|
||||
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:completed_at_lt].blank?
|
||||
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
|
||||
@distributors = Enterprise.is_distributor
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "payments_by_payment_type"
|
||||
table_items = payments
|
||||
|
||||
header = ["Payment State", "Distributor", "Payment Type", "Total ($)"]
|
||||
|
||||
columns = [ proc { |payments| payments.first.order.payment_state },
|
||||
proc { |payments| payments.first.order.distributor.name },
|
||||
proc { |payments| payments.first.payment_method.name },
|
||||
proc { |payments| payments.sum { |payment| payment.amount } } ]
|
||||
|
||||
rules = [ { group_by: proc { |payment| payment.order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |payment| payment.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |payment| payment.payment_method },
|
||||
sort_by: proc { |method| method.name } } ]
|
||||
|
||||
when "itemised_payment_totals"
|
||||
table_items = orders
|
||||
|
||||
header = ["Payment State", "Distributor", "Product Total ($)", "Shipping Total ($)", "Outstanding Balance ($)", "Total ($)"]
|
||||
|
||||
columns = [ proc { |orders| orders.first.payment_state },
|
||||
proc { |orders| orders.first.distributor.name },
|
||||
proc { |orders| orders.sum { |o| o.item_total } },
|
||||
proc { |orders| orders.sum { |o| o.ship_total } },
|
||||
proc { |orders| orders.sum { |o| o.outstanding_balance } },
|
||||
proc { |orders| orders.sum { |o| o.total } } ]
|
||||
|
||||
rules = [ { group_by: proc { |order| order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |order| order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
when "payment_totals"
|
||||
table_items = orders
|
||||
|
||||
header = ["Payment State", "Distributor", "Product Total ($)", "Shipping Total ($)", "Total ($)", "EFT ($)", "PayPal ($)", "Outstanding Balance ($)"]
|
||||
|
||||
columns = [ proc { |orders| orders.first.payment_state },
|
||||
proc { |orders| orders.first.distributor.name },
|
||||
proc { |orders| orders.sum { |o| o.item_total } },
|
||||
proc { |orders| orders.sum { |o| o.ship_total } },
|
||||
proc { |orders| orders.sum { |o| o.total } },
|
||||
proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum { |payment| payment.amount } } },
|
||||
proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum{ |payment| payment.amount } } },
|
||||
proc { |orders| orders.sum { |o| o.outstanding_balance } } ]
|
||||
|
||||
rules = [ { group_by: proc { |order| order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |order| order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
else
|
||||
table_items = payments
|
||||
|
||||
header = ["Payment State", "Distributor", "Payment Type", "Total ($)"]
|
||||
|
||||
columns = [ proc { |payments| payments.first.order.payment_state },
|
||||
proc { |payments| payments.first.order.distributor.name },
|
||||
proc { |payments| payments.first.payment_method.name },
|
||||
proc { |payments| payments.sum { |payment| payment.amount } } ]
|
||||
|
||||
rules = [ { group_by: proc { |payment| payment.order.payment_state },
|
||||
sort_by: proc { |payment_state| payment_state } },
|
||||
{ group_by: proc { |payment| payment.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |payment| payment.payment_method },
|
||||
sort_by: proc { |method| method.name } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(table_items)
|
||||
csv_file_name = "payments.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
|
||||
end
|
||||
|
||||
def order_cycles
|
||||
params[:q] = {} unless params[:q]
|
||||
|
||||
if params[:q][:completed_at_gt].blank?
|
||||
params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month
|
||||
else
|
||||
params[:q][:completed_at_gt] = Time.zone.parse(params[:q][:completed_at_gt]).beginning_of_day rescue Time.zone.now.beginning_of_month
|
||||
end
|
||||
|
||||
if params[:q] && !params[:q][:completed_at_lt].blank?
|
||||
params[:q][:completed_at_lt] = Time.zone.parse(params[:q][:completed_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
@search = Spree::Order.complete.search(params[:q])
|
||||
orders = @search.result
|
||||
line_items = orders.map { |o| o.line_items }.flatten
|
||||
#payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
|
||||
@distributors = Enterprise.is_distributor
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
when "order_cycle_supplier_totals"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "order_cycle_supplier_totals_by_distributor"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "To Distributor", "Amount", "Cost per Unit", "Total Cost", "Shipping Method"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "shipping method" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text },
|
||||
summary_columns: [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } } ]
|
||||
|
||||
when "order_cycle_distributor_totals_by_supplier"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Distributor", "Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Total Shipping Cost", "Shipping Method"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "shipping method" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
when "order_cycle_customer_totals"
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Distributor", "Customer", "Email", "Phone", "Product", "Variant", "Amount", "Item ($)", "Ship ($)", "Total ($)", "Paid?", "Packed?", "Shipped?"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.order.distributor },
|
||||
sort_by: proc { |distributor| distributor.name } },
|
||||
{ group_by: proc { |line_item| line_item.order },
|
||||
sort_by: proc { |order| order.bill_address.lastname + " " + order.bill_address.firstname },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.distributor.name },
|
||||
proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
proc { |line_items| line_items.first.order.email },
|
||||
proc { |line_items| line_items.first.order.bill_address.phone },
|
||||
proc { |line_items| "TOTAL" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
proc { |line_items| line_items.map { |li| li.order.paid? }.all? { |paid| paid == true } ? "Yes" : "No" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" } ] },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
else
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.variant.product.supplier.name },
|
||||
proc { |line_items| line_items.first.variant.product.name },
|
||||
proc { |line_items| line_items.first.variant.options_text },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity } },
|
||||
proc { |line_items| line_items.first.variant.price },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
{ group_by: proc { |line_item| line_item.variant },
|
||||
sort_by: proc { |variant| variant.options_text } } ]
|
||||
|
||||
end
|
||||
|
||||
order_grouper = OpenFoodWeb::OrderGrouper.new rules, columns
|
||||
|
||||
@header = header
|
||||
@table = order_grouper.table(table_items)
|
||||
csv_file_name = "order_cycles.csv"
|
||||
|
||||
render_report(@header, @table, params[:csv], csv_file_name)
|
||||
|
||||
end
|
||||
|
||||
def render_report (header, table, create_csv, csv_file_name)
|
||||
unless create_csv
|
||||
render :html => table
|
||||
else
|
||||
csv_string = CSV.generate do |csv|
|
||||
csv << header
|
||||
table.each { |row| csv << row }
|
||||
end
|
||||
send_data csv_string, :filename => csv_file_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class SuppliersController < ResourceController
|
||||
before_filter :load_data, :except => [:index]
|
||||
|
||||
private
|
||||
def load_data
|
||||
@countries = Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,39 +0,0 @@
|
||||
module Spree
|
||||
class DistributorsController < BaseController
|
||||
helper 'spree/products'
|
||||
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@distributor = Distributor.find params[:id]
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::HomeController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include EnterprisesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
|
||||
@@ -3,7 +3,7 @@ Spree::OrdersController.class_eval do
|
||||
after_filter :populate_variant_attributes, :only => :populate
|
||||
|
||||
def populate_order_distributor
|
||||
@distributor = params[:distributor_id].present? ? Spree::Distributor.find(params[:distributor_id]) : nil
|
||||
@distributor = params[:distributor_id].present? ? Enterprise.is_distributor.find(params[:distributor_id]) : nil
|
||||
|
||||
if populate_valid? @distributor
|
||||
order = current_order(true)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::ProductsController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include EnterprisesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
module Spree
|
||||
class SuppliersController < BaseController
|
||||
helper 'spree/products'
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@supplier = Supplier.find params[:id]
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::TaxonsController.class_eval do
|
||||
include Spree::DistributorsHelper
|
||||
include EnterprisesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :show => { :html => { :success => lambda {
|
||||
|
||||
@@ -4,4 +4,15 @@ module ApplicationHelper
|
||||
cms_page_content(:content, Cms::Page.find_by_full_path('/'))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Pass URL helper calls on to spree where applicable so that we don't need to use
|
||||
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
|
||||
def method_missing(method, *args, &block)
|
||||
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
|
||||
spree.send(method, *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
5
app/helpers/enterprises_helper.rb
Normal file
5
app/helpers/enterprises_helper.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module EnterprisesHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
end
|
||||
end
|
||||
@@ -1,7 +0,0 @@
|
||||
module Spree
|
||||
module DistributorsHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
end
|
||||
end
|
||||
end
|
||||
42
app/models/enterprise.rb
Normal file
42
app/models/enterprise.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
class Enterprise < ActiveRecord::Base
|
||||
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id'
|
||||
has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id'
|
||||
belongs_to :address, :class_name => 'Spree::Address'
|
||||
has_many :product_distributions, :foreign_key => 'distributor_id', :dependent => :destroy
|
||||
has_many :distributed_products, :through => :product_distributions, :source => :product
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :address
|
||||
validates_associated :address
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :is_primary_producer, where(:is_primary_producer => true)
|
||||
scope :is_distributor, where(:is_distributor => true)
|
||||
scope :with_distributed_active_products_on_hand, lambda { joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') }
|
||||
|
||||
|
||||
def has_supplied_products_on_hand?
|
||||
self.supplied_products.where('count_on_hand > 0').present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def initialize_country
|
||||
self.address ||= Spree::Address.new
|
||||
self.address.country = Spree::Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
address.firstname = address.lastname = address.phone = 'unused' if address.present?
|
||||
end
|
||||
end
|
||||
34
app/models/enterprise_set.rb
Normal file
34
app/models/enterprise_set.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# Tableless model to handle updating multiple enterprises at once from a
|
||||
# single form. Used to update next_collection_at field for all distributors in
|
||||
# admin backend.
|
||||
class EnterpriseSet
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :enterprises
|
||||
|
||||
def initialize(attributes={})
|
||||
@enterprises = Enterprise.all
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def enterprises_attributes=(attributes)
|
||||
attributes.each do |k, attributes|
|
||||
# attributes == {:id => 123, :next_collection_at => '...'}
|
||||
e = @enterprises.detect { |e| e.id.to_s == attributes[:id].to_s }
|
||||
e.assign_attributes(attributes.except(:id))
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
enterprises.all?(&:save)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
9
app/models/product_distribution.rb
Normal file
9
app/models/product_distribution.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
belongs_to :product, :class_name => 'Spree::Product'
|
||||
belongs_to :distributor, :class_name => 'Enterprise'
|
||||
belongs_to :shipping_method, :class_name => 'Spree::ShippingMethod'
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
validates_presence_of :distributor_id, :shipping_method_id
|
||||
validates_uniqueness_of :product_id, :scope => :distributor_id
|
||||
end
|
||||
@@ -1,34 +0,0 @@
|
||||
module Spree
|
||||
class Distributor < ActiveRecord::Base
|
||||
self.table_name = 'distributors'
|
||||
belongs_to :pickup_address, :foreign_key => 'pickup_address_id', :class_name => 'Spree::Address'
|
||||
has_many :orders
|
||||
|
||||
has_many :product_distributions, :dependent => :destroy
|
||||
has_many :products, :through => :product_distributions
|
||||
|
||||
accepts_nested_attributes_for :pickup_address
|
||||
|
||||
validates_presence_of :name, :pickup_address
|
||||
validates_associated :pickup_address
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :with_active_products_on_hand, lambda { joins(:products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(distributors.*)') }
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def initialize_country
|
||||
self.pickup_address ||= Address.new
|
||||
self.pickup_address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.pickup_address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
pickup_address.firstname = pickup_address.lastname = pickup_address.phone = 'unused' if pickup_address.present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,36 +0,0 @@
|
||||
# Tableless model to handle updating multiple distributors at once from a
|
||||
# single form. Used to update next_collection_at field for all distributors in
|
||||
# admin backend.
|
||||
module Spree
|
||||
class DistributorSet
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :distributors
|
||||
|
||||
def initialize(attributes={})
|
||||
@distributors = Spree::Distributor.all
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def distributors_attributes=(attributes)
|
||||
attributes.each do |k, attributes|
|
||||
# attributes == {:id => 123, :next_collection_at => '...'}
|
||||
d = @distributors.detect { |d| d.id.to_s == attributes[:id].to_s }
|
||||
d.assign_attributes(attributes.except(:id))
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
distributors.all?(&:save)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
Spree::Order.class_eval do
|
||||
belongs_to :distributor
|
||||
belongs_to :distributor, :class_name => 'Enterprise'
|
||||
|
||||
before_validation :shipping_address_from_distributor
|
||||
after_create :set_default_shipping_method
|
||||
@@ -57,7 +57,7 @@ Spree::Order.class_eval do
|
||||
|
||||
def shipping_address_from_distributor
|
||||
if distributor
|
||||
self.ship_address = distributor.pickup_address.clone
|
||||
self.ship_address = distributor.address.clone
|
||||
|
||||
if bill_address
|
||||
self.ship_address.firstname = bill_address.firstname
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
Spree::Product.class_eval do
|
||||
belongs_to :supplier
|
||||
belongs_to :supplier, :class_name => 'Enterprise'
|
||||
|
||||
has_many :product_distributions, :dependent => :destroy
|
||||
has_many :distributors, :through => :product_distributions
|
||||
|
||||
accepts_nested_attributes_for :product_distributions, :allow_destroy => true
|
||||
|
||||
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy
|
||||
attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size
|
||||
|
||||
validates_presence_of :supplier
|
||||
|
||||
scope :in_supplier, lambda { |supplier| where(:supplier_id => supplier) }
|
||||
scope :in_distributor, lambda { |distributor| joins(:product_distributions).where('product_distributions.distributor_id = ?', (distributor.respond_to?(:id) ? distributor.id : distributor.to_i)) }
|
||||
scope :in_supplier_or_distributor, lambda { |enterprise| select('distinct spree_products.*').
|
||||
joins('LEFT OUTER JOIN product_distributions ON product_distributions.product_id=spree_products.id').
|
||||
where('supplier_id=? OR product_distributions.distributor_id=?',
|
||||
enterprise.respond_to?(:id) ? enterprise.id : enterprise.to_i,
|
||||
enterprise.respond_to?(:id) ? enterprise.id : enterprise.to_i) }
|
||||
|
||||
|
||||
def shipping_method_for_distributor(distributor)
|
||||
@@ -23,7 +28,7 @@ Spree::Product.class_eval do
|
||||
|
||||
# Build a product distribution for each distributor
|
||||
def build_product_distributions
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Enterprise.is_distributor.each do |distributor|
|
||||
unless self.product_distributions.find_by_distributor_id distributor.id
|
||||
self.product_distributions.build(:distributor => distributor)
|
||||
end
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
module Spree
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
self.table_name = 'product_distributions'
|
||||
|
||||
belongs_to :product
|
||||
belongs_to :distributor
|
||||
belongs_to :shipping_method
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
validates_presence_of :distributor_id, :shipping_method_id
|
||||
validates_uniqueness_of :product_id, :scope => :distributor_id
|
||||
end
|
||||
end
|
||||
@@ -1,28 +0,0 @@
|
||||
module Spree
|
||||
class Supplier < ActiveRecord::Base
|
||||
self.table_name = 'suppliers'
|
||||
has_many :products
|
||||
belongs_to :address
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
|
||||
validates_presence_of :name, :address
|
||||
validates_associated :address
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
def initialize_country
|
||||
self.address ||= Address.new
|
||||
self.address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record?
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
address.firstname = address.lastname = address.phone = 'unused' if address.present?
|
||||
end
|
||||
|
||||
def to_param
|
||||
"#{id}-#{name.parameterize}"
|
||||
end
|
||||
end
|
||||
end
|
||||
9
app/overrides/add_distributor_details_to_product.rb
Normal file
9
app/overrides/add_distributor_details_to_product.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_before => "[data-hook='cart_form']",
|
||||
:partial => "spree/products/distributor_details",
|
||||
:name => "product_distributor_details")
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_after => "[data-hook='product_show']",
|
||||
:text => "<%= javascript_include_tag main_app.distributors_enterprises_path(:format => :js) %>",
|
||||
:name => "product_distributor_details_js")
|
||||
4
app/overrides/add_feedback_script.rb
Normal file
4
app/overrides/add_feedback_script.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
|
||||
:insert_bottom => "[data-hook='inside_head']",
|
||||
:partial => "layouts/feedback_script",
|
||||
:name => "feedback_script")
|
||||
@@ -1,11 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "distributors_admin_tabs",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<%= tab(:distributors, :url => spree.admin_distributors_path) %>",
|
||||
:disabled => false)
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "suppliers_admin_tabs",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<%= tab(:suppliers, :url => spree.admin_suppliers_path) %>",
|
||||
:disabled => false)
|
||||
4
app/overrides/enterprises_admin_tab.rb
Normal file
4
app/overrides/enterprises_admin_tab.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/layouts/admin",
|
||||
:name => "enterprises_admin_tabs",
|
||||
:insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
|
||||
:text => "<%= tab(:enterprises, :url => main_app.admin_enterprises_path) %>")
|
||||
@@ -11,8 +11,14 @@
|
||||
%tr{'data-hook' => "long_description"}
|
||||
%td Extended Description:
|
||||
%td= f.text_area :long_description, :class => 'rich_text'
|
||||
%tr{'data-hook' => "is_primary_producer"}
|
||||
%td Primary Producer?
|
||||
%td= f.check_box :is_primary_producer
|
||||
%tr{'data-hook' => "is_distributor"}
|
||||
%td Distributor?
|
||||
%td= f.check_box :is_distributor
|
||||
%tr{"data-hook" => "contact"}
|
||||
%td Contact:
|
||||
%td Contact Person:
|
||||
%td= f.text_field :contact
|
||||
%tr{"data-hook" => "phone"}
|
||||
%td Phone:
|
||||
@@ -20,15 +26,23 @@
|
||||
%tr{"data-hook" => "email"}
|
||||
%td Email:
|
||||
%td= f.text_field :email
|
||||
%tr{"data-hook" => "url"}
|
||||
%td URL:
|
||||
%td= f.text_field :url
|
||||
%tr{"data-hook" => "website"}
|
||||
%td Website:
|
||||
%td= f.text_field :website
|
||||
%tr{"data-hook" => "twitter"}
|
||||
%td Twitter:
|
||||
%td= f.text_field :twitter
|
||||
%tr{"data-hook" => "abn"}
|
||||
%td ABN:
|
||||
%td= f.text_field :abn
|
||||
%tr{"data-hook" => "acn"}
|
||||
%td ACN:
|
||||
%td= f.text_field :acn
|
||||
%fieldset
|
||||
%legend Address
|
||||
%table
|
||||
= f.fields_for :address do |address_form|
|
||||
= render 'spree/admin/shared/address_form', :f => address_form
|
||||
%fieldset
|
||||
%legend Pickup details
|
||||
%table{"data-hook" => "distributors_pickup_details"}
|
||||
@@ -38,5 +52,3 @@
|
||||
%tr{"data-hook" => "pickup_times"}
|
||||
%td Regular pickup times:
|
||||
%td= f.text_field :pickup_times
|
||||
= f.fields_for :pickup_address do |pickup_address_form|
|
||||
= render 'spree/admin/shared/address_form', :f => pickup_address_form
|
||||
@@ -1,6 +1,6 @@
|
||||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } %>
|
||||
|
||||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
|
||||
<%= form_for [:admin, @distributor] do |f| %>
|
||||
<%= form_for [main_app, :admin, @enterprise] do |f| %>
|
||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||
<%= render :partial => 'spree/admin/shared/edit_resource_links' %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
42
app/views/admin/enterprises/index.html.erb
Normal file
42
app/views/admin/enterprises/index.html.erb
Normal file
@@ -0,0 +1,42 @@
|
||||
<div class="toolbar" data-hook="toolbar">
|
||||
<ul class="actions">
|
||||
<li>
|
||||
<%= button_link_to "New Enterprise", main_app.new_admin_enterprise_path, :icon => 'add', :id => 'admin_new_enterprise_link' %>
|
||||
</li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<%= form_for @enterprise_set, :url => main_app.bulk_update_admin_enterprises_path do |f| %>
|
||||
<table class="index" id="listing_enterprises">
|
||||
<thead>
|
||||
<tr data-hook="enterprises_header">
|
||||
<th>Name</th>
|
||||
<th>Role</th>
|
||||
<th>Next Collection Date/Time</th>
|
||||
<th>Description</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= f.fields_for :enterprises do |enterprise_form| %>
|
||||
<% enterprise = enterprise_form.object %>
|
||||
<tr>
|
||||
<td><%= link_to enterprise.name, main_app.admin_enterprise_path(enterprise) %></td>
|
||||
<td><%= 'PP ' if enterprise.is_primary_producer %><%= 'D' if enterprise.is_distributor %></td>
|
||||
<td><%= enterprise_form.text_field :next_collection_at %></td>
|
||||
<td><%= enterprise.description %></td>
|
||||
<td data-hook="admin_users_index_row_actions">
|
||||
<%= link_to_edit enterprise, :class => 'edit' %>
|
||||
<%= link_to_delete enterprise %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if @enterprises.empty? %>
|
||||
<tr><td colspan="4"><%= t(:none) %></td></tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= f.submit 'Update' %>
|
||||
<% end %>
|
||||
@@ -1,7 +1,6 @@
|
||||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } %>
|
||||
|
||||
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @distributor } %>
|
||||
|
||||
<%= form_for [:admin, @distributor] do |f| %>
|
||||
<%= form_for [main_app, :admin, @enterprise] do |f| %>
|
||||
<%= render :partial => 'form', :locals => { :f => f } %>
|
||||
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
|
||||
<% end %>
|
||||
51
app/views/admin/enterprises/show.html.haml
Normal file
51
app/views/admin/enterprises/show.html.haml
Normal file
@@ -0,0 +1,51 @@
|
||||
%h1 Enterprise
|
||||
%table
|
||||
%tr
|
||||
%th Name:
|
||||
%td= @enterprise.name
|
||||
%tr
|
||||
%th Description:
|
||||
%td= @enterprise.description
|
||||
%tr
|
||||
%th Extended Description:
|
||||
%td= @enterprise.long_description.andand.html_safe
|
||||
%tr
|
||||
%th Primary producer?
|
||||
%td= @enterprise.is_primary_producer ? 'Yes' : 'No'
|
||||
%tr
|
||||
%th Distributor?
|
||||
%td= @enterprise.is_distributor ? 'Yes' : 'No'
|
||||
%tr
|
||||
%th Contact person:
|
||||
%td= @enterprise.contact
|
||||
%tr
|
||||
%th Phone number:
|
||||
%td= @enterprise.phone
|
||||
%tr
|
||||
%th Email:
|
||||
%td= @enterprise.email
|
||||
%tr
|
||||
%th Website:
|
||||
%td= @enterprise.website
|
||||
%tr
|
||||
%th Twitter:
|
||||
%td= @enterprise.twitter
|
||||
%tr
|
||||
%th ABN:
|
||||
%td= @enterprise.abn
|
||||
%tr
|
||||
%th ACN:
|
||||
%td= @enterprise.acn
|
||||
%tr
|
||||
%th Address:
|
||||
%td= render 'spree/shared/address', :address => @enterprise.address
|
||||
%tr
|
||||
%th Regular pickup times:
|
||||
%td= @enterprise.pickup_times
|
||||
%tr
|
||||
%th Next collection date/time:
|
||||
%td= @enterprise.next_collection_at
|
||||
%p
|
||||
= link_to :Edit, main_app.edit_admin_enterprise_path(@enterprise), :class => 'edit_enterprise'
|
||||
= t(:or)
|
||||
= link_to t(:back), main_app.admin_enterprises_path
|
||||
23
app/views/enterprises/_distributor_details.html.haml
Normal file
23
app/views/enterprises/_distributor_details.html.haml
Normal file
@@ -0,0 +1,23 @@
|
||||
%h2= distributor.name
|
||||
%p
|
||||
%strong Address:
|
||||
%br/
|
||||
= render 'spree/shared/address', :address => distributor.address
|
||||
%p
|
||||
%strong Next collection time:
|
||||
%br/
|
||||
= distributor.next_collection_at
|
||||
%p
|
||||
%strong Regular collection times:
|
||||
%br/
|
||||
= distributor.pickup_times
|
||||
%p
|
||||
%strong Contact:
|
||||
%br/
|
||||
= distributor.contact
|
||||
%br/
|
||||
= "Phone: #{distributor.phone}"
|
||||
%br/
|
||||
= "Email: #{distributor.email}"
|
||||
%p= distributor.description
|
||||
%p= link_to distributor.website, distributor.website if distributor.website
|
||||
1
app/views/enterprises/distributors.js.erb
Normal file
1
app/views/enterprises/distributors.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
distributors = <%= @distributor_details.to_json.html_safe %>;
|
||||
12
app/views/enterprises/index.html.haml
Normal file
12
app/views/enterprises/index.html.haml
Normal file
@@ -0,0 +1,12 @@
|
||||
- content_for :sidebar do
|
||||
%div{'data-hook' => "homepage_sidebar_navigation"}
|
||||
= render 'spree/sidebar'
|
||||
|
||||
|
||||
%h1 Enterprises
|
||||
|
||||
= cms_page_content(:content, Cms::Page.find_by_full_path('/enterprises'))
|
||||
|
||||
%ul.enterprises
|
||||
- @enterprises.each do |enterprise|
|
||||
%li= link_to enterprise.name, enterprise
|
||||
7
app/views/enterprises/show.html.haml
Normal file
7
app/views/enterprises/show.html.haml
Normal file
@@ -0,0 +1,7 @@
|
||||
%h2= @enterprise.name
|
||||
|
||||
.enterprise-description= @enterprise.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
12
app/views/enterprises/suppliers.html.haml
Normal file
12
app/views/enterprises/suppliers.html.haml
Normal file
@@ -0,0 +1,12 @@
|
||||
- content_for :sidebar do
|
||||
%div{'data-hook' => "homepage_sidebar_navigation"}
|
||||
= render 'spree/sidebar'
|
||||
|
||||
|
||||
%h1 Suppliers
|
||||
|
||||
= cms_page_content(:content, Cms::Page.find_by_full_path('/enterprises/suppliers'))
|
||||
|
||||
%ul.enterprises
|
||||
- @suppliers.each do |supplier|
|
||||
%li= link_to supplier.name, supplier
|
||||
8
app/views/layouts/_feedback_script.html
Normal file
8
app/views/layouts/_feedback_script.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<script type="text/javascript">
|
||||
var uvOptions = {};
|
||||
(function() {
|
||||
var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
|
||||
uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/mCbT1cbjQZkPELXOix9Ag.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
|
||||
})();
|
||||
</script>
|
||||
@@ -1,40 +0,0 @@
|
||||
<div class="toolbar" data-hook="toolbar">
|
||||
<ul class="actions">
|
||||
<li>
|
||||
<%= button_link_to "New Distributor", spree.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
|
||||
</li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<%= form_for @distributor_set, :url => bulk_update_admin_distributors_path do |f| %>
|
||||
<table class="index" id="listing_distributors">
|
||||
<thead>
|
||||
<tr data-hook="distributors_header">
|
||||
<th>Name</th>
|
||||
<th>Next Collection Date/Time</th>
|
||||
<th>Description</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= f.fields_for :distributors do |distributor_form| %>
|
||||
<% distributor = distributor_form.object %>
|
||||
<tr>
|
||||
<td><%= link_to distributor.name, spree.admin_distributor_path(distributor) %></td>
|
||||
<td><%= distributor_form.text_field :next_collection_at %></td>
|
||||
<td><%= distributor.description %></td>
|
||||
<td data-hook="admin_users_index_row_actions">
|
||||
<%= link_to_edit distributor, :class => 'edit' %>
|
||||
<%= link_to_delete distributor %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% if @distributors.empty? %>
|
||||
<tr><td colspan="4"><%= t(:none) %></td></tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= f.submit 'Update' %>
|
||||
<% end %>
|
||||
@@ -1,42 +0,0 @@
|
||||
%h1 Distributor
|
||||
%table
|
||||
%tr
|
||||
%th Name:
|
||||
%td= @distributor.name
|
||||
%tr
|
||||
%th Description:
|
||||
%td= @distributor.description
|
||||
%tr
|
||||
%th Extended Description:
|
||||
%td= @distributor.long_description.andand.html_safe
|
||||
%tr
|
||||
%th Contact person:
|
||||
%td= @distributor.contact
|
||||
%tr
|
||||
%th Phone number:
|
||||
%td= @distributor.phone
|
||||
%tr
|
||||
%th Email:
|
||||
%td= @distributor.email
|
||||
%tr
|
||||
%th Pickup address:
|
||||
%td= render 'spree/shared/address', :address => @distributor.pickup_address
|
||||
%tr
|
||||
%th Next collection date/time:
|
||||
%td= @distributor.next_collection_at
|
||||
%tr
|
||||
%th Regular pickup times:
|
||||
%td= @distributor.pickup_times
|
||||
%tr
|
||||
%th ABN:
|
||||
%td= @distributor.abn
|
||||
%tr
|
||||
%th ACN:
|
||||
%td= @distributor.acn
|
||||
%tr
|
||||
%th URL:
|
||||
%td= @distributor.url
|
||||
%p
|
||||
= link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
|
||||
= t(:or)
|
||||
= link_to t(:back), spree.admin_distributors_path
|
||||
@@ -5,3 +5,8 @@
|
||||
= f.label :group_buy_1, 'Yes'
|
||||
= f.radio_button :group_buy, '0', :checked => !f.object.group_buy
|
||||
= f.label :group_buy_0, 'No'
|
||||
|
||||
= f.field_container :group_buy_unit_size do
|
||||
= f.label :group_buy_unit_size
|
||||
%br
|
||||
= f.text_field :group_buy_unit_size
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%br
|
||||
= f.collection_select(:supplier_id, Spree::Supplier.all, :id, :name, :include_blank => true)
|
||||
= f.error_message_on :supplier
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer, :id, :name, :include_blank => true)
|
||||
= f.error_message_on :supplier
|
||||
|
||||
39
app/views/spree/admin/reports/bulk_coop.html.haml
Normal file
39
app/views/spree/admin/reports/bulk_coop.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.bulk_coop_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :completed_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :completed_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => 'All')
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Bulk Co-op - Totals by Supplier',:bulk_coop_supplier_report],['Bulk Co-op - Allocation',:bulk_coop_allocation],['Bulk Co-op - Packing Sheets',:bulk_coop_packing_sheets],['Bulk Co-op - Customer Payments',:bulk_coop_customer_payments]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
@@ -3,11 +3,11 @@
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :created_at_gt, :class => 'datepicker'
|
||||
= f.text_field :completed_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :created_at_lt, :class => 'datepicker'
|
||||
= f.text_field :completed_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
|
||||
39
app/views/spree/admin/reports/order_cycles.html.haml
Normal file
39
app/views/spree/admin/reports/order_cycles.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.order_cycles_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :completed_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :completed_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => @include_blank)
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Order Cycle Supplier Totals',:order_cycle_supplier_totals], ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], ['Order Cycle Customer Totals',:order_cycle_customer_totals]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
@@ -3,11 +3,11 @@
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= s.text_field :created_at_gt, :class => 'datepicker'
|
||||
= s.text_field :completed_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= s.text_field :created_at_lt, :class => 'datepicker'
|
||||
= s.text_field :completed_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
= check_box_tag :csv
|
||||
|
||||
39
app/views/spree/admin/reports/payments.html.haml
Normal file
39
app/views/spree/admin/reports/payments.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
= form_for @search, :url => spree.payments_admin_reports_path do |f|
|
||||
= label_tag nil, t(:date_range)
|
||||
%br
|
||||
.date-range-filter
|
||||
%div{"class" => "left sub-field"}
|
||||
= f.text_field :completed_at_gt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:start), :class => 'sub'
|
||||
%div{"class" => "right sub-field"}
|
||||
= f.text_field :completed_at_lt, :class => 'datepicker'
|
||||
%br
|
||||
= label_tag nil, t(:stop)
|
||||
%br
|
||||
= label_tag nil, "Distributor: "
|
||||
= f.collection_select(:distributor_id_eq, @distributors, :id, :name, :include_blank => 'All')
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select([['Payments By Type',:payments_by_payment_type],['Itemised Payment Totals',:itemised_payment_totals],['Payment Totals',:payment_totals]], @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
= button t(:search)
|
||||
%br
|
||||
%br
|
||||
%table#listing_orders.index
|
||||
%thead
|
||||
%tr{'data-hook' => "orders_header"}
|
||||
- @header.each do |heading|
|
||||
%th=heading
|
||||
%tbody
|
||||
- @table.each do |row|
|
||||
%tr
|
||||
- row.each do |column|
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
@@ -1,24 +0,0 @@
|
||||
- content_for :head do
|
||||
= render 'shared/cms_elrte_head'
|
||||
|
||||
%table{'data-hook' => "suppliers"}
|
||||
%tr{'data-hook' => "name"}
|
||||
%td Name:
|
||||
%td= f.text_field :name
|
||||
%tr{'data-hook' => "description"}
|
||||
%td Description:
|
||||
%td= f.text_field :description
|
||||
%tr{'data-hook' => "long_description"}
|
||||
%td Extended Description:
|
||||
%td= f.text_area :long_description, :class => 'rich_text'
|
||||
= f.fields_for :address do |address_form|
|
||||
= render 'spree/admin/shared/address_form', :f => address_form
|
||||
%tr{'data-hook' => "email"}
|
||||
%td Email:
|
||||
%td= f.text_field :email
|
||||
%tr{'data-hook' => "website"}
|
||||
%td Website:
|
||||
%td= f.text_field :website
|
||||
%tr{'data-hook' => "twitter"}
|
||||
%td Twitter:
|
||||
%td= f.text_field :twitter
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
= form_for [:admin, @supplier] do |f|
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/edit_resource_links'
|
||||
@@ -1,22 +0,0 @@
|
||||
.toolbar{'data-hook' => "suppliers"}
|
||||
%ul.actions
|
||||
%li= button_link_to "New Supplier", spree.new_admin_supplier_path, :icon => 'add', :id => 'admin_new_supplier_link'
|
||||
%br.clear
|
||||
%table#listing_suppliers.index
|
||||
%thead
|
||||
%tr{'data-hook' => "suppliers_header"}
|
||||
%th Name
|
||||
%th Description
|
||||
%th
|
||||
%tbody
|
||||
- @suppliers.each do |supplier|
|
||||
%tr
|
||||
%td= link_to supplier.name, spree.admin_supplier_path(supplier)
|
||||
%td= supplier.description
|
||||
%td{'data-hook' => "admin_supplier_index_row_actions"}
|
||||
= link_to_edit supplier, :class => 'edit'
|
||||
|
||||
= link_to_delete supplier
|
||||
- if @suppliers.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
|
||||
= form_for [:admin, @supplier] do |f|
|
||||
= render :partial => 'form', :locals => { :f => f }
|
||||
= render :partial => 'spree/admin/shared/new_resource_links'
|
||||
@@ -1,27 +0,0 @@
|
||||
%h1 Supplier
|
||||
%table
|
||||
%tr
|
||||
%th Name:
|
||||
%td= @supplier.name
|
||||
%tr
|
||||
%th Description:
|
||||
%td= @supplier.description
|
||||
%tr
|
||||
%th Extended Description:
|
||||
%td= @supplier.long_description.andand.html_safe
|
||||
%tr
|
||||
%th Address:
|
||||
%td= render 'spree/shared/address', :address => @supplier.address
|
||||
%tr
|
||||
%th Email:
|
||||
%td= @supplier.email
|
||||
%tr
|
||||
%th Website:
|
||||
%td= @supplier.website
|
||||
%tr
|
||||
%th Twitter:
|
||||
%td= @supplier.twitter
|
||||
%p
|
||||
= link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
|
||||
= t(:or)
|
||||
= link_to t(:back), spree.admin_suppliers_path
|
||||
@@ -1,27 +1,4 @@
|
||||
.columns.omega.six
|
||||
%fieldset#shipping
|
||||
%legend Distributor
|
||||
%h2= @order.distributor.name
|
||||
%p
|
||||
%strong Address:
|
||||
%br/
|
||||
= render 'spree/shared/address', :address => @order.distributor.pickup_address
|
||||
%p
|
||||
%strong Next collection time:
|
||||
%br/
|
||||
= @order.distributor.next_collection_at
|
||||
%p
|
||||
%strong Regular collection times:
|
||||
%br/
|
||||
= @order.distributor.pickup_times
|
||||
%p
|
||||
%strong Contact:
|
||||
%br/
|
||||
= @order.distributor.contact
|
||||
%br/
|
||||
= "Phone: #{@order.distributor.phone}"
|
||||
%br/
|
||||
= "Email: #{@order.distributor.email}"
|
||||
%p= @order.distributor.description
|
||||
%p= link_to @order.distributor.url, @order.distributor.url if @order.distributor.url
|
||||
|
||||
= render 'enterprises/distributor_details', :distributor => @order.distributor
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
%h2= @distributor.name
|
||||
|
||||
.distributor-description= @distributor.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
@@ -20,7 +20,7 @@ Delivery Details
|
||||
============================================================
|
||||
Address:
|
||||
<%= @order.distributor.name %>
|
||||
<% address = @order.distributor.pickup_address %>
|
||||
<% address = @order.distributor.address %>
|
||||
<%= address.address1 %> <%= ",\n #{address.address2}" unless address.address2.blank? %>
|
||||
<%= [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', ' %>
|
||||
Colection time:
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
- order = current_order(false)
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
%p Distributor
|
||||
= select_tag "distributor_id", options_from_collection_for_select([Spree::Distributor.new]+@product.distributors, "id", "name", current_distributor.andand.id)
|
||||
= select_tag "distributor_id", options_from_collection_for_select([Enterprise.new]+@product.distributors, "id", "name", current_distributor.andand.id)
|
||||
- else
|
||||
= hidden_field_tag "distributor_id", order.distributor.id
|
||||
.distributor-fixed= "Your distributor for this order is #{order.distributor.name}"
|
||||
%br/
|
||||
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
|
||||
= t(:add_to_cart)
|
||||
|
||||
|
||||
8
app/views/spree/products/_distributor_details.html.haml
Normal file
8
app/views/spree/products/_distributor_details.html.haml
Normal file
@@ -0,0 +1,8 @@
|
||||
%fieldset#product-distributor-details.columns.five.omega
|
||||
%legend Distributor
|
||||
.distributor-details
|
||||
- order = current_order(false)
|
||||
- if order.andand.distributor.present?
|
||||
= render 'enterprises/distributor_details', :distributor => order.distributor
|
||||
- else
|
||||
When you select a distributor for your order, their address and pickup times will be displayed here.
|
||||
@@ -2,7 +2,9 @@
|
||||
%h6.filter_name Shop by Supplier
|
||||
%ul.filter_choices
|
||||
- @suppliers.each do |supplier|
|
||||
%li.nowrap= link_to supplier.name, supplier
|
||||
- if supplier.has_supplied_products_on_hand?
|
||||
%li.nowrap= link_to supplier.name, [main_app, supplier]
|
||||
= button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get
|
||||
|
||||
%h6.filter_name Shop by Distributor
|
||||
%ul.filter_choices
|
||||
@@ -10,10 +12,10 @@
|
||||
- @distributors.each do |distributor|
|
||||
%li.nowrap
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
= link_to distributor.name, select_distributor_path(distributor)
|
||||
= link_to distributor.name, main_app.select_distributor_enterprise_path(distributor)
|
||||
- elsif order.distributor == distributor
|
||||
= link_to distributor.name, distributor
|
||||
= link_to distributor.name, [main_app, distributor]
|
||||
- else
|
||||
%span.inactive= distributor.name
|
||||
- if current_distributor && order.can_change_distributor?
|
||||
= button_to 'Browse All Distributors', deselect_distributors_path, :method => :get
|
||||
= button_to 'Browse All Distributors', main_app.deselect_distributor_enterprises_path, :method => :get
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
%h2= @supplier.name
|
||||
|
||||
.supplier-description= @supplier.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
@@ -28,3 +28,8 @@ Openfoodweb::Application.configure do
|
||||
# Expands the lines which load the assets
|
||||
config.assets.debug = true
|
||||
end
|
||||
|
||||
|
||||
# Load heroku vars from local file
|
||||
heroku_env = File.join(Rails.root, 'config', 'heroku_env.rb')
|
||||
load(heroku_env) if File.exists?(heroku_env)
|
||||
|
||||
@@ -34,8 +34,15 @@ ComfortableMexicanSofa.configure do |config|
|
||||
# the upload method and appropriate settings based on Paperclip. For S3 see:
|
||||
# http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/S3, and for
|
||||
# filesystem see: http://rdoc.info/gems/paperclip/2.3.8/Paperclip/Storage/Filesystem
|
||||
# config.upload_file_options = {:url => '/system/:class/:id/:attachment/:style/:filename'}
|
||||
|
||||
config.upload_file_options = {
|
||||
:storage => 's3',
|
||||
:s3_credentials => {
|
||||
:bucket => ENV['S3_BUCKET'],
|
||||
:access_key_id => ENV['S3_KEY'],
|
||||
:secret_access_key => ENV['S3_SECRET']
|
||||
}
|
||||
}
|
||||
|
||||
# Sofa allows you to setup entire site from files. Database is updated with each
|
||||
# request (if necessary). Please note that database entries are destroyed if there's
|
||||
# no corresponding file. Fixtures are disabled by default.
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
Openfoodweb::Application.routes.draw do
|
||||
root :to => 'spree/home#index'
|
||||
|
||||
resources :enterprises do
|
||||
get :suppliers, :on => :collection
|
||||
get :distributors, :on => :collection
|
||||
get :select_distributor, :on => :member
|
||||
get :deselect_distributor, :on => :collection
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
resources :enterprises do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
end
|
||||
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
end
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
resources :suppliers
|
||||
resources :distributors do
|
||||
get :select, :on => :member
|
||||
get :deselect, :on => :collection
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
resources :distributors do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
resources :suppliers
|
||||
end
|
||||
|
||||
match '/admin/reports/orders_and_distributors' => 'admin/reports#orders_and_distributors', :as => "orders_and_distributors_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/group_buys' => 'admin/reports#group_buys', :as => "group_buys_admin_reports", :via => [:get, :post]
|
||||
|
||||
match '/admin/reports/bulk_coop' => 'admin/reports#bulk_coop', :as => "bulk_coop_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/payments' => 'admin/reports#payments', :as => "payments_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/order_cycles' => 'admin/reports#order_cycles', :as => "order_cycles_admin_reports", :via => [:get, :post]
|
||||
end
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
developement:
|
||||
bucket: openfoodweb_test
|
||||
access_key_id: AKIAJ3EE2EKGP36D4PUA
|
||||
secret_access_key: GUvfWLC5G5bpcjqRYOa9/IyxofIPjKQjgJonJuTW
|
||||
production:
|
||||
bucket: openfoodweb_production
|
||||
access_key_id: AKIAJ3EE2EKGP36D4PUA
|
||||
secret_access_key: GUvfWLC5G5bpcjqRYOa9/IyxofIPjKQjgJonJuTW
|
||||
@@ -8,7 +8,7 @@ class MoveDistributorFromOrderToProduct < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
# Associate all products with the first distributor
|
||||
distributor = Spree::Distributor.first
|
||||
distributor = Distributor.first
|
||||
if distributor
|
||||
Spree::Product.all.each do |product|
|
||||
product.distributors << distributor
|
||||
|
||||
@@ -2,9 +2,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
def up
|
||||
# -- Distributors
|
||||
add_column :distributors, :pickup_address_id, :integer
|
||||
Spree::Distributor.reset_column_information
|
||||
Distributor.reset_column_information
|
||||
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Distributor.all.each do |distributor|
|
||||
pickup_address = Spree::Address.create!(:firstname => 'unused',
|
||||
:lastname => 'unused',
|
||||
:phone => 'unused',
|
||||
@@ -24,9 +24,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
|
||||
# -- Suppliers
|
||||
add_column :suppliers, :address_id, :integer
|
||||
Spree::Supplier.reset_column_information
|
||||
Supplier.reset_column_information
|
||||
|
||||
Spree::Supplier.all.each do |supplier|
|
||||
Supplier.all.each do |supplier|
|
||||
address = Spree::Address.create!(:firstname => 'unused',
|
||||
:lastname => 'unused',
|
||||
:phone => 'unused',
|
||||
@@ -51,9 +51,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
add_column :distributors, :post_code, :string
|
||||
add_column :distributors, :state_id, :integer
|
||||
add_column :distributors, :country_id, :integer
|
||||
Spree::Distributor.reset_column_information
|
||||
Distributor.reset_column_information
|
||||
|
||||
Spree::Distributor.all.each do |distributor|
|
||||
Distributor.all.each do |distributor|
|
||||
distributor[:pickup_address] = distributor.pickup_address.address1
|
||||
distributor.city = distributor.pickup_address.city
|
||||
distributor.post_code = distributor.pickup_address.zipcode
|
||||
@@ -71,9 +71,9 @@ class ExtractDistributorAndSupplierAddressToSpreeAddress < ActiveRecord::Migrati
|
||||
add_column :suppliers, :postcode, :string
|
||||
add_column :suppliers, :state_id, :integer
|
||||
add_column :suppliers, :country_id, :integer
|
||||
Spree::Supplier.reset_column_information
|
||||
Supplier.reset_column_information
|
||||
|
||||
Spree::Supplier.all.each do |supplier|
|
||||
Supplier.all.each do |supplier|
|
||||
supplier[:address] = supplier.address.address1
|
||||
supplier.city = supplier.address.city
|
||||
supplier.post_code = supplier.address.zipcode
|
||||
|
||||
@@ -10,7 +10,7 @@ class RenameDistributorsProductsToProductDistributions < ActiveRecord::Migration
|
||||
|
||||
# Set default shipping method on all product distributions
|
||||
sm = Spree::ShippingMethod.first
|
||||
Spree::ProductDistribution.update_all(:shipping_method_id => sm.id) if sm
|
||||
ProductDistribution.update_all(:shipping_method_id => sm.id) if sm
|
||||
end
|
||||
|
||||
def down
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddGroupBuyUnitSizeToProducts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_products, :group_buy_unit_size, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
class CombineSuppliersAndDistributorsIntoEnterprises < ActiveRecord::Migration
|
||||
class Supplier < ActiveRecord::Base; end
|
||||
class Distributor < ActiveRecord::Base; end
|
||||
class Enterprise < ActiveRecord::Base; end
|
||||
class ProductDistribution < ActiveRecord::Base; end
|
||||
class Spree::Product < ActiveRecord::Base; end
|
||||
class Spree::Order < ActiveRecord::Base; end
|
||||
|
||||
|
||||
def up
|
||||
# Create enterprises table
|
||||
create_table :enterprises do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.text :long_description
|
||||
t.boolean :is_primary_producer
|
||||
t.boolean :is_distributor
|
||||
t.string :contact
|
||||
t.string :phone
|
||||
t.string :email
|
||||
t.string :website
|
||||
t.string :twitter
|
||||
t.string :abn
|
||||
t.string :acn
|
||||
t.integer :address_id
|
||||
t.string :pickup_times
|
||||
t.integer :pickup_address_id
|
||||
t.string :next_collection_at
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# Copy suppliers to enterprises table with primary producer flag set
|
||||
updated_product_ids = [-1]
|
||||
Supplier.all.each do |s|
|
||||
attrs = s.attributes
|
||||
attrs.reject! { |k| k == 'id' }
|
||||
attrs.merge! is_primary_producer: true, is_distributor: false
|
||||
e = Enterprise.create! attrs
|
||||
|
||||
# Update supplier_id on product to point at the new enterprise
|
||||
product_ids = Spree::Product.where(:supplier_id => s.id).pluck(:id)
|
||||
Spree::Product.update_all("supplier_id=#{e.id}", "supplier_id=#{s.id} AND id NOT IN (#{updated_product_ids.join(', ')})")
|
||||
updated_product_ids += product_ids
|
||||
end
|
||||
|
||||
# Copy distributors to enterprises table with distributor flag set
|
||||
updated_product_distribution_ids = [-1]
|
||||
updated_order_ids = [-1]
|
||||
Distributor.all.each do |d|
|
||||
attrs = d.attributes
|
||||
attrs['website'] = attrs['url']
|
||||
attrs.reject! { |k| ['id', 'url'].include? k }
|
||||
attrs.merge! is_primary_producer: false, is_distributor: true
|
||||
e = Enterprise.create! attrs
|
||||
|
||||
# Update distributor_id on product distribution and order to point at the new enterprise
|
||||
product_distribution_ids = ProductDistribution.where(:distributor_id => d.id).pluck(:id)
|
||||
order_ids = Spree::Order.where(:distributor_id => d.id).pluck(:id)
|
||||
ProductDistribution.update_all("distributor_id=#{e.id}", "distributor_id=#{d.id} AND id NOT IN (#{updated_product_distribution_ids.join(', ')})")
|
||||
Spree::Order.update_all("distributor_id=#{e.id}", "distributor_id=#{d.id} AND id NOT IN (#{updated_order_ids.join(', ')})")
|
||||
updated_product_distribution_ids += product_distribution_ids
|
||||
updated_order_ids += order_ids
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :enterprises
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
class RemovePickupAddressFromEnterprises < ActiveRecord::Migration
|
||||
class Enterprise < ActiveRecord::Base; end
|
||||
|
||||
def up
|
||||
Enterprise.all.each do |e|
|
||||
e.address_id ||= e.pickup_address_id
|
||||
e.save!
|
||||
end
|
||||
|
||||
remove_column :enterprises, :pickup_address_id
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :enterprises, :pickup_address_id, :integer
|
||||
|
||||
Enterprise.all.each do |e|
|
||||
e.pickup_address_id ||= e.address_id
|
||||
e.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
class ChangeGroupBuyUnitSizeFromStringToFloat < ActiveRecord::Migration
|
||||
class Spree::Product < ActiveRecord::Base; end
|
||||
|
||||
def up
|
||||
add_column :spree_products, :group_buy_unit_size_f, :float
|
||||
Spree::Product.reset_column_information
|
||||
|
||||
Spree::Product.all.each do |product|
|
||||
product.group_buy_unit_size_f = product.group_buy_unit_size.to_f
|
||||
product.save!
|
||||
end
|
||||
|
||||
remove_column :spree_products, :group_buy_unit_size
|
||||
rename_column :spree_products, :group_buy_unit_size_f, :group_buy_unit_size
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :spree_products, :group_buy_unit_size, :string
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
class RemoveSuppliersAndDistributors < ActiveRecord::Migration
|
||||
def up
|
||||
drop_table :suppliers
|
||||
drop_table :distributors
|
||||
end
|
||||
|
||||
def down
|
||||
create_table "distributors" do |t|
|
||||
t.string :name
|
||||
t.string :contact
|
||||
t.string :phone
|
||||
t.string :email
|
||||
t.string :pickup_times
|
||||
t.string :url
|
||||
t.string :abn
|
||||
t.string :acn
|
||||
t.string :description
|
||||
t.datetime :created_at
|
||||
t.datetime :updated_at
|
||||
t.integer :pickup_address_id
|
||||
t.string :next_collection_at
|
||||
t.text :long_description
|
||||
end
|
||||
|
||||
create_table "suppliers" do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.string :email
|
||||
t.string :twitter
|
||||
t.string :website
|
||||
t.datetime :created_at
|
||||
t.datetime :updated_at
|
||||
t.integer :address_id
|
||||
t.text :long_description
|
||||
end
|
||||
end
|
||||
end
|
||||
34
db/schema.rb
34
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121010004400) do
|
||||
ActiveRecord::Schema.define(:version => 20121031222403) do
|
||||
|
||||
create_table "cms_blocks", :force => true do |t|
|
||||
t.integer "page_id", :null => false
|
||||
@@ -130,21 +130,24 @@ ActiveRecord::Schema.define(:version => 20121010004400) do
|
||||
add_index "cms_snippets", ["site_id", "identifier"], :name => "index_cms_snippets_on_site_id_and_identifier", :unique => true
|
||||
add_index "cms_snippets", ["site_id", "position"], :name => "index_cms_snippets_on_site_id_and_position"
|
||||
|
||||
create_table "distributors", :force => true do |t|
|
||||
create_table "enterprises", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.text "long_description"
|
||||
t.boolean "is_primary_producer"
|
||||
t.boolean "is_distributor"
|
||||
t.string "contact"
|
||||
t.string "phone"
|
||||
t.string "email"
|
||||
t.string "pickup_times"
|
||||
t.string "url"
|
||||
t.string "website"
|
||||
t.string "twitter"
|
||||
t.string "abn"
|
||||
t.string "acn"
|
||||
t.string "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "pickup_address_id"
|
||||
t.integer "address_id"
|
||||
t.string "pickup_times"
|
||||
t.string "next_collection_at"
|
||||
t.text "long_description"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "product_distributions", :force => true do |t|
|
||||
@@ -487,6 +490,7 @@ ActiveRecord::Schema.define(:version => 20121010004400) do
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.integer "supplier_id"
|
||||
t.boolean "group_buy"
|
||||
t.float "group_buy_unit_size"
|
||||
end
|
||||
|
||||
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
|
||||
@@ -772,16 +776,4 @@ ActiveRecord::Schema.define(:version => 20121010004400) do
|
||||
t.integer "zone_members_count", :default => 0
|
||||
end
|
||||
|
||||
create_table "suppliers", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.string "email"
|
||||
t.string "twitter"
|
||||
t.string "website"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "address_id"
|
||||
t.text "long_description"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
22
db/seeds.rb
22
db/seeds.rb
@@ -59,12 +59,12 @@ unless Spree::Taxonomy.find_by_name 'Products'
|
||||
end
|
||||
|
||||
|
||||
# -- Suppliers and distributors
|
||||
unless Spree::Supplier.count > 0
|
||||
puts "[db:seed] Seeding suppliers and distributors"
|
||||
# -- Enterprises
|
||||
unless Enterprise.count > 0
|
||||
puts "[db:seed] Seeding enterprises"
|
||||
|
||||
3.times { FactoryGirl.create(:supplier) }
|
||||
3.times { FactoryGirl.create(:distributor) }
|
||||
3.times { FactoryGirl.create(:supplier_enterprise) }
|
||||
3.times { FactoryGirl.create(:distributor_enterprise) }
|
||||
end
|
||||
|
||||
|
||||
@@ -74,19 +74,19 @@ unless Spree::Product.count > 0
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Garlic', :price => 20.00,
|
||||
:supplier => Spree::Supplier.all[0],
|
||||
:distributors => [Spree::Distributor.all[0]],
|
||||
:supplier => Enterprise.is_primary_producer[0],
|
||||
:distributors => [Enterprise.is_distributor[0]],
|
||||
:taxons => [Spree::Taxon.find_by_name('Vegetables')])
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Fuji Apple', :price => 5.00,
|
||||
:supplier => Spree::Supplier.all[1],
|
||||
:distributors => Spree::Distributor.all,
|
||||
:supplier => Enterprise.is_primary_producer[1],
|
||||
:distributors => Enterprise.is_distributor,
|
||||
:taxons => [Spree::Taxon.find_by_name('Fruit')])
|
||||
|
||||
FactoryGirl.create(:product,
|
||||
:name => 'Beef - 5kg Trays', :price => 50.00,
|
||||
:supplier => Spree::Supplier.all[2],
|
||||
:distributors => [Spree::Distributor.all[2]],
|
||||
:supplier => Enterprise.is_primary_producer[2],
|
||||
:distributors => [Enterprise.is_distributor[2]],
|
||||
:taxons => [Spree::Taxon.find_by_name('Meat and Fish')])
|
||||
end
|
||||
|
||||
@@ -38,8 +38,8 @@ module OpenFoodWeb
|
||||
end
|
||||
|
||||
# Sum quantities for each product (Total line)
|
||||
sum_quantities = line_items_by_product.sum { |li| li.variant.weight * li.quantity }
|
||||
sum_max_quantities = line_items_by_product.sum { |li| li.variant.weight * (li.max_quantity || 0) }
|
||||
sum_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * li.quantity }
|
||||
sum_max_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * (li.max_quantity || 0) }
|
||||
variants_and_quantities << GroupBuyProductRow.new(product, sum_quantities, sum_max_quantities)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ module OpenFoodWeb
|
||||
order.bill_address.full_name, order.email, order.bill_address.phone, order.bill_address.city,
|
||||
line_item.product.sku, line_item.product.name, line_item.variant.options_text, line_item.quantity, line_item.max_quantity, line_item.price * line_item.quantity, line_item.itemwise_shipping_cost,
|
||||
order.payments.first.payment_method.andand.name,
|
||||
order.distributor.andand.name, order.distributor.pickup_address.address1, order.distributor.pickup_address.city, order.distributor.pickup_address.zipcode, order.special_instructions ]
|
||||
order.distributor.andand.name, order.distributor.address.address1, order.distributor.address.city, order.distributor.address.zipcode, order.special_instructions ]
|
||||
end
|
||||
end
|
||||
order_and_distributor_details
|
||||
|
||||
58
lib/open_food_web/order_grouper.rb
Normal file
58
lib/open_food_web/order_grouper.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
module OpenFoodWeb
|
||||
|
||||
class OrderGrouper
|
||||
def initialize(rules, column_constructors)
|
||||
@rules = rules
|
||||
@column_constructors = column_constructors
|
||||
end
|
||||
|
||||
def build_tree(items, remaining_rules)
|
||||
rules = remaining_rules.clone
|
||||
unless rules.empty?
|
||||
rule = rules.delete_at(0) # Remove current rule for subsequent groupings
|
||||
group_and_sort(rule, rules, items)
|
||||
else
|
||||
items
|
||||
end
|
||||
end
|
||||
|
||||
def group_and_sort(rule, remaining_rules, items)
|
||||
branch = {}
|
||||
groups = items.group_by { |item| rule[:group_by].call(item) }
|
||||
sorted_groups = groups.sort_by { |key, value| rule[:sort_by].call(key) }
|
||||
sorted_groups.each do |property,items_by_property|
|
||||
branch[property] = build_tree(items_by_property, remaining_rules)
|
||||
branch[property][:summary_row] = { items: items_by_property, columns: rule[:summary_columns] } unless rule[:summary_columns] == nil || is_leaf_node(branch[property])
|
||||
end
|
||||
branch
|
||||
end
|
||||
|
||||
def build_table(groups)
|
||||
rows = []
|
||||
unless is_leaf_node(groups)
|
||||
groups.each do |key, group|
|
||||
unless key == :summary_row
|
||||
build_table(group).each { |g| rows << g }
|
||||
else
|
||||
rows << group[:columns].map { |cols| cols.call(group[:items]) }
|
||||
end
|
||||
end
|
||||
else
|
||||
rows << @column_constructors.map { |column_constructor| column_constructor.call(groups) }
|
||||
end
|
||||
rows
|
||||
end
|
||||
|
||||
def table(items)
|
||||
tree = build_tree(items,@rules)
|
||||
table = build_table(tree)
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def is_leaf_node(node)
|
||||
node.is_a? Array
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -14,6 +14,7 @@ module OpenFoodWeb
|
||||
def get_base_scope
|
||||
base_scope = super
|
||||
|
||||
base_scope = base_scope.in_supplier_or_distributor(enterprise_id) if enterprise_id
|
||||
base_scope = base_scope.in_supplier(supplier_id) if supplier_id
|
||||
base_scope = base_scope.in_distributor(distributor_id) if distributor_id
|
||||
|
||||
@@ -23,6 +24,7 @@ module OpenFoodWeb
|
||||
|
||||
def prepare(params)
|
||||
super(params)
|
||||
@properties[:enterprise_id] = params[:enterprise_id]
|
||||
@properties[:supplier_id] = params[:supplier_id]
|
||||
@properties[:distributor_id] = params[:distributor_id]
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Spree
|
||||
module ProductFilters
|
||||
if Spree::Distributor.table_exists?
|
||||
if Enterprise.table_exists?
|
||||
Spree::Product.scope :distributor_any,
|
||||
lambda {|*opts|
|
||||
conds = opts.map {|o| ProductFilters.distributor_filter[:conds][o]}.reject {|c| c.nil?}
|
||||
@@ -8,8 +8,8 @@ module Spree
|
||||
}
|
||||
|
||||
def ProductFilters.distributor_filter
|
||||
distributors = Spree::Distributor.all.map(&:name).compact.uniq
|
||||
conds = Hash[*distributors.map { |d| [d, "#{Spree::Distributor.table_name}.name = '#{d}'"] }.flatten]
|
||||
distributors = Enterprise.is_distributor.map(&:name).compact.uniq
|
||||
conds = Hash[*distributors.map { |d| [d, "#{Enterprise.table_name}.name = '#{d}'"] }.flatten]
|
||||
{ :name => "Group",
|
||||
:scope => :distributor_any,
|
||||
:conds => conds,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
require 'spree/core/current_order'
|
||||
|
||||
describe Spree::DistributorsController do
|
||||
describe EnterprisesController do
|
||||
include Spree::Core::CurrentOrder
|
||||
|
||||
before :each do
|
||||
@@ -11,11 +11,19 @@ describe Spree::DistributorsController do
|
||||
create(:itemwise_shipping_method)
|
||||
end
|
||||
|
||||
it "displays suppliers" do
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
spree_get :suppliers
|
||||
|
||||
assigns(:suppliers).should == [s]
|
||||
end
|
||||
|
||||
it "selects distributors" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
spree_get :select, :id => d.id
|
||||
spree_get :select_distributor, :id => d.id
|
||||
response.should be_redirect
|
||||
|
||||
order = current_order(false)
|
||||
@@ -23,12 +31,12 @@ describe Spree::DistributorsController do
|
||||
end
|
||||
|
||||
it "deselects distributors" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
order = current_order(true)
|
||||
order.distributor = d
|
||||
order.save!
|
||||
|
||||
spree_get :deselect
|
||||
spree_get :deselect_distributor
|
||||
response.should be_redirect
|
||||
|
||||
order.reload
|
||||
@@ -38,8 +46,8 @@ describe Spree::DistributorsController do
|
||||
context "when a product has been added to the cart" do
|
||||
it "does not allow selecting another distributor" do
|
||||
# Given some distributors and an order with a product
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1])
|
||||
o = current_order(true)
|
||||
|
||||
@@ -48,7 +56,7 @@ describe Spree::DistributorsController do
|
||||
o.add_variant(p.master, 1)
|
||||
|
||||
# When I attempt to select a distributor
|
||||
spree_get :select, :id => d2.id
|
||||
spree_get :select_distributor, :id => d2.id
|
||||
|
||||
# Then my distributor should remain unchanged
|
||||
o.reload
|
||||
@@ -57,7 +65,7 @@ describe Spree::DistributorsController do
|
||||
|
||||
it "does not allow deselecting distributors" do
|
||||
# Given a distributor and an order with a product
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
o = current_order(true)
|
||||
o.distributor = d
|
||||
@@ -65,7 +73,7 @@ describe Spree::DistributorsController do
|
||||
o.add_variant(p.master, 1)
|
||||
|
||||
# When I attempt to deselect the distributor
|
||||
spree_get :deselect
|
||||
spree_get :deselect_distributor
|
||||
|
||||
# Then my distributor should remain unchanged
|
||||
o.reload
|
||||
@@ -11,8 +11,8 @@ describe Spree::HomeController do
|
||||
|
||||
it "splits products by local/remote distributor when distributor is selected" do
|
||||
# Given two distributors with a product under each
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ describe Spree::OrdersController do
|
||||
|
||||
context "adding the first product to the cart" do
|
||||
it "does not add the product if the user does not specify a distributor" do
|
||||
create(:distributor)
|
||||
create(:distributor_enterprise)
|
||||
p = create(:product)
|
||||
|
||||
expect do
|
||||
@@ -20,8 +20,8 @@ describe Spree::OrdersController do
|
||||
end
|
||||
|
||||
it "does not add the product if the user specifies a distributor that the product is not available at" do
|
||||
distributor_product = create(:distributor)
|
||||
distributor_no_product = create(:distributor)
|
||||
distributor_product = create(:distributor_enterprise)
|
||||
distributor_no_product = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [distributor_product])
|
||||
|
||||
expect do
|
||||
@@ -30,8 +30,8 @@ describe Spree::OrdersController do
|
||||
end
|
||||
|
||||
it "adds the product and sets the distributor even if the order has a different distributor set" do
|
||||
distributor_product = create(:distributor)
|
||||
distributor_no_product = create(:distributor)
|
||||
distributor_product = create(:distributor_enterprise)
|
||||
distributor_no_product = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [distributor_product])
|
||||
|
||||
order = current_order(true)
|
||||
@@ -47,7 +47,7 @@ describe Spree::OrdersController do
|
||||
|
||||
it "sets the order's distributor" do
|
||||
# Given a product in a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
# When we add the product to our cart
|
||||
@@ -61,7 +61,7 @@ describe Spree::OrdersController do
|
||||
context "adding a subsequent product to the cart" do
|
||||
before(:each) do
|
||||
# Given a product and a distributor
|
||||
@distributor = create(:distributor)
|
||||
@distributor = create(:distributor_enterprise)
|
||||
@product = create(:product, :distributors => [@distributor])
|
||||
|
||||
# And the product is in the cart
|
||||
@@ -72,7 +72,7 @@ describe Spree::OrdersController do
|
||||
|
||||
it "does not add the product if the product is not available at the order's distributor" do
|
||||
# Given a product at another distributor
|
||||
d2 = create(:distributor)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I attempt to add the product to the cart
|
||||
@@ -85,7 +85,7 @@ describe Spree::OrdersController do
|
||||
|
||||
it "does not add the product if the product is not available at the given distributor" do
|
||||
# Given a product at another distributor
|
||||
d2 = create(:distributor)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I attempt to add the product to the cart with a fake distributor_id
|
||||
@@ -98,7 +98,7 @@ describe Spree::OrdersController do
|
||||
|
||||
it "does not add the product if the chosen distributor is different from the order's distributor" do
|
||||
# Given a product that's available at the chosen distributor and another distributor
|
||||
d2 = create(:distributor)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p2 = create(:product, :distributors => [@distributor, d2])
|
||||
|
||||
# When I attempt to add the product to the cart with the alternate distributor
|
||||
@@ -112,7 +112,7 @@ describe Spree::OrdersController do
|
||||
|
||||
context "adding a group buy product to the cart" do
|
||||
it "sets a variant attribute for the max quantity" do
|
||||
distributor_product = create(:distributor)
|
||||
distributor_product = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [distributor_product], :group_buy => true)
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
@@ -2,30 +2,27 @@ require 'faker'
|
||||
require 'spree/core/testing_support/factories'
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :supplier, :class => Spree::Supplier do
|
||||
sequence(:name) { |n| "Supplier #{n}" }
|
||||
description 'supplier'
|
||||
factory :enterprise, :class => Enterprise do
|
||||
sequence(:name) { |n| "Enterprise #{n}" }
|
||||
description 'enterprise'
|
||||
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
|
||||
email 'supplier@example.com'
|
||||
email 'enterprise@example.com'
|
||||
address { Spree::Address.first || FactoryGirl.create(:address) }
|
||||
end
|
||||
|
||||
factory :distributor, :class => Spree::Distributor do
|
||||
sequence(:name) { |n| "Distributor #{n}" }
|
||||
contact 'Mr Turing'
|
||||
phone '1000100100'
|
||||
description 'The creator'
|
||||
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
|
||||
email 'alan@somewhere.com'
|
||||
url 'http://example.com'
|
||||
pickup_times "Whenever you're free"
|
||||
next_collection_at 'Thursday 10am'
|
||||
pickup_address { Spree::Address.first || FactoryGirl.create(:address) }
|
||||
factory :supplier_enterprise, :parent => :enterprise do
|
||||
is_primary_producer true
|
||||
is_distributor false
|
||||
end
|
||||
|
||||
factory :product_distribution, :class => Spree::ProductDistribution do
|
||||
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
|
||||
distributor { |pd| Spree::Distributor.first || FactoryGirl.create(:distributor) }
|
||||
factory :distributor_enterprise, :parent => :enterprise do
|
||||
is_primary_producer false
|
||||
is_distributor true
|
||||
end
|
||||
|
||||
factory :product_distribution, :class => ProductDistribution do
|
||||
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
|
||||
distributor { |pd| Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) }
|
||||
shipping_method { |pd| Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) }
|
||||
end
|
||||
|
||||
@@ -46,7 +43,7 @@ FactoryGirl.modify do
|
||||
# When this fix has been merged into a version of Spree that we're using, this line can be removed.
|
||||
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
|
||||
|
||||
supplier { Spree::Supplier.first || FactoryGirl.create(:supplier) }
|
||||
supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) }
|
||||
on_hand 3
|
||||
|
||||
# before(:create) do |product, evaluator|
|
||||
|
||||
@@ -7,9 +7,9 @@ module OpenFoodWeb
|
||||
@orders = []
|
||||
bill_address = create(:address)
|
||||
distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
|
||||
distributor = create(:distributor, :pickup_address => distributor_address)
|
||||
distributor = create(:distributor_enterprise, :address => distributor_address)
|
||||
|
||||
@supplier1 = create(:supplier)
|
||||
@supplier1 = create(:supplier_enterprise)
|
||||
@variant1 = create(:variant)
|
||||
@variant1.product.supplier = @supplier1
|
||||
@variant1.product.save!
|
||||
@@ -35,8 +35,8 @@ module OpenFoodWeb
|
||||
order2.line_items << line_item22
|
||||
@orders << order2
|
||||
|
||||
@supplier2 = create(:supplier)
|
||||
@variant3 = create(:variant)
|
||||
@supplier2 = create(:supplier_enterprise)
|
||||
@variant3 = create(:variant, :weight => nil)
|
||||
@variant3.product.supplier = @supplier2
|
||||
@variant3.product.save!
|
||||
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
@@ -82,16 +82,16 @@ module OpenFoodWeb
|
||||
|
||||
table_row_objects = subject.variants_and_quantities
|
||||
|
||||
variant_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
variant_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
|
||||
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
|
||||
variant_groups = variant_rows.group_by{ |r| r.variant }
|
||||
product_groups = product_rows.group_by{ |r| r.product }
|
||||
variant_groups = variant_rows.group_by { |r| r.variant }
|
||||
product_groups = product_rows.group_by { |r| r.product }
|
||||
|
||||
supplier_groups.length.should == 2
|
||||
variant_groups.length.should == 3
|
||||
product_groups.length.should == 3
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ module OpenFoodWeb
|
||||
before(:each) do
|
||||
@bill_address = create(:address)
|
||||
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
|
||||
@distributor = create(:distributor, :pickup_address => @distributor_address)
|
||||
@distributor = create(:distributor_enterprise, :address => @distributor_address)
|
||||
product = create(:product)
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor, :shipping_method => create(:shipping_method))
|
||||
@shipping_instructions = "pick up on thursday please!"
|
||||
@@ -41,7 +41,7 @@ module OpenFoodWeb
|
||||
@bill_address.full_name, @order.email, @bill_address.phone, @bill_address.city,
|
||||
@line_item.product.sku, @line_item.product.name, @line_item.variant.options_text, @line_item.quantity, @line_item.max_quantity, @line_item.price * @line_item.quantity, @line_item.itemwise_shipping_cost,
|
||||
@payment_method.name,
|
||||
@distributor.name, @distributor.pickup_address.address1, @distributor.pickup_address.city, @distributor.pickup_address.zipcode, @shipping_instructions ]
|
||||
@distributor.name, @distributor.address.address1, @distributor.address.city, @distributor.address.zipcode, @shipping_instructions ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
152
spec/lib/open_food_web/order_grouper_spec.rb
Normal file
152
spec/lib/open_food_web/order_grouper_spec.rb
Normal file
@@ -0,0 +1,152 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module OpenFoodWeb
|
||||
describe OrderGrouper do
|
||||
|
||||
before(:each) do
|
||||
@items = [1, 2, 3, 4]
|
||||
end
|
||||
|
||||
context "constructing the table" do
|
||||
it "should build a tree then build a table" do
|
||||
rules = [ { group_by: Proc.new { |sentence| sentence.paragraph.chapter }, sort_by: Proc.new { |chapter| chapter.name }, summary_columns: [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| "TOTAL" }, Proc.new { |is| "" }, Proc.new { |is| is.sum {|i| i.property1 } } ] },
|
||||
{ group_by: Proc.new { |sentence| sentence.paragraph }, sort_by: Proc.new { |paragraph| paragraph.name } } ]
|
||||
columns = [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| is.first.paragraph.name }, Proc.new { |is| is.first.name }, Proc.new { |is| is.sum {|i| i.property1 } }]
|
||||
|
||||
subject = OrderGrouper.new rules, columns
|
||||
|
||||
tree = double(:tree)
|
||||
subject.should_receive(:build_tree).with(@items, rules).and_return(tree)
|
||||
subject.should_receive(:build_table).with(tree)
|
||||
|
||||
subject.table(@items)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "grouping items without rules" do
|
||||
it "returns the original array when no rules are provided" do
|
||||
rules = []
|
||||
column1 = double(:col1)
|
||||
column2 = double(:col2)
|
||||
columns = [column1, column2]
|
||||
subject = OrderGrouper.new rules, columns
|
||||
|
||||
rules.should_receive(:clone).and_return(rules)
|
||||
subject.build_tree(@items, rules).should == @items
|
||||
end
|
||||
end
|
||||
|
||||
context "grouping items with rules" do
|
||||
|
||||
before(:each) do
|
||||
@rule1 = double(:rule1)
|
||||
rule2 = double(:rule2)
|
||||
@rules = [@rule1, rule2]
|
||||
@remaining_rules = [rule2]
|
||||
column1 = double(:col1)
|
||||
column2 = double(:col2)
|
||||
@columns = [column1, column2]
|
||||
end
|
||||
|
||||
it "builds branches by removing a rule from 'rules' and running group_and_sort" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
@rules.should_receive(:clone).and_return(@rules)
|
||||
@rules.should_receive(:delete_at).with(0)
|
||||
grouped_tree = double(:grouped_tree)
|
||||
subject.should_receive(:group_and_sort).and_return(grouped_tree)
|
||||
|
||||
subject.build_tree(@items, @rules).should == grouped_tree
|
||||
end
|
||||
|
||||
it "separates the first rule from rules before sending to group_and_sort" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
grouped_tree = double(:grouped_tree)
|
||||
subject.should_receive(:group_and_sort).with(@rule1, @rules[1..-1], @items).and_return(grouped_tree)
|
||||
|
||||
subject.build_tree(@items, @rules).should == grouped_tree
|
||||
end
|
||||
|
||||
it "should group, then sort, send each group to build_tree, and return a branch" do
|
||||
summary_columns_object = double(:summary_columns)
|
||||
@rule1.stub(:[]).with(:summary_columns) { summary_columns_object }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
number_of_categories = 3
|
||||
groups = double(:groups)
|
||||
@items.should_receive(:group_by).and_return(groups)
|
||||
sorted_groups = {}
|
||||
1.upto(number_of_categories) { |i| sorted_groups[i] = double(:group, name: "Group "+ i.to_s ) }
|
||||
groups.should_receive(:sort_by).and_return(sorted_groups)
|
||||
group = { group1: 1, group2: 2, group3: 3 }
|
||||
subject.should_receive(:build_tree).exactly(number_of_categories).times.and_return(group)
|
||||
|
||||
group_tree = {}
|
||||
1.upto(number_of_categories) { |i| group_tree[i] = group }
|
||||
1.upto(number_of_categories) { |i| group_tree[i][:summary_row] = summary_columns_object }
|
||||
subject.group_and_sort(@rule1, @remaining_rules, @items).should == group_tree
|
||||
end
|
||||
end
|
||||
|
||||
context "building the table Array" do
|
||||
before(:each) do
|
||||
rule1 = double(:rule1)
|
||||
rule2 = double(:rule2)
|
||||
@rules = [rule1, rule2]
|
||||
@column1 = double(:col1, :call => "Column1")
|
||||
@column2 = double(:col2, :call => "Column2")
|
||||
@columns = [@column1, @column2]
|
||||
|
||||
sumcol1 = double(:sumcol1, :call => "SumColumn1")
|
||||
sumcol2 = double(:sumcol2, :call => "SumColumn2")
|
||||
@sumcols = [sumcol1, sumcol2]
|
||||
|
||||
item1 = double(:item1)
|
||||
item2 = double(:item2)
|
||||
item3 = double(:item3)
|
||||
@items1 = [item1, item2]
|
||||
@items2 = [item2, item3]
|
||||
@items3 = [item3, item1]
|
||||
end
|
||||
it "should return columns when given an Array" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
@column1.should_receive(:call)
|
||||
@column2.should_receive(:call)
|
||||
|
||||
subject.build_table(@items1).should == [["Column1", "Column2"]]
|
||||
end
|
||||
|
||||
it "should return a row for each key-value pair when given a Hash" do
|
||||
groups = { items1: @items1, items2: @items2, items3: @items3 }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
#subject.should_receive(:build_table).exactly(2).times
|
||||
|
||||
expected_return = []
|
||||
groups.length.times { expected_return << ["Column1", "Column2"] }
|
||||
subject.build_table(groups).should == expected_return
|
||||
end
|
||||
|
||||
it "should return an extra row when a :summary_row key appears in a given Hash" do
|
||||
groups = { items1: @items1, items2: @items2, items3: @items3, summary_row: { items: { items2: @items2, items3: @items3 }, columns: @sumcols } }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
expected_return = []
|
||||
groups.each do |key, group|
|
||||
if key == :summary_row
|
||||
expected_return << ["SumColumn1", "SumColumn2"]
|
||||
else
|
||||
expected_return << ["Column1", "Column2"]
|
||||
end
|
||||
end
|
||||
subject.build_table(groups).should == expected_return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,8 +5,8 @@ module OpenFoodWeb
|
||||
describe Searcher do
|
||||
it "searches by supplier" do
|
||||
# Given products under two suppliers
|
||||
s1 = create(:supplier)
|
||||
s2 = create(:supplier)
|
||||
s1 = create(:supplier_enterprise)
|
||||
s2 = create(:supplier_enterprise)
|
||||
p1 = create(:product, :supplier => s1)
|
||||
p2 = create(:product, :supplier => s2)
|
||||
|
||||
@@ -18,8 +18,8 @@ module OpenFoodWeb
|
||||
|
||||
it "searches by distributor" do
|
||||
# Given products under two distributors
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
@@ -28,5 +28,25 @@ module OpenFoodWeb
|
||||
products = searcher.retrieve_products
|
||||
products.should == [p1]
|
||||
end
|
||||
|
||||
it "searches by supplier or distributor" do
|
||||
# Given products under some suppliers and distributors
|
||||
s0 = create(:supplier_enterprise)
|
||||
s1 = create(:supplier_enterprise)
|
||||
d1 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :supplier => s1)
|
||||
p2 = create(:product, :distributors => [d1])
|
||||
p3 = create(:product)
|
||||
|
||||
# When we search by the supplier enterprise, we should see the supplied products
|
||||
searcher = Searcher.new(:enterprise_id => s1.id.to_s)
|
||||
products = searcher.retrieve_products
|
||||
products.should == [p1]
|
||||
|
||||
# When we search by the distributor enterprise, we should see the distributed products
|
||||
searcher = Searcher.new(:enterprise_id => d1.id.to_s)
|
||||
products = searcher.retrieve_products
|
||||
products.should == [p2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,8 +16,8 @@ describe OpenFoodWeb::SplitProductsByDistributor do
|
||||
end
|
||||
|
||||
it "splits products when a distributor is selected" do
|
||||
d1 = build(:distributor)
|
||||
d2 = build(:distributor)
|
||||
d1 = build(:distributor_enterprise)
|
||||
d2 = build(:distributor_enterprise)
|
||||
orig_products = [build(:product, :distributors => [d1]),
|
||||
build(:product, :distributors => [d2])]
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ require 'spec_helper'
|
||||
describe Spree::ProductFilters do
|
||||
context "distributor filter" do
|
||||
it "provides filtering for all distributors" do
|
||||
3.times { create(:distributor) }
|
||||
Spree::ProductFilters.distributor_filter[:labels].should == Spree::Distributor.all.map { |d| [d.name, d.name] }
|
||||
3.times { create(:distributor_enterprise) }
|
||||
Spree::ProductFilters.distributor_filter[:labels].should == Enterprise.is_distributor.map { |d| [d.name, d.name] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Distributor do
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:pickup_address) }
|
||||
it { should have_many(:product_distributions) }
|
||||
it { should have_many(:orders) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { should validate_presence_of(:name) }
|
||||
end
|
||||
|
||||
it "should default country to system country" do
|
||||
distributor = Distributor.new
|
||||
distributor.pickup_address.country.should == Country.find_by_id(Config[:default_country_id])
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
it "returns distributors with products in stock" do
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d3 = create(:distributor)
|
||||
d4 = create(:distributor)
|
||||
create(:product, :distributors => [d1, d2], :on_hand => 5)
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 0)
|
||||
|
||||
Distributor.with_active_products_on_hand.sort.should == [d1, d2]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
53
spec/models/enterprises_spec.rb
Normal file
53
spec/models/enterprises_spec.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Enterprise do
|
||||
|
||||
describe "associations" do
|
||||
it { should have_many(:supplied_products) }
|
||||
it { should have_many(:distributed_orders) }
|
||||
it { should belong_to(:address) }
|
||||
it { should have_many(:product_distributions) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { should validate_presence_of(:name) }
|
||||
end
|
||||
|
||||
it "should default address country to system country" do
|
||||
subject.address.country.should == Spree::Country.find_by_id(Spree::Config[:default_country_id])
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
it "returns distributors with products in stock" do
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
d4 = create(:distributor_enterprise)
|
||||
create(:product, :distributors => [d1, d2], :on_hand => 5)
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 0)
|
||||
|
||||
Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2]
|
||||
end
|
||||
end
|
||||
|
||||
context "has_supplied_products_on_hand?" do
|
||||
before :each do
|
||||
@supplier = create(:supplier_enterprise)
|
||||
end
|
||||
|
||||
it "returns false when no products" do
|
||||
@supplier.should_not have_supplied_products_on_hand
|
||||
end
|
||||
|
||||
it "returns false when the product is out of stock" do
|
||||
create(:product, :supplier => @supplier, :on_hand => 0)
|
||||
@supplier.should_not have_supplied_products_on_hand
|
||||
end
|
||||
|
||||
it "returns true when the product is in stock" do
|
||||
create(:product, :supplier => @supplier, :on_hand => 1)
|
||||
@supplier.should have_supplied_products_on_hand
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,7 +15,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "reveals permission for changing distributor" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
subject.distributor = d
|
||||
@@ -27,7 +27,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "raises an exception if distributor is changed without permission" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
subject.distributor = d
|
||||
subject.save!
|
||||
@@ -41,8 +41,8 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "reveals permission for adding products to the cart" do
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
|
||||
p_first = create(:product, :distributors => [d1])
|
||||
p_subsequent_same_dist = create(:product, :distributors => [d1])
|
||||
@@ -67,7 +67,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "sets attributes on line items for variants" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
subject.distributor = d
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user