mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-13 18:46:49 +00:00
Compare commits
38 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 | ||
|
|
b9a072b61a | ||
|
|
1d1c27701d | ||
|
|
077098e6c1 | ||
|
|
04d8648c6d | ||
|
|
4c2debba7e | ||
|
|
abe3feb996 | ||
|
|
c700d9e71b | ||
|
|
ff24149195 |
@@ -145,7 +145,7 @@ GEM
|
||||
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)
|
||||
|
||||
@@ -128,8 +128,8 @@ ul.product-listing {
|
||||
}
|
||||
|
||||
|
||||
/* Supplier and distributor description */
|
||||
.supplier-description, .distributor-description {
|
||||
/* Enterprise description */
|
||||
.enterprise-description {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
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 main_app.admin_distributors_path, :notice => 'Distributor collection times updated.'
|
||||
else
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_distributor_set
|
||||
@distributor_set = DistributorSet.new :distributors => collection
|
||||
end
|
||||
|
||||
def load_countries
|
||||
@countries = Spree::Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
@@ -1,16 +0,0 @@
|
||||
module Admin
|
||||
class SuppliersController < ResourceController
|
||||
before_filter :load_data, :except => [:index]
|
||||
|
||||
helper 'spree/products'
|
||||
|
||||
private
|
||||
def load_data
|
||||
@countries = Spree::Country.order(:name)
|
||||
end
|
||||
|
||||
def collection
|
||||
super.order(:name)
|
||||
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 = Supplier.all
|
||||
@distributors = 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
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
class DistributorsController < BaseController
|
||||
class EnterprisesController < BaseController
|
||||
def index
|
||||
@distributors = Distributor.all
|
||||
@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 => 'distributors/details', :locals => {:distributor => d})] }]
|
||||
@distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'enterprises/distributor_details', :locals => {:distributor => d})] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options = {:enterprise_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@distributor = Distributor.find params[:id]
|
||||
@enterprise = Enterprise.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
def select_distributor
|
||||
distributor = Enterprise.is_distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
@@ -32,7 +40,7 @@ class DistributorsController < BaseController
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect
|
||||
def deselect_distributor
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
@@ -14,16 +14,16 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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
|
||||
@@ -43,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 = Distributor.all
|
||||
@distributors = Enterprise.is_distributor
|
||||
|
||||
@report = OpenFoodWeb::GroupBuyReport.new orders
|
||||
unless params[:csv]
|
||||
@@ -74,36 +74,38 @@ Spree::Admin::ReportsController.class_eval do
|
||||
def bulk_coop
|
||||
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
|
||||
line_items = orders.map { |o| o.line_items }.flatten
|
||||
|
||||
@distributors = Distributor.all
|
||||
@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"]
|
||||
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| "UNIT SIZE" },
|
||||
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| 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 } },
|
||||
@@ -111,32 +113,45 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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| "UNIT SIZE" },
|
||||
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.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"]
|
||||
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| "UNIT SIZE" },
|
||||
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| 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 } },
|
||||
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.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
|
||||
when "bulk_coop_packing_sheets"
|
||||
|
||||
@@ -151,42 +166,52 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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.user },
|
||||
sort_by: proc { |user| user.to_s } } ]
|
||||
{ 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.created_at.to_s },
|
||||
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.user },
|
||||
sort_by: proc { |user| user.to_s } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.created_at } } ]
|
||||
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"]
|
||||
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| "UNIT SIZE" },
|
||||
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| 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 } },
|
||||
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
|
||||
@@ -201,22 +226,22 @@ Spree::Admin::ReportsController.class_eval do
|
||||
def payments
|
||||
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
|
||||
payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
|
||||
@distributors = Distributor.all
|
||||
@distributors = Enterprise.is_distributor
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
@@ -305,23 +330,23 @@ Spree::Admin::ReportsController.class_eval do
|
||||
def order_cycles
|
||||
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
|
||||
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 = Distributor.all
|
||||
@distributors = Enterprise.is_distributor
|
||||
@report_type = params[:report_type]
|
||||
|
||||
case params[:report_type]
|
||||
@@ -337,7 +362,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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| "status" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
@@ -404,7 +429,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.variant.price } },
|
||||
proc { |line_items| "total shipping cost" },
|
||||
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 } },
|
||||
@@ -415,11 +440,12 @@ Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
when "order_cycle_customer_totals"
|
||||
table_items = line_items
|
||||
@include_blank = false
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Customer", "Email", "Phone", "Product", "Variant", "Amount", "Total Cost", "Paid?", "Packed?", "Shipped?"]
|
||||
header = ["Distributor", "Customer", "Email", "Phone", "Product", "Variant", "Amount", "Item ($)", "Ship ($)", "Total ($)", "Paid?", "Packed?", "Shipped?"]
|
||||
|
||||
columns = [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
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 },
|
||||
@@ -428,18 +454,25 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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.user },
|
||||
sort_by: proc { |user| user.to_s },
|
||||
summary_columns: [ proc { |line_items| line_items.first.order.bill_address.firstname + " " + line_items.first.order.bill_address.lastname },
|
||||
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| "work out whether paid or not" },
|
||||
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 },
|
||||
@@ -449,6 +482,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
|
||||
else
|
||||
table_items = line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Supplier", "Product", "Variant", "Amount", "Cost per Unit", "Total Cost", "Status", "Incoming Transport"]
|
||||
|
||||
@@ -458,7 +492,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
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| "status" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "incoming transport" } ]
|
||||
|
||||
rules = [ { group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::HomeController.class_eval do
|
||||
include 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? ? 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 DistributorsHelper
|
||||
include EnterprisesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :index => { :html => { :success => lambda {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'open_food_web/split_products_by_distributor'
|
||||
|
||||
Spree::TaxonsController.class_eval do
|
||||
include DistributorsHelper
|
||||
include EnterprisesHelper
|
||||
include OpenFoodWeb::SplitProductsByDistributor
|
||||
|
||||
respond_override :show => { :html => { :success => lambda {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
class SuppliersController < BaseController
|
||||
def index
|
||||
@suppliers = Supplier.all
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@supplier = Supplier.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
module DistributorsHelper
|
||||
module EnterprisesHelper
|
||||
def current_distributor
|
||||
@current_distributor ||= current_order(false).andand.distributor
|
||||
end
|
||||
@@ -1,31 +0,0 @@
|
||||
class Distributor < ActiveRecord::Base
|
||||
belongs_to :pickup_address, :foreign_key => 'pickup_address_id', :class_name => 'Spree::Address'
|
||||
has_many :orders, :class_name => 'Spree::Order'
|
||||
|
||||
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 ||= Spree::Address.new
|
||||
self.pickup_address.country = Spree::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
|
||||
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
|
||||
@@ -1,30 +1,30 @@
|
||||
# Tableless model to handle updating multiple distributors at once from a
|
||||
# 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 DistributorSet
|
||||
class EnterpriseSet
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :distributors
|
||||
attr_accessor :enterprises
|
||||
|
||||
def initialize(attributes={})
|
||||
@distributors = Distributor.all
|
||||
@enterprises = Enterprise.all
|
||||
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def distributors_attributes=(attributes)
|
||||
def enterprises_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))
|
||||
e = @enterprises.detect { |e| e.id.to_s == attributes[:id].to_s }
|
||||
e.assign_attributes(attributes.except(:id))
|
||||
end
|
||||
end
|
||||
|
||||
def save
|
||||
distributors.all?(&:save)
|
||||
enterprises.all?(&:save)
|
||||
end
|
||||
|
||||
def persisted?
|
||||
@@ -1,6 +1,6 @@
|
||||
class ProductDistribution < ActiveRecord::Base
|
||||
belongs_to :product, :class_name => 'Spree::Product'
|
||||
belongs_to :distributor
|
||||
belongs_to :distributor, :class_name => 'Enterprise'
|
||||
belongs_to :shipping_method, :class_name => 'Spree::ShippingMethod'
|
||||
|
||||
validates_presence_of :product_id, :on => :update
|
||||
|
||||
@@ -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,5 +1,5 @@
|
||||
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
|
||||
@@ -12,6 +12,11 @@ Spree::Product.class_eval do
|
||||
|
||||
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
|
||||
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,33 +0,0 @@
|
||||
class Supplier < ActiveRecord::Base
|
||||
has_many :products, :class_name => 'Spree::Product'
|
||||
belongs_to :address, :class_name => 'Spree::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 has_products_on_hand?
|
||||
self.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
|
||||
@@ -5,5 +5,5 @@ Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_after => "[data-hook='product_show']",
|
||||
:text => "<%= javascript_include_tag main_app.distributors_path(:format => :js) %>",
|
||||
:text => "<%= javascript_include_tag main_app.distributors_enterprises_path(:format => :js) %>",
|
||||
:name => "product_distributor_details_js")
|
||||
|
||||
@@ -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 => main_app.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 => main_app.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) %>")
|
||||
@@ -1,40 +0,0 @@
|
||||
<div class="toolbar" data-hook="toolbar">
|
||||
<ul class="actions">
|
||||
<li>
|
||||
<%= button_link_to "New Distributor", main_app.new_admin_distributor_path, :icon => 'add', :id => 'admin_new_distributor_link' %>
|
||||
</li>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
<%= form_for @distributor_set, :url => main_app.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, main_app.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, main_app.edit_admin_distributor_path(@distributor), :class => 'edit_distributor'
|
||||
= t(:or)
|
||||
= link_to t(:back), main_app.admin_distributors_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 [main_app, :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
|
||||
@@ -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", main_app.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, main_app.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,5 +0,0 @@
|
||||
= render :partial => 'spree/shared/error_messages', :locals => { :target => @supplier }
|
||||
|
||||
= form_for [main_app, :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, main_app.edit_admin_supplier_path(@supplier), :class => 'edit_supplier'
|
||||
= t(:or)
|
||||
= link_to t(:back), main_app.admin_suppliers_path
|
||||
@@ -1,7 +0,0 @@
|
||||
%h2= @distributor.name
|
||||
|
||||
.distributor-description= @distributor.long_description.andand.html_safe
|
||||
|
||||
%h3 Available Now
|
||||
|
||||
= render :template => 'spree/products/index'
|
||||
@@ -2,7 +2,7 @@
|
||||
%p
|
||||
%strong Address:
|
||||
%br/
|
||||
= render 'spree/shared/address', :address => distributor.pickup_address
|
||||
= render 'spree/shared/address', :address => distributor.address
|
||||
%p
|
||||
%strong Next collection time:
|
||||
%br/
|
||||
@@ -20,4 +20,4 @@
|
||||
%br/
|
||||
= "Email: #{distributor.email}"
|
||||
%p= distributor.description
|
||||
%p= link_to distributor.url, distributor.url if distributor.url
|
||||
%p= link_to distributor.website, distributor.website if distributor.website
|
||||
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'
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
%h1 Suppliers
|
||||
|
||||
= cms_page_content(:content, Cms::Page.find_by_full_path('/suppliers'))
|
||||
= cms_page_content(:content, Cms::Page.find_by_full_path('/enterprises/suppliers'))
|
||||
|
||||
%ul.suppliers
|
||||
%ul.enterprises
|
||||
- @suppliers.each do |supplier|
|
||||
%li= link_to supplier.name, supplier
|
||||
@@ -1,5 +1,5 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%br
|
||||
= f.collection_select(:supplier_id, Supplier.all, :id, :name, :include_blank => true)
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer, :id, :name, :include_blank => true)
|
||||
= f.error_message_on :supplier
|
||||
|
||||
@@ -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
|
||||
@@ -36,4 +36,4 @@
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
%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
|
||||
|
||||
@@ -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
|
||||
@@ -36,4 +36,4 @@
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
%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
|
||||
|
||||
@@ -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
|
||||
@@ -36,4 +36,4 @@
|
||||
%td= column
|
||||
- if @table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.columns.omega.six
|
||||
%fieldset#shipping
|
||||
%legend Distributor
|
||||
= render 'distributors/details', :distributor => @order.distributor
|
||||
= render 'enterprises/distributor_details', :distributor => @order.distributor
|
||||
|
||||
@@ -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([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)
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
.distributor-details
|
||||
- order = current_order(false)
|
||||
- if order.andand.distributor.present?
|
||||
= render 'distributors/details', :distributor => order.distributor
|
||||
= 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,9 +2,9 @@
|
||||
%h6.filter_name Shop by Supplier
|
||||
%ul.filter_choices
|
||||
- @suppliers.each do |supplier|
|
||||
- if supplier.has_products_on_hand?
|
||||
- if supplier.has_supplied_products_on_hand?
|
||||
%li.nowrap= link_to supplier.name, [main_app, supplier]
|
||||
= button_to 'Browse All Suppliers', main_app.suppliers_path, :method => :get
|
||||
= button_to 'Browse All Suppliers', main_app.suppliers_enterprises_path, :method => :get
|
||||
|
||||
%h6.filter_name Shop by Distributor
|
||||
%ul.filter_choices
|
||||
@@ -12,10 +12,10 @@
|
||||
- @distributors.each do |distributor|
|
||||
%li.nowrap
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
= link_to distributor.name, main_app.select_distributor_path(distributor)
|
||||
= link_to distributor.name, main_app.select_distributor_enterprise_path(distributor)
|
||||
- elsif order.distributor == 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', main_app.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'
|
||||
@@ -1,17 +1,17 @@
|
||||
Openfoodweb::Application.routes.draw do
|
||||
root :to => 'spree/home#index'
|
||||
|
||||
resources :suppliers
|
||||
resources :distributors do
|
||||
get :select, :on => :member
|
||||
get :deselect, :on => :collection
|
||||
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 :distributors do
|
||||
resources :enterprises do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
resources :suppliers
|
||||
end
|
||||
|
||||
# Mount Spree's routes
|
||||
|
||||
@@ -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
|
||||
183
db/schema.rb
183
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121018002907) 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 => 20121018002907) 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", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
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|
|
||||
@@ -183,8 +186,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "alternative_phone"
|
||||
t.integer "state_id"
|
||||
t.integer "country_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "company"
|
||||
end
|
||||
|
||||
@@ -193,12 +196,12 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
|
||||
create_table "spree_adjustments", :force => true do |t|
|
||||
t.integer "source_id"
|
||||
t.decimal "amount", :precision => 8, :scale => 2
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0
|
||||
t.string "label"
|
||||
t.string "source_type"
|
||||
t.integer "adjustable_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "mandatory"
|
||||
t.boolean "locked"
|
||||
t.integer "originator_id"
|
||||
@@ -230,15 +233,15 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "type"
|
||||
t.integer "calculable_id", :null => false
|
||||
t.string "calculable_type", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_configurations", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "type", :limit => 50
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "spree_configurations", ["name", "type"], :name => "index_configurations_on_name_and_type"
|
||||
@@ -276,8 +279,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "environment", :default => "development"
|
||||
t.string "server", :default => "test"
|
||||
t.boolean "test_mode", :default => true
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_inventory_units", :force => true do |t|
|
||||
@@ -285,8 +288,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "state"
|
||||
t.integer "variant_id"
|
||||
t.integer "order_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "shipment_id"
|
||||
t.integer "return_authorization_id"
|
||||
end
|
||||
@@ -300,8 +303,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "variant_id"
|
||||
t.integer "quantity", :null => false
|
||||
t.decimal "price", :precision => 8, :scale => 2, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "max_quantity"
|
||||
t.integer "shipping_method_id"
|
||||
end
|
||||
@@ -313,22 +316,22 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "source_id"
|
||||
t.string "source_type"
|
||||
t.text "details"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_mail_methods", :force => true do |t|
|
||||
t.string "environment"
|
||||
t.boolean "active", :default => true
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_option_types", :force => true do |t|
|
||||
t.string "name", :limit => 100
|
||||
t.string "presentation", :limit => 100
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "position", :default => 0, :null => false
|
||||
end
|
||||
|
||||
@@ -342,8 +345,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "name"
|
||||
t.string "presentation"
|
||||
t.integer "option_type_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_option_values_variants", :id => false, :force => true do |t|
|
||||
@@ -362,8 +365,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.decimal "adjustment_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.decimal "credit_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "completed_at"
|
||||
t.integer "bill_address_id"
|
||||
t.integer "ship_address_id"
|
||||
@@ -384,8 +387,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.text "description"
|
||||
t.boolean "active", :default => true
|
||||
t.string "environment", :default => "development"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "deleted_at"
|
||||
t.string "display_on"
|
||||
end
|
||||
@@ -393,8 +396,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
create_table "spree_payments", :force => true do |t|
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "order_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "source_id"
|
||||
t.string "source_type"
|
||||
t.integer "payment_method_id"
|
||||
@@ -423,8 +426,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.text "value"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "key"
|
||||
t.string "value_type"
|
||||
end
|
||||
@@ -449,16 +452,16 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "position"
|
||||
t.integer "product_id"
|
||||
t.integer "option_type_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_product_properties", :force => true do |t|
|
||||
t.string "value"
|
||||
t.integer "product_id"
|
||||
t.integer "property_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "spree_product_properties", ["product_id"], :name => "index_product_properties_on_product_id"
|
||||
@@ -482,12 +485,12 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "meta_keywords"
|
||||
t.integer "tax_category_id"
|
||||
t.integer "shipping_category_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.integer "supplier_id"
|
||||
t.boolean "group_buy"
|
||||
t.string "group_buy_unit_size"
|
||||
t.float "group_buy_unit_size"
|
||||
end
|
||||
|
||||
add_index "spree_products", ["available_on"], :name => "index_products_on_available_on"
|
||||
@@ -528,8 +531,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "user_id"
|
||||
t.integer "product_group_id"
|
||||
t.string "type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "spree_promotion_rules", ["product_group_id"], :name => "index_promotion_rules_on_product_group_id"
|
||||
@@ -546,8 +549,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
create_table "spree_properties", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "presentation", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_properties_prototypes", :id => false, :force => true do |t|
|
||||
@@ -557,8 +560,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
|
||||
create_table "spree_prototypes", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_return_authorizations", :force => true do |t|
|
||||
@@ -567,8 +570,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
|
||||
t.integer "order_id"
|
||||
t.text "reason"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_roles", :force => true do |t|
|
||||
@@ -591,8 +594,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "order_id"
|
||||
t.integer "shipping_method_id"
|
||||
t.integer "address_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "state"
|
||||
end
|
||||
|
||||
@@ -600,15 +603,15 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
|
||||
create_table "spree_shipping_categories", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_shipping_methods", :force => true do |t|
|
||||
t.string "name"
|
||||
t.integer "zone_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "display_on"
|
||||
t.integer "shipping_category_id"
|
||||
t.boolean "match_none"
|
||||
@@ -624,8 +627,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "transaction_id"
|
||||
t.integer "customer_id"
|
||||
t.string "payment_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_state_changes", :force => true do |t|
|
||||
@@ -633,8 +636,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "previous_state"
|
||||
t.integer "stateful_id"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "stateful_type"
|
||||
t.string "next_state"
|
||||
end
|
||||
@@ -648,8 +651,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
create_table "spree_tax_categories", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "is_default", :default => false
|
||||
t.datetime "deleted_at"
|
||||
end
|
||||
@@ -658,15 +661,15 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.decimal "amount", :precision => 8, :scale => 5
|
||||
t.integer "zone_id"
|
||||
t.integer "tax_category_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "included_in_price", :default => false
|
||||
end
|
||||
|
||||
create_table "spree_taxonomies", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_taxons", :force => true do |t|
|
||||
@@ -675,8 +678,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "name", :null => false
|
||||
t.string "permalink"
|
||||
t.integer "taxonomy_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "lft"
|
||||
t.integer "rgt"
|
||||
t.string "icon_file_name"
|
||||
@@ -694,8 +697,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "permissable_id"
|
||||
t.string "permissable_type"
|
||||
t.string "token"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "spree_tokenized_permissions", ["permissable_id", "permissable_type"], :name => "index_tokenized_name_and_type"
|
||||
@@ -704,8 +707,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "environment"
|
||||
t.string "analytics_id"
|
||||
t.boolean "active", :default => true
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_users", :force => true do |t|
|
||||
@@ -726,8 +729,8 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.string "login"
|
||||
t.integer "ship_address_id"
|
||||
t.integer "bill_address_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "authentication_token"
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
@@ -750,7 +753,7 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.boolean "is_master", :default => false
|
||||
t.integer "product_id"
|
||||
t.integer "count_on_hand", :default => 0, :null => false
|
||||
t.decimal "cost_price", :precision => 8, :scale => 2
|
||||
t.decimal "cost_price", :precision => 8, :scale => 2, :default => 0.0
|
||||
t.integer "position"
|
||||
end
|
||||
|
||||
@@ -760,29 +763,17 @@ ActiveRecord::Schema.define(:version => 20121018002907) do
|
||||
t.integer "zoneable_id"
|
||||
t.string "zoneable_type"
|
||||
t.integer "zone_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "spree_zones", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "default_tax", :default => false
|
||||
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", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
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 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 => Supplier.all[0],
|
||||
:distributors => [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 => Supplier.all[1],
|
||||
:distributors => 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 => Supplier.all[2],
|
||||
:distributors => [Distributor.all[2]],
|
||||
:supplier => Enterprise.is_primary_producer[2],
|
||||
:distributors => [Enterprise.is_distributor[2]],
|
||||
:taxons => [Spree::Taxon.find_by_name('Meat and Fish')])
|
||||
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
|
||||
|
||||
@@ -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 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 = Distributor.all.map(&:name).compact.uniq
|
||||
conds = Hash[*distributors.map { |d| [d, "#{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 DistributorsController do
|
||||
describe EnterprisesController do
|
||||
include Spree::Core::CurrentOrder
|
||||
|
||||
before :each do
|
||||
@@ -11,11 +11,19 @@ describe 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 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 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 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 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 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 => 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 => 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 :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| Distributor.first || FactoryGirl.create(:distributor) }
|
||||
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 { 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,7 +35,7 @@ module OpenFoodWeb
|
||||
order2.line_items << line_item22
|
||||
@orders << order2
|
||||
|
||||
@supplier2 = create(:supplier)
|
||||
@supplier2 = create(:supplier_enterprise)
|
||||
@variant3 = create(:variant, :weight => nil)
|
||||
@variant3.product.supplier = @supplier2
|
||||
@variant3.product.save!
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 == 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
|
||||
|
||||
@@ -6,7 +6,7 @@ describe ProductDistribution do
|
||||
pd1.should be_valid
|
||||
|
||||
new_product = create(:product)
|
||||
new_distributor = create(:distributor)
|
||||
new_distributor = create(:distributor_enterprise)
|
||||
|
||||
pd2 = build(:product_distribution, :product => pd1.product, :distributor => pd1.distributor)
|
||||
pd2.should_not be_valid
|
||||
|
||||
@@ -19,17 +19,60 @@ describe Spree::Product do
|
||||
end
|
||||
end
|
||||
|
||||
context "finders" do
|
||||
describe "scopes" do
|
||||
describe "in_supplier_or_distributor" do
|
||||
it "finds supplied products" do
|
||||
s0 = create(:supplier_enterprise)
|
||||
s1 = create(:supplier_enterprise)
|
||||
p0 = create(:product, :supplier => s0)
|
||||
p1 = create(:product, :supplier => s1)
|
||||
|
||||
Spree::Product.in_supplier_or_distributor(s1).should == [p1]
|
||||
end
|
||||
|
||||
it "finds distributed products" do
|
||||
d0 = create(:distributor_enterprise)
|
||||
d1 = create(:distributor_enterprise)
|
||||
p0 = create(:product, :distributors => [d0])
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
|
||||
Spree::Product.in_supplier_or_distributor(d1).should == [p1]
|
||||
end
|
||||
|
||||
it "finds products supplied and distributed by the same enterprise" do
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :supplier => s, :distributors => [d])
|
||||
|
||||
Spree::Product.in_supplier_or_distributor(s).should == [p]
|
||||
Spree::Product.in_supplier_or_distributor(d).should == [p]
|
||||
end
|
||||
|
||||
it "shows each product once when it is distributed by many distributors" do
|
||||
s = create(:supplier_enterprise)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
p = create(:product, :supplier => s, :distributors => [d1, d2, d3])
|
||||
|
||||
[s, d1, d2, d3].each do |enterprise|
|
||||
Spree::Product.in_supplier_or_distributor(enterprise).should == [p]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finders" do
|
||||
it "finds the shipping method for a particular distributor" do
|
||||
shipping_method = create(:shipping_method)
|
||||
distributor = create(:distributor)
|
||||
distributor = create(:distributor_enterprise)
|
||||
product = create(:product)
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => distributor, :shipping_method => shipping_method)
|
||||
product.shipping_method_for_distributor(distributor).should == shipping_method
|
||||
end
|
||||
|
||||
it "raises an error if distributor is not found" do
|
||||
distributor = create(:distributor)
|
||||
distributor = create(:distributor_enterprise)
|
||||
product = create(:product)
|
||||
expect do
|
||||
product.shipping_method_for_distributor(distributor)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Supplier do
|
||||
|
||||
describe "associations" do
|
||||
it { should have_many(:products) }
|
||||
it { should belong_to(:address) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { should validate_presence_of(:name) }
|
||||
end
|
||||
|
||||
it "should default country to system country" do
|
||||
subject.address.country.should == Country.find_by_id(Config[:default_country_id])
|
||||
end
|
||||
|
||||
context "has_products_on_hand?" do
|
||||
before :each do
|
||||
@supplier = create(:supplier)
|
||||
end
|
||||
|
||||
it "returns false when no products" do
|
||||
@supplier.should_not have_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_products_on_hand
|
||||
end
|
||||
|
||||
it "returns true when the product is in stock" do
|
||||
create(:product, :supplier => @supplier, :on_hand => 1)
|
||||
@supplier.should have_products_on_hand
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,80 +0,0 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administration
|
||||
I want manage the distributors of products
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "listing distributors" do
|
||||
d = create(:distributor)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Distributors'
|
||||
|
||||
page.should have_content d.name
|
||||
end
|
||||
|
||||
scenario "viewing a distributor" do
|
||||
d = create(:distributor)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Distributors'
|
||||
click_link d.name
|
||||
|
||||
page.should have_content d.name
|
||||
end
|
||||
|
||||
scenario "creating a new distributor" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Distributors'
|
||||
click_link 'New Distributor'
|
||||
|
||||
fill_in 'distributor_name', :with => 'Eaterprises'
|
||||
fill_in 'distributor_description', :with => 'Connecting farmers and eaters'
|
||||
fill_in 'distributor_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
fill_in 'distributor_contact', :with => 'Kirsten or Ren'
|
||||
fill_in 'distributor_phone', :with => '0413 897 321'
|
||||
|
||||
fill_in 'distributor_pickup_address_attributes_address1', :with => '35 Ballantyne St'
|
||||
fill_in 'distributor_pickup_address_attributes_city', :with => 'Thornbury'
|
||||
fill_in 'distributor_pickup_address_attributes_zipcode', :with => '3072'
|
||||
select('Australia', :from => 'distributor_pickup_address_attributes_country_id')
|
||||
select('Victoria', :from => 'distributor_pickup_address_attributes_state_id')
|
||||
|
||||
fill_in 'distributor_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
|
||||
fill_in 'distributor_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
|
||||
fill_in 'distributor_email', :with => 'info@eaterprises.com.au'
|
||||
fill_in 'distributor_url', :with => 'http://eaterprises.com.au'
|
||||
fill_in 'distributor_abn', :with => '09812309823'
|
||||
fill_in 'distributor_acn', :with => ''
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Distributor "Eaterprises" has been successfully created!'
|
||||
end
|
||||
|
||||
|
||||
scenario "updating many distributor next collection times at once" do
|
||||
# Given three distributors
|
||||
3.times { create(:distributor) }
|
||||
|
||||
# When I go to the distributors page
|
||||
login_to_admin_section
|
||||
click_link 'Distributors'
|
||||
|
||||
# And I fill in some new collection times and save them
|
||||
fill_in 'distributor_set_distributors_attributes_0_next_collection_at', :with => 'One'
|
||||
fill_in 'distributor_set_distributors_attributes_1_next_collection_at', :with => 'Two'
|
||||
fill_in 'distributor_set_distributors_attributes_2_next_collection_at', :with => 'Three'
|
||||
click_button 'Update'
|
||||
|
||||
# Then my times should have been saved
|
||||
flash_message.should == 'Distributor collection times updated.'
|
||||
Distributor.all.map { |d| d.next_collection_at }.should == %w(One Two Three)
|
||||
end
|
||||
|
||||
end
|
||||
122
spec/requests/admin/enterprises_spec.rb
Normal file
122
spec/requests/admin/enterprises_spec.rb
Normal file
@@ -0,0 +1,122 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want manage enterprises
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "listing enterprises" do
|
||||
e = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
|
||||
page.should have_content e.name
|
||||
end
|
||||
|
||||
scenario "viewing an enterprise" do
|
||||
e = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
click_link e.name
|
||||
|
||||
page.should have_content e.name
|
||||
end
|
||||
|
||||
scenario "creating a new enterprise" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Enterprises'
|
||||
click_link 'New Enterprise'
|
||||
|
||||
fill_in 'enterprise_name', :with => 'Eaterprises'
|
||||
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
|
||||
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
|
||||
uncheck 'enterprise_is_primary_producer'
|
||||
check 'enterprise_is_distributor'
|
||||
|
||||
fill_in 'enterprise_contact', :with => 'Kirsten or Ren'
|
||||
fill_in 'enterprise_phone', :with => '0413 897 321'
|
||||
fill_in 'enterprise_email', :with => 'info@eaterprises.com.au'
|
||||
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
|
||||
fill_in 'enterprise_twitter', :with => '@eaterprises'
|
||||
fill_in 'enterprise_abn', :with => '09812309823'
|
||||
fill_in 'enterprise_acn', :with => ''
|
||||
|
||||
fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
|
||||
fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
|
||||
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
|
||||
select('Australia', :from => 'enterprise_address_attributes_country_id')
|
||||
select('Victoria', :from => 'enterprise_address_attributes_state_id')
|
||||
|
||||
fill_in 'enterprise_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
|
||||
fill_in 'enterprise_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Enterprise "Eaterprises" has been successfully created!'
|
||||
end
|
||||
|
||||
scenario "editing an existing enterprise" do
|
||||
@enterprise = create(:enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Enterprises'
|
||||
click_link 'Edit'
|
||||
|
||||
fill_in 'enterprise_name', :with => 'Eaterprises'
|
||||
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
|
||||
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
|
||||
uncheck 'enterprise_is_primary_producer'
|
||||
check 'enterprise_is_distributor'
|
||||
|
||||
fill_in 'enterprise_contact', :with => 'Kirsten or Ren'
|
||||
fill_in 'enterprise_phone', :with => '0413 897 321'
|
||||
fill_in 'enterprise_email', :with => 'info@eaterprises.com.au'
|
||||
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
|
||||
fill_in 'enterprise_twitter', :with => '@eaterprises'
|
||||
fill_in 'enterprise_abn', :with => '09812309823'
|
||||
fill_in 'enterprise_acn', :with => ''
|
||||
|
||||
fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
|
||||
fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
|
||||
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
|
||||
select('Australia', :from => 'enterprise_address_attributes_country_id')
|
||||
select('Victoria', :from => 'enterprise_address_attributes_state_id')
|
||||
|
||||
fill_in 'enterprise_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM'
|
||||
fill_in 'enterprise_next_collection_at', :with => 'Thursday, 22nd Feb, 6 - 9 PM'
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
|
||||
end
|
||||
|
||||
|
||||
scenario "updating many distributor next collection times at once" do
|
||||
# Given three distributors
|
||||
3.times { create(:distributor_enterprise) }
|
||||
|
||||
# When I go to the enterprises page
|
||||
login_to_admin_section
|
||||
click_link 'Enterprises'
|
||||
|
||||
# And I fill in some new collection times and save them
|
||||
fill_in 'enterprise_set_enterprises_attributes_0_next_collection_at', :with => 'One'
|
||||
fill_in 'enterprise_set_enterprises_attributes_1_next_collection_at', :with => 'Two'
|
||||
fill_in 'enterprise_set_enterprises_attributes_2_next_collection_at', :with => 'Three'
|
||||
click_button 'Update'
|
||||
|
||||
# Then my times should have been saved
|
||||
flash_message.should == 'Distributor collection times updated.'
|
||||
Enterprise.is_distributor.map { |d| d.next_collection_at }.should == %w(One Two Three)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -8,8 +8,8 @@ feature %q{
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@supplier = create(:supplier, :name => 'New supplier')
|
||||
@distributors = (1..3).map { create(:distributor) }
|
||||
@supplier = create(:supplier_enterprise, :name => 'New supplier')
|
||||
@distributors = (1..3).map { create(:distributor_enterprise) }
|
||||
@shipping_method = create(:shipping_method, :name => 'My shipping method')
|
||||
end
|
||||
|
||||
@@ -49,14 +49,14 @@ feature %q{
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
select 'New supplier', :from => 'product_supplier_id'
|
||||
choose 'product_group_buy_1'
|
||||
fill_in 'Group buy unit size', :with => '10 kg'
|
||||
fill_in 'Group buy unit size', :with => '10'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.group_buy.should be_true
|
||||
product.group_buy_unit_size.should == '10 kg'
|
||||
product.group_buy_unit_size.should == 10.0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
51
spec/requests/admin/reports_spec.rb
Normal file
51
spec/requests/admin/reports_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want numbers, all the numbers!
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
|
||||
scenario "orders and distributors report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Orders And Distributors'
|
||||
|
||||
page.should have_content 'Order date'
|
||||
end
|
||||
|
||||
scenario "group buys report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Group Buys'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "bulk co-op report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Bulk Co-Op'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "payments reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Payment Reports'
|
||||
|
||||
page.should have_content 'Payment State'
|
||||
end
|
||||
|
||||
scenario "order cycle reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Order Cycle Reports'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
end
|
||||
@@ -27,7 +27,7 @@ feature 'shipping methods' do
|
||||
|
||||
scenario "deleting a shipping method referenced by a product distribution" do
|
||||
p = create(:product)
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
create(:product_distribution, product: p, distributor: d, shipping_method: @sm)
|
||||
|
||||
visit_delete spree.admin_shipping_method_path(@sm)
|
||||
@@ -38,7 +38,7 @@ feature 'shipping methods' do
|
||||
|
||||
scenario "deleting a shipping method referenced by a line item" do
|
||||
sm2 = create(:shipping_method)
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
p = create(:product)
|
||||
create(:product_distribution, product: p, distributor: d, shipping_method: sm2)
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature %q{
|
||||
As an administration
|
||||
I want manage the suppliers of products
|
||||
} do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
end
|
||||
|
||||
scenario "listing suppliers" do
|
||||
s = create(:supplier)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Suppliers'
|
||||
|
||||
page.should have_content s.name
|
||||
end
|
||||
|
||||
scenario "viewing a supplier" do
|
||||
s = create(:supplier)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Suppliers'
|
||||
click_link s.name
|
||||
|
||||
page.should have_content s.name
|
||||
end
|
||||
|
||||
scenario "creating a new supplier" do
|
||||
login_to_admin_section
|
||||
|
||||
click_link 'Suppliers'
|
||||
click_link 'New Supplier'
|
||||
|
||||
fill_in 'supplier_name', :with => 'David Arnold'
|
||||
fill_in 'supplier_description', :with => 'A farmer with a difference'
|
||||
fill_in 'supplier_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'
|
||||
|
||||
fill_in 'supplier_address_attributes_address1', :with => '35 Byron Ave'
|
||||
fill_in 'supplier_address_attributes_city', :with => 'Ararat'
|
||||
fill_in 'supplier_address_attributes_zipcode', :with => '1112'
|
||||
select('Australia', :from => 'supplier_address_attributes_country_id')
|
||||
select('Victoria', :from => 'supplier_address_attributes_state_id')
|
||||
|
||||
fill_in 'supplier_email', :with => 'david@here.com'
|
||||
fill_in 'supplier_website', :with => 'http://somewhere.com'
|
||||
fill_in 'supplier_twitter', :with => 'davida'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Supplier "David Arnold" has been successfully created!'
|
||||
end
|
||||
end
|
||||
@@ -10,8 +10,8 @@ feature %q{
|
||||
|
||||
scenario "adding a product to the cart with no distributor chosen" do
|
||||
# Given a product and some distributors
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1])
|
||||
create(:product, :distributors => [d2])
|
||||
|
||||
@@ -30,8 +30,8 @@ feature %q{
|
||||
create(:itemwise_shipping_method)
|
||||
|
||||
# Given a product, some distributors and a defined shipping cost
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
create(:product, :distributors => [d2])
|
||||
p = create(:product, :price => 12.34)
|
||||
create(:product_distribution, :product => p, :distributor => d1, :shipping_method => create(:shipping_method))
|
||||
@@ -67,8 +67,8 @@ feature %q{
|
||||
|
||||
it "does not allow the user to change distributor after a product has been added to the cart" do
|
||||
# Given a product and some distributors
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1])
|
||||
|
||||
# When I add a product to my cart (which sets my distributor)
|
||||
@@ -87,7 +87,7 @@ feature %q{
|
||||
context "adding a subsequent product to the cart" do
|
||||
it "does not allow the user to choose a distributor" do
|
||||
# Given a product under a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
# And a product in my cart
|
||||
@@ -103,8 +103,8 @@ feature %q{
|
||||
|
||||
it "does not allow the user to add a product from another distributor" do
|
||||
# Given two products, each at a different distributor
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
@@ -123,7 +123,7 @@ feature %q{
|
||||
|
||||
it "adds products with valid distributors" do
|
||||
# Given two products, each at the same distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d])
|
||||
p2 = create(:product, :distributors => [d])
|
||||
|
||||
@@ -146,7 +146,7 @@ feature %q{
|
||||
context "group buys" do
|
||||
scenario "adding a product to the cart for a group buy" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
|
||||
# When I add the item to my cart
|
||||
@@ -166,7 +166,7 @@ feature %q{
|
||||
|
||||
scenario "adding a product with variants to the cart for a group buy" do
|
||||
# Given a group buy product with variants and a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
create(:variant, :product => p)
|
||||
|
||||
@@ -187,7 +187,7 @@ feature %q{
|
||||
|
||||
scenario "adding a product to cart that is not a group buy does not show max quantity field" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => false)
|
||||
|
||||
# When I view the add to cart form, there should not be a max quantity field
|
||||
@@ -198,7 +198,7 @@ feature %q{
|
||||
|
||||
scenario "adding a product with a max quantity less than quantity results in max_quantity==quantity" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
|
||||
# When I add the item to my cart
|
||||
|
||||
@@ -9,13 +9,13 @@ feature %q{
|
||||
include WebHelper
|
||||
|
||||
background do
|
||||
@distributor = create(:distributor, :name => 'Edible garden',
|
||||
:pickup_address => create(:address,
|
||||
:address1 => '12 Bungee Rd',
|
||||
:city => 'Carion',
|
||||
:zipcode => 3056,
|
||||
:state => Spree::State.find_by_name('Victoria'),
|
||||
:country => Spree::Country.find_by_name('Australia')),
|
||||
@distributor = create(:distributor_enterprise, :name => 'Edible garden',
|
||||
:address => create(:address,
|
||||
:address1 => '12 Bungee Rd',
|
||||
:city => 'Carion',
|
||||
:zipcode => 3056,
|
||||
:state => Spree::State.find_by_name('Victoria'),
|
||||
:country => Spree::Country.find_by_name('Australia')),
|
||||
:pickup_times => 'Tuesday, 4 PM')
|
||||
|
||||
@shipping_method_1 = create(:shipping_method, :name => 'Shipping Method One')
|
||||
@@ -94,18 +94,18 @@ feature %q{
|
||||
# Distributor details should be displayed
|
||||
within('fieldset#shipping') do
|
||||
[@distributor.name,
|
||||
@distributor.pickup_address.address1,
|
||||
@distributor.pickup_address.city,
|
||||
@distributor.pickup_address.zipcode,
|
||||
@distributor.pickup_address.state_text,
|
||||
@distributor.pickup_address.country.name,
|
||||
@distributor.address.address1,
|
||||
@distributor.address.city,
|
||||
@distributor.address.zipcode,
|
||||
@distributor.address.state_text,
|
||||
@distributor.address.country.name,
|
||||
@distributor.pickup_times,
|
||||
@distributor.next_collection_at,
|
||||
@distributor.contact,
|
||||
@distributor.phone,
|
||||
@distributor.email,
|
||||
@distributor.description,
|
||||
@distributor.url].each do |value|
|
||||
@distributor.website].each do |value|
|
||||
|
||||
page.should have_content value
|
||||
end
|
||||
|
||||
@@ -31,7 +31,6 @@ feature %q{
|
||||
page.should_not have_content 'Home page content'
|
||||
end
|
||||
|
||||
|
||||
scenario "viewing the menu of CMS pages" do
|
||||
# Given some CMS pages
|
||||
home_page = create(:cms_page, content: 'Home')
|
||||
@@ -48,4 +47,19 @@ feature %q{
|
||||
page.should have_selector 'ul#main-nav-bar li', :text => 'Three'
|
||||
end
|
||||
|
||||
scenario "viewing a page from the CMS menu" do
|
||||
# Given some CMS pages
|
||||
home_page = create(:cms_page, content: 'Home')
|
||||
create(:cms_page, parent: home_page, label: 'One')
|
||||
create(:cms_page, parent: home_page, label: 'Two', content: 'This is the page')
|
||||
create(:cms_page, parent: home_page, label: 'Three')
|
||||
|
||||
# When I go to one of the pages
|
||||
visit spree.root_path
|
||||
click_link 'Two'
|
||||
|
||||
# Then I should see the page
|
||||
page.should have_content 'This is the page'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -10,9 +10,9 @@ feature %q{
|
||||
|
||||
scenario "viewing a list of distributors" do
|
||||
# Given some distributors
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d3 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
|
||||
# And some of those distributors have a product
|
||||
create(:product, :distributors => [d1, d2])
|
||||
@@ -26,10 +26,31 @@ feature %q{
|
||||
page.should_not have_selector 'a', :text => d3.name
|
||||
end
|
||||
|
||||
scenario "viewing a distributor" do
|
||||
# Given some distributors with products
|
||||
d1 = create(:distributor_enterprise, :long_description => "<p>Hello, world!</p>")
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1])
|
||||
p2 = create(:product, :distributors => [d2])
|
||||
|
||||
# When I go to the first distributor page
|
||||
visit spree.root_path
|
||||
click_link d1.name
|
||||
|
||||
# Then I should see the distributor details
|
||||
page.should have_selector 'h2', :text => d1.name
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
|
||||
# And I should see the first, but not the second product
|
||||
page.should have_content p1.name
|
||||
page.should_not have_content p2.name
|
||||
end
|
||||
|
||||
|
||||
context "when a distributor is selected" do
|
||||
it "displays the distributor's details" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor
|
||||
@@ -40,12 +61,12 @@ feature %q{
|
||||
page.should have_selector 'h2', :text => 'Melb Uni Co-op'
|
||||
|
||||
# And I should see the distributor's long description
|
||||
page.should have_selector 'div.distributor-description', :text => 'Hello, world!'
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
end
|
||||
|
||||
it "displays the distributor's name on the home page" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op', :description => '<p>Hello, world!</p>')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor
|
||||
@@ -63,8 +84,8 @@ feature %q{
|
||||
taxonomy = Spree::Taxonomy.find_by_name('Products') || create(:taxonomy, :name => 'Products')
|
||||
taxonomy_root = taxonomy.root
|
||||
taxon = create(:taxon, :name => 'Taxon one', :parent_id => taxonomy_root.id)
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product, :distributors => [d1], :taxons => [taxon])
|
||||
p2 = create(:product, :distributors => [d2], :taxons => [taxon])
|
||||
|
||||
@@ -90,7 +111,7 @@ feature %q{
|
||||
|
||||
it "allows the user to leave the distributor" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor, :name => 'Melb Uni Co-op')
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op')
|
||||
create(:product, :distributors => [d])
|
||||
|
||||
# When I select the distributor and then leave it
|
||||
@@ -105,7 +126,7 @@ feature %q{
|
||||
context "viewing a product, it provides a choice of distributor when adding to cart" do
|
||||
it "works when no distributor is chosen" do
|
||||
# Given a distributor and a product under it
|
||||
distributor = create(:distributor)
|
||||
distributor = create(:distributor_enterprise)
|
||||
product = create(:product, :distributors => [distributor])
|
||||
|
||||
# When we view the product
|
||||
@@ -118,7 +139,7 @@ feature %q{
|
||||
|
||||
it "displays the local distributor as the default choice when available for the current product" do
|
||||
# Given a distributor and a product under it
|
||||
distributor = create(:distributor)
|
||||
distributor = create(:distributor_enterprise)
|
||||
product = create(:product, :distributors => [distributor])
|
||||
|
||||
# When we select the distributor and view the product
|
||||
@@ -132,8 +153,8 @@ feature %q{
|
||||
|
||||
it "works when viewing a product from a remote distributor" do
|
||||
# Given two distributors and our product under one
|
||||
distributor_product = create(:distributor)
|
||||
distributor_no_product = create(:distributor)
|
||||
distributor_product = create(:distributor_enterprise)
|
||||
distributor_no_product = create(:distributor_enterprise)
|
||||
product = create(:product, :distributors => [distributor_product])
|
||||
create(:product, :distributors => [distributor_no_product])
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ feature %q{
|
||||
|
||||
scenario "viewing a product shows its supplier and distributor" do
|
||||
# Given a product with a supplier and distributor
|
||||
s = create(:supplier)
|
||||
d = create(:distributor)
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :supplier => s, :distributors => [d])
|
||||
|
||||
# When I view the product
|
||||
@@ -33,7 +33,7 @@ feature %q{
|
||||
end
|
||||
|
||||
it "displays distributor details when one is selected" do
|
||||
d = create(:distributor)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
visit spree.root_path
|
||||
@@ -42,18 +42,18 @@ feature %q{
|
||||
|
||||
within '#product-distributor-details' do
|
||||
[d.name,
|
||||
d.pickup_address.address1,
|
||||
d.pickup_address.city,
|
||||
d.pickup_address.zipcode,
|
||||
d.pickup_address.state_text,
|
||||
d.pickup_address.country.name,
|
||||
d.address.address1,
|
||||
d.address.city,
|
||||
d.address.zipcode,
|
||||
d.address.state_text,
|
||||
d.address.country.name,
|
||||
d.pickup_times,
|
||||
d.next_collection_at,
|
||||
d.contact,
|
||||
d.phone,
|
||||
d.email,
|
||||
d.description,
|
||||
d.url].each do |value|
|
||||
d.website].each do |value|
|
||||
|
||||
page.should have_content value
|
||||
end
|
||||
@@ -63,9 +63,9 @@ feature %q{
|
||||
|
||||
context "with Javascript", js: true do
|
||||
it "changes distributor details when the distributor is changed" do
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d3 = create(:distributor)
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1, d2, d3])
|
||||
|
||||
visit spree.product_path p
|
||||
|
||||
@@ -10,9 +10,9 @@ feature %q{
|
||||
|
||||
scenario "viewing a list of suppliers in the sidebar" do
|
||||
# Given some suppliers
|
||||
s1 = create(:supplier)
|
||||
s2 = create(:supplier)
|
||||
s3 = create(:supplier)
|
||||
s1 = create(:supplier_enterprise)
|
||||
s2 = create(:supplier_enterprise)
|
||||
s3 = create(:supplier_enterprise)
|
||||
|
||||
# And some of those suppliers have a product
|
||||
create(:product, :supplier => s1)
|
||||
@@ -29,9 +29,9 @@ feature %q{
|
||||
|
||||
scenario "viewing a list of all suppliers" do
|
||||
# Given some suppliers
|
||||
s1 = create(:supplier)
|
||||
s2 = create(:supplier)
|
||||
s3 = create(:supplier)
|
||||
s1 = create(:supplier_enterprise)
|
||||
s2 = create(:supplier_enterprise)
|
||||
s3 = create(:supplier_enterprise)
|
||||
|
||||
# And some of those suppliers have a product
|
||||
create(:product, :supplier => s1)
|
||||
@@ -49,18 +49,23 @@ feature %q{
|
||||
|
||||
scenario "viewing products provided by a supplier" do
|
||||
# Given a supplier with a product
|
||||
s = create(:supplier, :name => 'Murrnong', :long_description => "<p>Hello, world!</p>")
|
||||
p = create(:product, :supplier => s)
|
||||
s1 = create(:supplier_enterprise, :name => 'Murrnong', :long_description => "<p>Hello, world!</p>")
|
||||
p1 = create(:product, :supplier => s1)
|
||||
|
||||
# When I select the supplier
|
||||
# And a different supplier with another product
|
||||
s2 = create(:supplier_enterprise, :name => 'Red Herring')
|
||||
p2 = create(:product, :supplier => s2)
|
||||
|
||||
# When I select the first supplier
|
||||
visit spree.root_path
|
||||
click_link s.name
|
||||
click_link s1.name
|
||||
|
||||
# Then I should see the supplier details
|
||||
page.should have_selector 'h2', :text => s.name
|
||||
page.should have_selector 'div.supplier-description', :text => 'Hello, world!'
|
||||
page.should have_selector 'h2', :text => s1.name
|
||||
page.should have_selector 'div.enterprise-description', :text => 'Hello, world!'
|
||||
|
||||
# And I should see the product
|
||||
page.should have_content p.name
|
||||
# And I should see the first, but not the second product
|
||||
page.should have_content p1.name
|
||||
page.should_not have_content p2.name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,8 +40,8 @@ feature %q{
|
||||
taxon_two = create(:taxon, :name => 'Taxon two', :parent_id => taxonomy_root.id)
|
||||
taxon_three = create(:taxon, :name => 'Taxon three', :parent_id => taxonomy_root.id)
|
||||
|
||||
my_distributor = create(:distributor, :name => 'My Distributor')
|
||||
other_distributor = create(:distributor, :name => 'Other Distributor')
|
||||
my_distributor = create(:distributor_enterprise, :name => 'My Distributor')
|
||||
other_distributor = create(:distributor_enterprise, :name => 'Other Distributor')
|
||||
|
||||
1.times { create(:product, :taxons => [taxon_one], :distributors => [other_distributor]) }
|
||||
2.times { create(:product, :taxons => [taxon_two], :distributors => [other_distributor]) }
|
||||
|
||||
Reference in New Issue
Block a user