mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Auto-merge from CI [skip ci]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges", "VariantUnitManager", "OptionValueNamer", "SpreeApiKey"
|
||||
($scope, $http, dataFetcher, blankOption, pendingChanges, VariantUnitManager, OptionValueNamer, SpreeApiKey) ->
|
||||
"$scope", "$http", "$filter", "dataFetcher", "blankOption", "pendingChanges", "VariantUnitManager", "OptionValueNamer", "SpreeApiKey"
|
||||
($scope, $http, $filter, dataFetcher, blankOption, pendingChanges, VariantUnitManager, OptionValueNamer, SpreeApiKey) ->
|
||||
$scope.loading = true
|
||||
|
||||
$scope.initialiseVariables = ->
|
||||
@@ -32,7 +32,8 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
variant: { name: "Variant", visible: true }
|
||||
quantity: { name: "Quantity", visible: true }
|
||||
max: { name: "Max", visible: true }
|
||||
|
||||
unit_value: { name: "Weight/Volume", visible: false }
|
||||
price: { name: "Price", visible: false }
|
||||
$scope.initialise = ->
|
||||
$scope.initialiseVariables()
|
||||
authorise_api_reponse = ""
|
||||
@@ -42,13 +43,15 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
if $scope.spree_api_key_ok
|
||||
$http.defaults.headers.common["X-Spree-Token"] = SpreeApiKey
|
||||
dataFetcher("/api/enterprises/accessible?template=bulk_index&q[is_primary_producer_eq]=true").then (data) ->
|
||||
$scope.suppliers = data
|
||||
$scope.suppliers = $filter('orderBy')(data, 'name')
|
||||
$scope.suppliers.unshift blankOption()
|
||||
dataFetcher("/api/enterprises/accessible?template=bulk_index&q[is_distributor_eq]=true").then (data) ->
|
||||
$scope.distributors = data
|
||||
dataFetcher("/api/enterprises/accessible?template=bulk_index&q[sells_in][]=own&q[sells_in][]=any").then (data) ->
|
||||
$scope.distributors = $filter('orderBy')(data, 'name')
|
||||
$scope.distributors.unshift blankOption()
|
||||
ocFetcher = dataFetcher("/api/order_cycles/accessible").then (data) ->
|
||||
ocFetcher = dataFetcher("/api/order_cycles/accessible?as=distributor&q[orders_close_at_gt]=#{formatDate(daysFromToday(-90))}").then (data) ->
|
||||
$scope.orderCycles = data
|
||||
$scope.orderCyclesByID = []
|
||||
$scope.orderCyclesByID[oc.id] = oc for oc in $scope.orderCycles
|
||||
$scope.orderCycles.unshift blankOption()
|
||||
$scope.fetchOrders()
|
||||
ocFetcher.then ->
|
||||
@@ -60,7 +63,7 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
|
||||
$scope.fetchOrders = ->
|
||||
$scope.loading = true
|
||||
dataFetcher("/api/orders/managed?template=bulk_index;page=1;per_page=500;q[completed_at_not_null]=true;q[completed_at_gt]=#{$scope.startDate};q[completed_at_lt]=#{$scope.endDate}").then (data) ->
|
||||
dataFetcher("/admin/orders/managed?template=bulk_index;page=1;per_page=500;q[state_not_eq]=canceled;q[completed_at_not_null]=true;q[completed_at_gt]=#{$scope.startDate};q[completed_at_lt]=#{$scope.endDate}").then (data) ->
|
||||
$scope.resetOrders data
|
||||
$scope.loading = false
|
||||
|
||||
@@ -162,6 +165,25 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
$scope.supplierFilter = $scope.suppliers[0].id
|
||||
$scope.orderCycleFilter = $scope.orderCycles[0].id
|
||||
$scope.quickSearch = ""
|
||||
|
||||
$scope.weightAdjustedPrice = (lineItem, oldValue) ->
|
||||
if oldValue <= 0
|
||||
oldValue = lineItem.units_variant.unit_value
|
||||
if lineItem.unit_value <= 0
|
||||
lineItem.unit_value = lineItem.units_variant.unit_value
|
||||
lineItem.price = lineItem.price * lineItem.unit_value / oldValue
|
||||
#$scope.bulk_order_form.line_item.price.$setViewValue($scope.bulk_order_form.line_item.price.$viewValue)
|
||||
|
||||
$scope.unitValueLessThanZero = (lineItem) ->
|
||||
if lineItem.units_variant.unit_value <= 0
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
$scope.$watch "orderCycleFilter", (newVal, oldVal) ->
|
||||
unless $scope.orderCycleFilter == "0" || angular.equals(newVal, oldVal)
|
||||
$scope.startDate = $scope.orderCyclesByID[$scope.orderCycleFilter].first_order
|
||||
$scope.endDate = $scope.orderCyclesByID[$scope.orderCycleFilter].last_order
|
||||
]
|
||||
|
||||
daysFromToday = (days) ->
|
||||
|
||||
@@ -8,7 +8,9 @@ angular.module("ofn.admin").directive "ofnLineItemUpdAttr", [
|
||||
scope.$watch ->
|
||||
scope.$eval(attrs.ngModel)
|
||||
, (value) ->
|
||||
if ngModel.$dirty
|
||||
#if ngModel.$dirty
|
||||
# i think i can take this out, this directive is still only called
|
||||
# on a change and only an updated value will create a db call.
|
||||
if value == element.dbValue
|
||||
pendingChanges.remove(scope.line_item.id, attrName)
|
||||
switchClass( element, "", ["update-pending", "update-error", "update-success"], false )
|
||||
@@ -20,4 +22,4 @@ angular.module("ofn.admin").directive "ofnLineItemUpdAttr", [
|
||||
url: "/api/orders/#{scope.line_item.order.number}/line_items/#{scope.line_item.id}?line_item[#{attrName}]=#{value}"
|
||||
pendingChanges.add(scope.line_item.id, attrName, changeObj)
|
||||
switchClass( element, "update-pending", ["update-error", "update-success"], false )
|
||||
]
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Darkswarm.controller "HubNodeCtrl", ($scope, HashNavigation, Navigation, $location, $templateCache, CurrentHub) ->
|
||||
$scope.toggle = ->
|
||||
HashNavigation.toggle $scope.hub.hash
|
||||
$scope.toggle = (e) ->
|
||||
HashNavigation.toggle $scope.hub.hash if !angular.element(e.target).inheritedData('is-link')
|
||||
|
||||
$scope.open = ->
|
||||
HashNavigation.active $scope.hub.hash
|
||||
|
||||
@@ -65,6 +65,24 @@
|
||||
.active_table_row:nth-child(2)
|
||||
padding-bottom: 0.75rem
|
||||
|
||||
|
||||
.producers-list
|
||||
li.more-producers-link
|
||||
.less
|
||||
display: none
|
||||
a:hover
|
||||
text-decoration: underline
|
||||
li.additional-producer
|
||||
display: none
|
||||
&.show-more-producers
|
||||
li.additional-producer
|
||||
display: block
|
||||
li.more-producers-link
|
||||
.more
|
||||
display: none
|
||||
.less
|
||||
display: block
|
||||
|
||||
//CURRENT hub (shows selected hub)
|
||||
&.current
|
||||
//overwrites active_table
|
||||
@@ -83,6 +101,7 @@
|
||||
.active_table_row:first-child .skinny-head
|
||||
background-color: rgba(255,255,255,0.85)
|
||||
|
||||
|
||||
//INACTIVE - closed hub
|
||||
&.inactive
|
||||
&.closed, &.open
|
||||
|
||||
@@ -13,7 +13,8 @@ module Api
|
||||
end
|
||||
|
||||
def accessible
|
||||
@enterprises = Enterprise.ransack(params[:q]).result.accessible_by(current_api_user)
|
||||
permitted = OpenFoodNetwork::Permissions.new(current_api_user).order_cycle_enterprises
|
||||
@enterprises = permitted.ransack(params[:q]).result
|
||||
render params[:template] || :bulk_index
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,16 @@ module Api
|
||||
end
|
||||
|
||||
def accessible
|
||||
@order_cycles = OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
|
||||
@order_cycles = if params[:as] == "distributor"
|
||||
OrderCycle.ransack(params[:q]).result.
|
||||
involving_managed_distributors_of(current_api_user).order('updated_at DESC')
|
||||
elsif params[:as] == "producer"
|
||||
OrderCycle.ransack(params[:q]).result.
|
||||
involving_managed_producers_of(current_api_user).order('updated_at DESC')
|
||||
else
|
||||
OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
|
||||
end
|
||||
|
||||
render params[:template] || :bulk_index
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ Spree::Admin::OrdersController.class_eval do
|
||||
# We need to add expections for collection actions other than :index here
|
||||
# because spree_auth_devise causes load_order to be called, which results
|
||||
# in an auth failure as the @order object is nil for collection actions
|
||||
before_filter :check_authorization, :except => :bulk_management
|
||||
before_filter :check_authorization, except: [:bulk_management, :managed]
|
||||
|
||||
# After updating an order, the fees should be updated as well
|
||||
# Currently, adding or deleting line items does not trigger updating the
|
||||
@@ -17,7 +17,7 @@ Spree::Admin::OrdersController.class_eval do
|
||||
after_filter :update_distribution_charge, :only => :update
|
||||
|
||||
respond_override :index => { :html =>
|
||||
{ :success => lambda {
|
||||
{ :success => lambda {
|
||||
# Filter orders to only show those distributed by current user (or all for admin user)
|
||||
@orders = @search.result.includes([:user, :shipments, :payments]).
|
||||
distributed_by_user(spree_current_user).
|
||||
@@ -37,4 +37,10 @@ Spree::Admin::OrdersController.class_eval do
|
||||
def update_distribution_charge
|
||||
@order.update_distribution_charge!
|
||||
end
|
||||
|
||||
def managed
|
||||
permissions = OpenFoodNetwork::Permissions.new(spree_current_user)
|
||||
@orders = permissions.editable_orders.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
||||
render json: @orders, each_serializer: Api::Admin::OrderSerializer
|
||||
end
|
||||
end
|
||||
|
||||
@@ -406,27 +406,34 @@ Spree::Admin::ReportsController.class_eval do
|
||||
end
|
||||
params[:q][:meta_sort] ||= "completed_at.desc"
|
||||
|
||||
# -- Search
|
||||
@search = Spree::Order.complete.not_state(:canceled).managed_by(spree_current_user).search(params[:q])
|
||||
orders = @search.result
|
||||
@line_items = orders.map do |o|
|
||||
lis = o.line_items.managed_by(spree_current_user)
|
||||
lis = lis.supplied_by_any(params[:supplier_id_in]) if params[:supplier_id_in].present?
|
||||
lis
|
||||
end.flatten
|
||||
#payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
|
||||
permissions = OpenFoodNetwork::Permissions.new(spree_current_user)
|
||||
|
||||
# -- Prepare form options
|
||||
my_distributors = Enterprise.is_distributor.managed_by(spree_current_user)
|
||||
my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user)
|
||||
# -- Search
|
||||
|
||||
@search = Spree::Order.complete.not_state(:canceled).search(params[:q])
|
||||
orders = permissions.visible_orders.merge(@search.result)
|
||||
|
||||
@line_items = permissions.visible_line_items.merge(Spree::LineItem.where(order_id: orders))
|
||||
@line_items = @line_items.supplied_by_any(params[:supplier_id_in]) if params[:supplier_id_in].present?
|
||||
|
||||
line_items_with_hidden_details = @line_items.where('"spree_line_items"."id" NOT IN (?)', permissions.editable_line_items)
|
||||
@line_items.select{ |li| line_items_with_hidden_details.include? li }.each do |line_item|
|
||||
# TODO We should really be hiding customer code here too, but until we
|
||||
# have an actual association between order and customer, it's a bit tricky
|
||||
line_item.order.bill_address.assign_attributes(firstname: "HIDDEN", lastname: "", phone: "", address1: "", address2: "", city: "", zipcode: "", state: nil)
|
||||
line_item.order.ship_address.assign_attributes(firstname: "HIDDEN", lastname: "", phone: "", address1: "", address2: "", city: "", zipcode: "", state: nil)
|
||||
line_item.order.assign_attributes(email: "HIDDEN")
|
||||
end
|
||||
|
||||
# My distributors and any distributors distributing products I supply
|
||||
@distributors = my_distributors | Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers))
|
||||
@distributors = permissions.visible_enterprises_for_order_reports.is_distributor
|
||||
|
||||
# My suppliers and any suppliers supplying products I distribute
|
||||
@suppliers = my_suppliers | my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
|
||||
@suppliers = permissions.visible_enterprises_for_order_reports.is_primary_producer
|
||||
|
||||
@order_cycles = OrderCycle.active_or_complete.
|
||||
involving_managed_distributors_of(spree_current_user).order('orders_close_at DESC')
|
||||
|
||||
@order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC')
|
||||
@report_types = REPORT_TYPES[:orders_and_fulfillment]
|
||||
@report_type = params[:report_type]
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
Spree::Api::LineItemsController.class_eval do
|
||||
after_filter :apply_enterprise_fees, :only => :update
|
||||
|
||||
def apply_enterprise_fees
|
||||
authorize! :read, order
|
||||
order.update_distribution_charge!
|
||||
end
|
||||
end
|
||||
@@ -4,12 +4,4 @@ Spree::Api::OrdersController.class_eval do
|
||||
# because Spree's API controller causes authorize_read! to be called, which
|
||||
# results in an ActiveRecord::NotFound Exception as the order object is not
|
||||
# defined for collection actions
|
||||
before_filter :authorize_read!, :except => [:managed]
|
||||
|
||||
def managed
|
||||
authorize! :admin, Spree::Order
|
||||
authorize! :read, Spree::Order
|
||||
@orders = Spree::Order.ransack(params[:q]).result.distributed_by_user(current_api_user).page(params[:page]).per(params[:per_page])
|
||||
respond_with(@orders, default_template: :index)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ Spree::Api::ProductsController.class_eval do
|
||||
|
||||
# TODO: This should be named 'managed'. Is the action above used? Maybe we should remove it.
|
||||
def bulk_products
|
||||
@products = OpenFoodNetwork::Permissions.new(current_api_user).managed_products.
|
||||
@products = OpenFoodNetwork::Permissions.new(current_api_user).editable_products.
|
||||
merge(product_scope).
|
||||
order('created_at DESC').
|
||||
ransack(params[:q]).result.
|
||||
|
||||
@@ -162,17 +162,6 @@ class Enterprise < ActiveRecord::Base
|
||||
end
|
||||
}
|
||||
|
||||
# Return enterprises that participate in order cycles that user coordinates, sends to or receives from
|
||||
scope :accessible_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
else
|
||||
with_order_cycles_outer.
|
||||
where('order_cycles.id IN (?)', OrderCycle.accessible_by(user)).
|
||||
select('DISTINCT enterprises.*')
|
||||
end
|
||||
}
|
||||
|
||||
def self.find_near(suburb)
|
||||
enterprises = []
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class OrderCycle < ActiveRecord::Base
|
||||
closed.
|
||||
where("order_cycles.orders_close_at >= ?", 31.days.ago).
|
||||
order("order_cycles.orders_close_at DESC") }
|
||||
|
||||
|
||||
scope :soonest_opening, lambda { upcoming.order('order_cycles.orders_open_at ASC') }
|
||||
|
||||
scope :distributing_product, lambda { |product|
|
||||
@@ -64,6 +64,25 @@ class OrderCycle < ActiveRecord::Base
|
||||
joins('LEFT OUTER JOIN enterprises ON (enterprises.id = exchanges.sender_id OR enterprises.id = exchanges.receiver_id)')
|
||||
}
|
||||
|
||||
scope :involving_managed_distributors_of, lambda { |user|
|
||||
enterprises = Enterprise.managed_by(user)
|
||||
|
||||
# Order cycles where I managed an enterprise at either end of an outgoing exchange
|
||||
# ie. coordinator or distibutor
|
||||
joins(:exchanges).merge(Exchange.outgoing).
|
||||
where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises).
|
||||
select('DISTINCT order_cycles.*')
|
||||
}
|
||||
|
||||
scope :involving_managed_producers_of, lambda { |user|
|
||||
enterprises = Enterprise.managed_by(user)
|
||||
|
||||
# Order cycles where I managed an enterprise at either end of an incoming exchange
|
||||
# ie. coordinator or producer
|
||||
joins(:exchanges).merge(Exchange.incoming).
|
||||
where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises).
|
||||
select('DISTINCT order_cycles.*')
|
||||
}
|
||||
|
||||
def self.first_opening_for(distributor)
|
||||
with_distributor(distributor).soonest_opening.first
|
||||
|
||||
@@ -120,7 +120,7 @@ class AbilityDecorator
|
||||
can [:admin, :index, :read, :create, :edit], Spree::Classification
|
||||
|
||||
# Reports page
|
||||
can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory], :report
|
||||
can [:admin, :index, :customers, :orders_and_distributors, :group_buys, :bulk_coop, :payments, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], :report
|
||||
end
|
||||
|
||||
def add_order_cycle_management_abilities(user)
|
||||
@@ -142,7 +142,7 @@ class AbilityDecorator
|
||||
# during the order creation process from the admin backend
|
||||
order.distributor.nil? || user.enterprises.include?(order.distributor)
|
||||
end
|
||||
can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor)
|
||||
can [:admin, :bulk_management, :managed], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor)
|
||||
can [:admin, :create], Spree::LineItem
|
||||
can [:destroy], Spree::LineItem do |item|
|
||||
user.admin? || user.enterprises.include?(order.distributor) || user == order.order_cycle.manager
|
||||
@@ -154,7 +154,6 @@ class AbilityDecorator
|
||||
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::ReturnAuthorization
|
||||
can [:destroy], Spree::Adjustment do |adjustment|
|
||||
# Sharing code with destroying a line item. This should be unified and probably applied for other actions as well.
|
||||
binding.pry
|
||||
if user.admin?
|
||||
true
|
||||
elsif adjustment.adjustable.instance_of? Spree::Order
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Spree::LineItem.class_eval do
|
||||
attr_accessible :max_quantity
|
||||
attr_accessible :max_quantity, :unit_value
|
||||
attr_accessible :unit_value, :price, :as => :api
|
||||
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
|
||||
@@ -127,6 +127,7 @@ Spree::Order.class_eval do
|
||||
else
|
||||
current_item = Spree::LineItem.new(:quantity => quantity, max_quantity: max_quantity)
|
||||
current_item.variant = variant
|
||||
current_item.unit_value = variant.unit_value
|
||||
if currency
|
||||
current_item.currency = currency unless currency.nil?
|
||||
current_item.price = variant.price_in(currency).amount
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
Spree.user_class.class_eval do
|
||||
handle_asynchronously :send_reset_password_instructions
|
||||
if method_defined? :send_reset_password_instructions_with_delay
|
||||
Bugsnag.notify RuntimeError.new "send_reset_password_instructions already handled asyncronously - double-calling results in infinite job loop"
|
||||
else
|
||||
handle_asynchronously :send_reset_password_instructions
|
||||
end
|
||||
|
||||
has_many :enterprise_roles, :dependent => :destroy
|
||||
has_many :enterprises, through: :enterprise_roles
|
||||
|
||||
14
app/serializers/api/admin/basic_order_cycle_serializer.rb
Normal file
14
app/serializers/api/admin/basic_order_cycle_serializer.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class Api::Admin::BasicOrderCycleSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :first_order, :last_order
|
||||
|
||||
has_many :suppliers, serializer: Api::Admin::IdNameSerializer
|
||||
has_many :distributors, serializer: Api::Admin::IdNameSerializer
|
||||
|
||||
def first_order
|
||||
object.orders_open_at.strftime("%F")
|
||||
end
|
||||
|
||||
def last_order
|
||||
(object.orders_close_at + 1.day).strftime("%F")
|
||||
end
|
||||
end
|
||||
19
app/serializers/api/admin/line_item_serializer.rb
Normal file
19
app/serializers/api/admin/line_item_serializer.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Api::Admin::LineItemSerializer < ActiveModel::Serializer
|
||||
attributes :id, :quantity, :max_quantity, :supplier, :price, :unit_value, :units_product, :units_variant
|
||||
|
||||
def supplier
|
||||
Api::Admin::IdNameSerializer.new(object.product.supplier).serializable_hash
|
||||
end
|
||||
|
||||
def units_product
|
||||
Api::Admin::UnitsProductSerializer.new(object.product).serializable_hash
|
||||
end
|
||||
|
||||
def units_variant
|
||||
Api::Admin::UnitsVariantSerializer.new(object.variant).serializable_hash
|
||||
end
|
||||
|
||||
def unit_value
|
||||
object.unit_value.to_f
|
||||
end
|
||||
end
|
||||
31
app/serializers/api/admin/order_serializer.rb
Normal file
31
app/serializers/api/admin/order_serializer.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
class Api::Admin::OrderSerializer < ActiveModel::Serializer
|
||||
attributes :id, :number, :full_name, :email, :phone, :completed_at, :line_items
|
||||
|
||||
has_one :distributor, serializer: Api::Admin::IdNameSerializer
|
||||
has_one :order_cycle, serializer: Api::Admin::BasicOrderCycleSerializer
|
||||
|
||||
def full_name
|
||||
object.billing_address.nil? ? "" : ( object.billing_address.full_name || "" )
|
||||
end
|
||||
|
||||
def email
|
||||
object.email || ""
|
||||
end
|
||||
|
||||
def phone
|
||||
object.billing_address.nil? ? "a" : ( object.billing_address.phone || "" )
|
||||
end
|
||||
|
||||
def completed_at
|
||||
object.completed_at.blank? ? "" : object.completed_at.strftime("%F %T")
|
||||
end
|
||||
|
||||
def line_items
|
||||
# we used to have a scope here, but we are at the point where a user which can edit an order
|
||||
# should be able to edit all of the line_items as well, making the scope redundant
|
||||
ActiveModel::ArraySerializer.new(
|
||||
object.line_items.order('id ASC'),
|
||||
{each_serializer: Api::Admin::LineItemSerializer}
|
||||
)
|
||||
end
|
||||
end
|
||||
3
app/serializers/api/admin/units_product_serializer.rb
Normal file
3
app/serializers/api/admin/units_product_serializer.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Api::Admin::UnitsProductSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :group_buy_unit_size, :variant_unit
|
||||
end
|
||||
8
app/serializers/api/admin/units_variant_serializer.rb
Normal file
8
app/serializers/api/admin/units_variant_serializer.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Api::Admin::UnitsVariantSerializer < ActiveModel::Serializer
|
||||
attributes :id, :full_name, :unit_value
|
||||
|
||||
def full_name
|
||||
full_name = object.full_name
|
||||
object.product.name + (full_name.empty? ? "" : ": #{full_name}")
|
||||
end
|
||||
end
|
||||
@@ -1,9 +1,11 @@
|
||||
object @order_cycle
|
||||
|
||||
attributes :id, :name
|
||||
node( :first_order ) { |order| order.orders_open_at.strftime("%F") }
|
||||
node( :last_order ) { |order| (order.orders_close_at + 1.day).strftime("%F") }
|
||||
node( :suppliers ) do |oc|
|
||||
partial 'api/enterprises/bulk_index', :object => oc.suppliers
|
||||
end
|
||||
node( :distributors ) do |oc|
|
||||
partial 'api/enterprises/bulk_index', :object => oc.distributors
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.row.active_table_row{"ng-show" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"}
|
||||
.row.active_table_row{"ng-show" => "open()", "ng-click" => "toggle($event)", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"}
|
||||
.columns.small-12.medium-6.large-5.fat
|
||||
%div{"bo-if" => "hub.taxons"}
|
||||
%label Shop for
|
||||
@@ -21,8 +21,20 @@
|
||||
.columns.small-12.medium-3.large-5.fat
|
||||
%div{"bo-if" => "hub.producers"}
|
||||
%label Our producers
|
||||
%ul.small-block-grid-2.medium-block-grid-1.large-block-grid-2
|
||||
%li{"ng-repeat" => "enterprise in hub.producers"}
|
||||
%ul.small-block-grid-2.medium-block-grid-1.large-block-grid-2{"ng-class" => "{'show-more-producers' : toggleMoreProducers}", "class" => "producers-list"}
|
||||
%li{"ng-repeat" => "enterprise in hub.producers | limitTo:7"}
|
||||
%enterprise-modal
|
||||
%i.ofn-i_036-producers
|
||||
%span{"bo-text" => "enterprise.name"}
|
||||
%li{"data-is-link" => "true", "class" => "more-producers-link", "bo-show" => "hub.producers.length>7"}
|
||||
%a{"ng-click" => "toggleMoreProducers=!toggleMoreProducers"}
|
||||
.more
|
||||
+
|
||||
%span{"bo-text" => "hub.producers.length-7"}
|
||||
More
|
||||
.less
|
||||
Show less
|
||||
%li{"ng-repeat" => "enterprise in hub.producers.slice(7,hub.producers.length)", "class" => "additional-producer"}
|
||||
%enterprise-modal
|
||||
%i.ofn-i_036-producers
|
||||
%span{"bo-text" => "enterprise.name"}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true}
|
||||
.row.active_table_row{"ng-if" => "hub.is_distributor", "ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}", bindonce: true}
|
||||
|
||||
.columns.small-12.medium-6.large-5.skinny-head
|
||||
%a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
|
||||
|
||||
@@ -41,3 +41,4 @@
|
||||
|
||||
#footer
|
||||
%loading
|
||||
= render 'shared/analytics'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.row.active_table_row{"ng-if" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"}
|
||||
.row.active_table_row{"ng-if" => "open()", "ng-click" => "toggle($event)", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"}
|
||||
|
||||
.columns.small-12.medium-7.large-7.fat
|
||||
/ Will add in long description available once clean up HTML formatting producer.long_description
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"}
|
||||
.row.active_table_row{"ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"}
|
||||
.columns.small-12.medium-4.large-4.skinny-head
|
||||
%span{"bo-if" => "producer.is_distributor" }
|
||||
%a.is_distributor{"bo-href" => "producer.path" }
|
||||
|
||||
8
app/views/shared/_analytics.html.haml
Normal file
8
app/views/shared/_analytics.html.haml
Normal file
@@ -0,0 +1,8 @@
|
||||
:javascript
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-62912229-1', 'auto');
|
||||
ga('send', 'pageview');
|
||||
@@ -43,7 +43,7 @@
|
||||
Shared Resource?
|
||||
%div{ :class => "eight columns" }
|
||||
%h6{ :class => "eight columns alpha", 'ng-show' => 'sharedResource', style: 'text-align: center;' } {{ selectedUnitsProduct.name + ": ALL" }}
|
||||
%h6{ :class => "eight columns alpha", 'ng-hide' => 'sharedResource', style: 'text-align: center;' } {{ selectedUnitsVariant.unit_text }}
|
||||
%h6{ :class => "eight columns alpha", 'ng-hide' => 'sharedResource', style: 'text-align: center;' } {{ selectedUnitsVariant.full_name }}
|
||||
%div{ :class => "four columns omega" }
|
||||
%h6{ :class => "four columns alpha", :style => 'text-align: right;' }
|
||||
%a{ :href => '#', 'ng-click' => 'selectedUnitsVariant = {};selectedUnitsProduct = {};sharedResource=false;' } Clear
|
||||
@@ -100,53 +100,60 @@
|
||||
%div{ :class => "sixteen columns alpha", 'ng-show' => '!loading && filteredLineItems.length == 0'}
|
||||
%h1#no_results No orders found.
|
||||
%div{ 'ng-hide' => 'loading || filteredLineItems.length == 0' }
|
||||
%table.index#listing_orders.bulk{ :class => "sixteen columns alpha" }
|
||||
%thead
|
||||
%tr
|
||||
%th.bulk
|
||||
%input{ :type => "checkbox", :name => 'toggle_bulk', 'ng-click' => 'toggleAllCheckboxes()', 'ng-checked' => "allBoxesChecked()" }
|
||||
%th.order_no{ 'ng-show' => 'columns.order_no.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.number'; reverse = !reverse" } Order No.
|
||||
%th.full_name{ 'ng-show' => 'columns.full_name.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.full_name'; reverse = !reverse" } Name
|
||||
%th.email{ 'ng-show' => 'columns.email.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.email'; reverse = !reverse" } Email
|
||||
%th.phone{ 'ng-show' => 'columns.phone.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.phone'; reverse = !reverse" } Phone
|
||||
%th.date{ 'ng-show' => 'columns.order_date.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.completed_at'; reverse = !reverse" } Order Date
|
||||
%th.producer{ 'ng-show' => 'columns.producer.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'supplier.name'; reverse = !reverse" } Producer
|
||||
%th.order_cycle{ 'ng-show' => 'columns.order_cycle.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.order_cycle.name'; reverse = !reverse" } Order Cycle
|
||||
%th.hub{ 'ng-show' => 'columns.hub.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.distributor.name'; reverse = !reverse" } Hub
|
||||
%th.variant{ 'ng-show' => 'columns.variant.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'units_variant.unit_text'; reverse = !reverse" } Product: Unit
|
||||
%th.quantity{ 'ng-show' => 'columns.quantity.visible' } Quantity
|
||||
%th.max{ 'ng-show' => 'columns.max.visible' } Max
|
||||
%th.actions
|
||||
%th.actions
|
||||
Ask?
|
||||
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
|
||||
%tr.line_item{ 'ng-repeat' => "line_item in filteredLineItems = ( lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter | variantFilter:selectedUnitsProduct:selectedUnitsVariant:sharedResource | orderBy:predicate:reverse )", 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%td.bulk
|
||||
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked' }
|
||||
%td.order_no{ 'ng-show' => 'columns.order_no.visible' } {{ line_item.order.number }}
|
||||
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.full_name }}
|
||||
%td.email{ 'ng-show' => 'columns.email.visible' } {{ line_item.order.email }}
|
||||
%td.phone{ 'ng-show' => 'columns.phone.visible' } {{ line_item.order.phone }}
|
||||
%td.date{ 'ng-show' => 'columns.order_date.visible' } {{ line_item.order.completed_at }}
|
||||
%td.producer{ 'ng-show' => 'columns.producer.visible' } {{ line_item.supplier.name }}
|
||||
%td.order_cycle{ 'ng-show' => 'columns.order_cycle.visible' } {{ line_item.order.order_cycle.name }}
|
||||
%td.hub{ 'ng-show' => 'columns.hub.visible' } {{ line_item.order.distributor.name }}
|
||||
%td.variant{ 'ng-show' => 'columns.variant.visible' }
|
||||
%a{ :href => '#', 'ng-click' => "setSelectedUnitsVariant(line_item.units_product,line_item.units_variant)" } {{ line_item.units_variant.unit_text }}
|
||||
%td.quantity{ 'ng-show' => 'columns.quantity.visible' }
|
||||
%input{ :type => 'number', :name => 'quantity', 'ng-model' => "line_item.quantity", 'ofn-line-item-upd-attr' => "quantity" }
|
||||
%td.max{ 'ng-show' => 'columns.max.visible' } {{ line_item.max_quantity }}
|
||||
%td.actions
|
||||
%a{ :class => "edit-order icon-edit no-text", 'ofn-confirm-link-path' => "/admin/orders/{{line_item.order.number}}/edit" }
|
||||
%td.actions
|
||||
%a{ 'ng-click' => "deleteLineItem(line_item)", :class => "delete-line-item icon-trash no-text" }
|
||||
%input{ :type => "button", 'value' => 'Update', 'ng-click' => 'pendingChanges.submitAll()' }
|
||||
%form{ 'ng-model' => "bulk_order_form" }
|
||||
%table.index#listing_orders.bulk{ :class => "sixteen columns alpha" }
|
||||
%thead
|
||||
%tr
|
||||
%th.bulk
|
||||
%input{ :type => "checkbox", :name => 'toggle_bulk', 'ng-click' => 'toggleAllCheckboxes()', 'ng-checked' => "allBoxesChecked()" }
|
||||
%th.order_no{ 'ng-show' => 'columns.order_no.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.number'; reverse = !reverse" } Order No.
|
||||
%th.full_name{ 'ng-show' => 'columns.full_name.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.full_name'; reverse = !reverse" } Name
|
||||
%th.email{ 'ng-show' => 'columns.email.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.email'; reverse = !reverse" } Email
|
||||
%th.phone{ 'ng-show' => 'columns.phone.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.phone'; reverse = !reverse" } Phone
|
||||
%th.date{ 'ng-show' => 'columns.order_date.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.completed_at'; reverse = !reverse" } Order Date
|
||||
%th.producer{ 'ng-show' => 'columns.producer.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'supplier.name'; reverse = !reverse" } Producer
|
||||
%th.order_cycle{ 'ng-show' => 'columns.order_cycle.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.order_cycle.name'; reverse = !reverse" } Order Cycle
|
||||
%th.hub{ 'ng-show' => 'columns.hub.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'order.distributor.name'; reverse = !reverse" } Hub
|
||||
%th.variant{ 'ng-show' => 'columns.variant.visible' }
|
||||
%a{ :href => '', 'ng-click' => "predicate = 'units_variant.full_name'; reverse = !reverse" } Product: Unit
|
||||
%th.quantity{ 'ng-show' => 'columns.quantity.visible' } Quantity
|
||||
%th.max{ 'ng-show' => 'columns.max.visible' } Max
|
||||
%th.unit_value{ 'ng-show' => 'columns.unit_value.visible' } Weight/Volume
|
||||
%th.price{ 'ng-show' => 'columns.price.visible' } Price
|
||||
%th.actions
|
||||
%th.actions
|
||||
Ask?
|
||||
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
|
||||
%tr.line_item{ 'ng-repeat' => "line_item in filteredLineItems = ( lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter | variantFilter:selectedUnitsProduct:selectedUnitsVariant:sharedResource | orderBy:predicate:reverse )", 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%td.bulk
|
||||
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked' }
|
||||
%td.order_no{ 'ng-show' => 'columns.order_no.visible' } {{ line_item.order.number }}
|
||||
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.full_name }}
|
||||
%td.email{ 'ng-show' => 'columns.email.visible' } {{ line_item.order.email }}
|
||||
%td.phone{ 'ng-show' => 'columns.phone.visible' } {{ line_item.order.phone }}
|
||||
%td.date{ 'ng-show' => 'columns.order_date.visible' } {{ line_item.order.completed_at }}
|
||||
%td.producer{ 'ng-show' => 'columns.producer.visible' } {{ line_item.supplier.name }}
|
||||
%td.order_cycle{ 'ng-show' => 'columns.order_cycle.visible' } {{ line_item.order.order_cycle.name }}
|
||||
%td.hub{ 'ng-show' => 'columns.hub.visible' } {{ line_item.order.distributor.name }}
|
||||
%td.variant{ 'ng-show' => 'columns.variant.visible' }
|
||||
%a{ :href => '#', 'ng-click' => "setSelectedUnitsVariant(line_item.units_product,line_item.units_variant)" } {{ line_item.units_variant.full_name }}
|
||||
%td.quantity{ 'ng-show' => 'columns.quantity.visible' }
|
||||
%input{ :type => 'number', :name => 'quantity', 'ng-model' => "line_item.quantity", 'ofn-line-item-upd-attr' => "quantity" }
|
||||
%td.max{ 'ng-show' => 'columns.max.visible' } {{ line_item.max_quantity }}
|
||||
%td.unit_value{ 'ng-show' => 'columns.unit_value.visible' }
|
||||
%input{ :type => 'number', :name => 'unit_value', :id => 'unit_value', 'ng-model' => "line_item.unit_value", 'ng-readonly' => "unitValueLessThanZero(line_item)", 'ng-change' => "weightAdjustedPrice(line_item, {{ line_item.unit_value }})", 'ofn-line-item-upd-attr' => "unit_value" }
|
||||
%td.price{ 'ng-show' => 'columns.price.visible' }
|
||||
%input{ :type => 'text', :name => 'price', :id => 'price', :value => '{{ line_item.price | currency }}', 'ng-model' => "line_item.price", 'ng-readonly' => "true", 'ofn-line-item-upd-attr' => "price" }
|
||||
%td.actions
|
||||
%a{ :class => "edit-order icon-edit no-text", 'ofn-confirm-link-path' => "/admin/orders/{{line_item.order.number}}/edit" }
|
||||
%td.actions
|
||||
%a{ 'ng-click' => "deleteLineItem(line_item)", :class => "delete-line-item icon-trash no-text" }
|
||||
%input{ :type => "button", 'value' => 'Update', 'ng-click' => 'pendingChanges.submitAll()' }
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
include_blank: true)
|
||||
%br
|
||||
%br
|
||||
= label_tag nil, "Report Type: "
|
||||
= select_tag(:report_type, options_for_select(@report_types, @report_type))
|
||||
%br
|
||||
%br
|
||||
= check_box_tag :csv
|
||||
= label_tag :csv, "Download as csv"
|
||||
%br
|
||||
@@ -41,4 +45,3 @@
|
||||
- if @report.table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
object @line_item
|
||||
attributes :id, :quantity, :max_quantity
|
||||
node( :supplier ) { |li| partial 'api/enterprises/bulk_show', :object => li.product.supplier }
|
||||
node( :units_product ) { |li| partial 'spree/api/products/units_show', :object => li.product }
|
||||
node( :units_variant ) { |li| partial 'spree/api/variants/units_show', :object => li.variant }
|
||||
@@ -1,2 +0,0 @@
|
||||
collection @orders.order('id ASC')
|
||||
extends "spree/api/orders/bulk_show"
|
||||
@@ -1,14 +0,0 @@
|
||||
object @order
|
||||
attributes :id, :number
|
||||
|
||||
node( :full_name ) { |order| order.billing_address.nil? ? "" : ( order.billing_address.full_name || "" ) }
|
||||
node( :email ) { |order| order.email || "" }
|
||||
node( :phone ) { |order| order.billing_address.nil? ? "a" : ( order.billing_address.phone || "" ) }
|
||||
node( :completed_at ) { |order| order.completed_at.blank? ? "" : order.completed_at.strftime("%F %T") }
|
||||
node( :distributor ) { |order| partial 'api/enterprises/bulk_show', :object => order.distributor }
|
||||
node( :order_cycle ) { |order| partial 'api/order_cycles/bulk_show', :object => order.order_cycle }
|
||||
node( :line_items ) do |order|
|
||||
order.line_items.managed_by(@current_api_user).order('id ASC').map do |line_item|
|
||||
partial 'spree/api/line_items/bulk_show', :object => line_item
|
||||
end
|
||||
end
|
||||
@@ -1,2 +0,0 @@
|
||||
object @product
|
||||
attributes :id, :name, :group_buy_unit_size, :variant_unit
|
||||
@@ -1,9 +0,0 @@
|
||||
object @variant
|
||||
attributes :id
|
||||
|
||||
node( :unit_text ) do |v|
|
||||
options_text = v.options_text
|
||||
v.product.name + (options_text.empty? ? "" : ": #{options_text}")
|
||||
end
|
||||
|
||||
node( :unit_value ) { |v| v.unit_value }
|
||||
@@ -186,6 +186,10 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
|
||||
resources :orders do
|
||||
get :managed, on: :collection
|
||||
end
|
||||
end
|
||||
|
||||
resources :orders do
|
||||
|
||||
5
db/migrate/20150305004846_add_weight_to_line_items.rb
Normal file
5
db/migrate/20150305004846_add_weight_to_line_items.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddWeightToLineItems < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spree_line_items, :unit_value, :decimal, :precision => 8, :scale => 2
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class PopulateLineItemUnitValue < ActiveRecord::Migration
|
||||
def up
|
||||
execute "UPDATE spree_line_items SET unit_value = spree_variants.unit_value FROM spree_variants WHERE spree_line_items.variant_id = spree_variants.id"
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150424025907) do
|
||||
ActiveRecord::Schema.define(:version => 20150424151117) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
@@ -549,6 +549,7 @@ ActiveRecord::Schema.define(:version => 20150424025907) do
|
||||
t.string "currency"
|
||||
t.decimal "distribution_fee", :precision => 10, :scale => 2
|
||||
t.string "shipping_method_name"
|
||||
t.decimal "unit_value", :precision => 8, :scale => 2
|
||||
end
|
||||
|
||||
add_index "spree_line_items", ["order_id"], :name => "index_line_items_on_order_id"
|
||||
@@ -618,9 +619,9 @@ ActiveRecord::Schema.define(:version => 20150424025907) do
|
||||
t.string "email"
|
||||
t.text "special_instructions"
|
||||
t.integer "distributor_id"
|
||||
t.integer "order_cycle_id"
|
||||
t.string "currency"
|
||||
t.string "last_ip_address"
|
||||
t.integer "order_cycle_id"
|
||||
t.integer "cart_id"
|
||||
end
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ module OpenFoodNetwork
|
||||
|
||||
if @coordinator.sells == "any"
|
||||
# If the coordinator sells any, relationships come into play
|
||||
granting(:add_to_order_cycle, to: [@coordinator]).pluck(:id).each do |enterprise_id|
|
||||
related_enterprises_granting(:add_to_order_cycle, to: [@coordinator]).pluck(:id).each do |enterprise_id|
|
||||
coordinator_permitted << enterprise_id
|
||||
end
|
||||
|
||||
@@ -30,19 +30,19 @@ module OpenFoodNetwork
|
||||
Enterprise.where(id: coordinator_permitted | all_active)
|
||||
else
|
||||
# Any enterprises that I manage directly, which have granted P-OC to the coordinator
|
||||
managed_permitted = granting(:add_to_order_cycle, to: [@coordinator], scope: managed_participating_enterprises ).pluck(:id)
|
||||
managed_permitted = related_enterprises_granting(:add_to_order_cycle, to: [@coordinator], scope: managed_participating_enterprises ).pluck(:id)
|
||||
|
||||
# Any hubs in this OC that have been granted P-OC by producers I manage in this OC
|
||||
hubs_permitted = granted(:add_to_order_cycle, by: managed_participating_producers, scope: @order_cycle.distributors).pluck(:id)
|
||||
hubs_permitted = related_enterprises_granted(:add_to_order_cycle, by: managed_participating_producers, scope: @order_cycle.distributors).pluck(:id)
|
||||
|
||||
# Any hubs in this OC that have granted P-OC to producers I manage in this OC
|
||||
hubs_permitting = granting(:add_to_order_cycle, to: managed_participating_producers, scope: @order_cycle.distributors).pluck(:id)
|
||||
hubs_permitting = related_enterprises_granting(:add_to_order_cycle, to: managed_participating_producers, scope: @order_cycle.distributors).pluck(:id)
|
||||
|
||||
# Any producers in this OC that have been granted P-OC by hubs I manage in this OC
|
||||
producers_permitted = granted(:add_to_order_cycle, by: managed_participating_hubs, scope: @order_cycle.suppliers).pluck(:id)
|
||||
producers_permitted = related_enterprises_granted(:add_to_order_cycle, by: managed_participating_hubs, scope: @order_cycle.suppliers).pluck(:id)
|
||||
|
||||
# Any producers in this OC that have granted P-OC to hubs I manage in this OC
|
||||
producers_permitting = granting(:add_to_order_cycle, to: managed_participating_hubs, scope: @order_cycle.suppliers).pluck(:id)
|
||||
producers_permitting = related_enterprises_granting(:add_to_order_cycle, to: managed_participating_hubs, scope: @order_cycle.suppliers).pluck(:id)
|
||||
|
||||
managed_active = []
|
||||
hubs_active = []
|
||||
@@ -125,7 +125,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
# Any variants of any producers that have granted the hub P-OC
|
||||
producers = granting(:add_to_order_cycle, to: [hub], scope: Enterprise.is_primary_producer)
|
||||
producers = related_enterprises_granting(:add_to_order_cycle, to: [hub], scope: Enterprise.is_primary_producer)
|
||||
permitted_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id IN (?)', producers)
|
||||
|
||||
# PLUS any variants that are already in an outgoing exchange of this hub, so things don't break
|
||||
@@ -138,7 +138,7 @@ module OpenFoodNetwork
|
||||
Spree::Variant.where(id: coordinator_variants | permitted_variants | active_variants)
|
||||
else
|
||||
# Any variants produced by MY PRODUCERS that are in this order cycle, where my producer has granted P-OC to the hub
|
||||
producers = granting(:add_to_order_cycle, to: [hub], scope: managed_participating_producers)
|
||||
producers = related_enterprises_granting(:add_to_order_cycle, to: [hub], scope: managed_participating_producers)
|
||||
permitted_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id IN (?)', producers)
|
||||
|
||||
# PLUS any of my incoming producers' variants that are already in an outgoing exchange of this hub, so things don't break
|
||||
@@ -162,7 +162,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
# Any variants of any producers that have granted the hub P-OC
|
||||
producers = granting(:add_to_order_cycle, to: [hub], scope: Enterprise.is_primary_producer)
|
||||
producers = related_enterprises_granting(:add_to_order_cycle, to: [hub], scope: Enterprise.is_primary_producer)
|
||||
permitted_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id IN (?)', producers)
|
||||
|
||||
# PLUS any variants that are already in an outgoing exchange of this hub, so things don't break
|
||||
@@ -175,10 +175,10 @@ module OpenFoodNetwork
|
||||
Spree::Variant.where(id: coordinator_variants | permitted_variants | active_variants)
|
||||
else
|
||||
# Any of my managed producers in this order cycle granted P-OC by the hub
|
||||
granted_producers = granted(:add_to_order_cycle, by: [hub], scope: managed_participating_producers)
|
||||
granted_producers = related_enterprises_granted(:add_to_order_cycle, by: [hub], scope: managed_participating_producers)
|
||||
|
||||
# Any variants produced by MY PRODUCERS that are in this order cycle, where my producer has granted P-OC to the hub
|
||||
granting_producers = granting(:add_to_order_cycle, to: [hub], scope: granted_producers)
|
||||
granting_producers = related_enterprises_granting(:add_to_order_cycle, to: [hub], scope: granted_producers)
|
||||
permitted_variants = Spree::Variant.joins(:product).where('spree_products.supplier_id IN (?)', granting_producers)
|
||||
|
||||
Spree::Variant.where(id: permitted_variants)
|
||||
@@ -216,7 +216,7 @@ module OpenFoodNetwork
|
||||
# Find my managed hubs in this order cycle
|
||||
hubs = managed_participating_hubs
|
||||
# Any incoming exchange where the producer has granted P-OC to one or more of those hubs
|
||||
producers = granting(:add_to_order_cycle, to: hubs, scope: Enterprise.is_primary_producer).pluck :id
|
||||
producers = related_enterprises_granting(:add_to_order_cycle, to: hubs, scope: Enterprise.is_primary_producer).pluck :id
|
||||
permitted_exchanges = @order_cycle.exchanges.incoming.where(sender_id: producers).pluck :id
|
||||
|
||||
# TODO: remove active_exchanges when we think it is safe to do so
|
||||
@@ -235,7 +235,7 @@ module OpenFoodNetwork
|
||||
# Find my producers in this order cycle
|
||||
producers = managed_participating_producers.pluck :id
|
||||
# Any outgoing exchange where the distributor has been granted P-OC by one or more of those producers
|
||||
hubs = granted(:add_to_order_cycle, by: producers, scope: Enterprise.is_hub)
|
||||
hubs = related_enterprises_granted(:add_to_order_cycle, by: producers, scope: Enterprise.is_hub)
|
||||
permitted_exchanges = @order_cycle.exchanges.outgoing.where(receiver_id: hubs).pluck :id
|
||||
|
||||
# TODO: remove active_exchanges when we think it is safe to do so
|
||||
|
||||
@@ -5,23 +5,28 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def can_manage_complex_order_cycles?
|
||||
managed_and_related_enterprises_with(:add_to_order_cycle).any? do |e|
|
||||
managed_and_related_enterprises_granting(:add_to_order_cycle).any? do |e|
|
||||
e.sells == 'any'
|
||||
end
|
||||
end
|
||||
|
||||
# Find enterprises that an admin is allowed to add to an order cycle
|
||||
def order_cycle_enterprises
|
||||
def visible_enterprises_for_order_reports
|
||||
managed_and_related_enterprises_with :add_to_order_cycle
|
||||
end
|
||||
|
||||
def order_cycle_enterprises
|
||||
# Return enterprises that the user manages and those that have granted P-OC to managed enterprises
|
||||
managed_and_related_enterprises_granting :add_to_order_cycle
|
||||
end
|
||||
|
||||
# Find enterprises for which an admin is allowed to edit their profile
|
||||
def editable_enterprises
|
||||
managed_and_related_enterprises_with :edit_profile
|
||||
managed_and_related_enterprises_granting :edit_profile
|
||||
end
|
||||
|
||||
def variant_override_hubs
|
||||
managed_and_related_enterprises_with(:add_to_order_cycle).is_hub
|
||||
managed_and_related_enterprises_granting(:add_to_order_cycle).is_hub
|
||||
end
|
||||
|
||||
def variant_override_producers
|
||||
@@ -33,7 +38,7 @@ module OpenFoodNetwork
|
||||
# override variants
|
||||
# {hub1_id => [producer1_id, producer2_id, ...], ...}
|
||||
def variant_override_enterprises_per_hub
|
||||
hubs = managed_and_related_enterprises_with(:add_to_order_cycle).is_distributor
|
||||
hubs = managed_and_related_enterprises_granting(:add_to_order_cycle).is_distributor
|
||||
|
||||
# Permissions granted by create_variant_overrides relationship from producer to hub
|
||||
permissions = Hash[
|
||||
@@ -56,14 +61,69 @@ module OpenFoodNetwork
|
||||
permissions
|
||||
end
|
||||
|
||||
def managed_products
|
||||
# Find enterprises that an admin is allowed to add to an order cycle
|
||||
def visible_orders
|
||||
# Any orders that I can edit
|
||||
editable = editable_orders.pluck(:id)
|
||||
|
||||
# Any orders placed through hubs that my producers have granted P-OC, and which contain my their products
|
||||
# This is pretty complicated but it's looking for order where at least one of my producers has granted
|
||||
# P-OC to the distributor AND the order contains products of at least one of THE SAME producers
|
||||
granted_distributors = related_enterprises_granted(:add_to_order_cycle, by: managed_enterprises.is_primary_producer)
|
||||
produced = Spree::Order.with_line_items_variants_and_products_outer.
|
||||
where(
|
||||
"spree_orders.distributor_id IN (?) AND spree_products.supplier_id IN (?)",
|
||||
granted_distributors,
|
||||
related_enterprises_granting(:add_to_order_cycle, to: granted_distributors).merge(managed_enterprises.is_primary_producer)
|
||||
).pluck(:id)
|
||||
|
||||
Spree::Order.where(id: editable | produced)
|
||||
end
|
||||
|
||||
# Find enterprises that an admin is allowed to add to an order cycle
|
||||
def editable_orders
|
||||
# Any orders placed through any hub that I manage
|
||||
managed = Spree::Order.where(distributor_id: managed_enterprises.pluck(:id)).pluck(:id)
|
||||
|
||||
# Any order that is placed through an order cycle one of my managed enterprises coordinates
|
||||
coordinated = Spree::Order.where(order_cycle_id: coordinated_order_cycles.pluck(:id)).pluck(:id)
|
||||
|
||||
Spree::Order.where(id: managed | coordinated )
|
||||
end
|
||||
|
||||
def visible_line_items
|
||||
# Any line items that I can edit
|
||||
editable = editable_line_items.pluck(:id)
|
||||
|
||||
# Any from visible orders, where the product is produced by one of my managed producers
|
||||
produced = Spree::LineItem.where(order_id: visible_orders.pluck(:id)).joins(:product).
|
||||
where('spree_products.supplier_id IN (?)', managed_enterprises.is_primary_producer.pluck(:id))
|
||||
|
||||
Spree::LineItem.where(id: editable | produced)
|
||||
end
|
||||
|
||||
def editable_line_items
|
||||
Spree::LineItem.where(order_id: editable_orders)
|
||||
end
|
||||
|
||||
def editable_products
|
||||
managed_enterprise_products_ids = managed_enterprise_products.pluck :id
|
||||
permitted_enterprise_products_ids = related_enterprise_products.pluck :id
|
||||
Spree::Product.where('id IN (?)', managed_enterprise_products_ids + permitted_enterprise_products_ids)
|
||||
permitted_enterprise_products_ids = products_supplied_by(
|
||||
related_enterprises_granting(:manage_products).pluck(:id)
|
||||
).pluck :id
|
||||
Spree::Product.where('spree_products.id IN (?)', managed_enterprise_products_ids | permitted_enterprise_products_ids)
|
||||
end
|
||||
|
||||
def visible_products
|
||||
managed_enterprise_products_ids = managed_enterprise_products.pluck :id
|
||||
permitted_enterprise_products_ids = products_supplied_by(
|
||||
related_enterprises_granting(:manage_products).pluck(:id) | related_enterprises_granting(:add_to_order_cycle).pluck(:id)
|
||||
).pluck :id
|
||||
Spree::Product.where('spree_products.id IN (?)', managed_enterprise_products_ids | permitted_enterprise_products_ids)
|
||||
end
|
||||
|
||||
def managed_product_enterprises
|
||||
managed_and_related_enterprises_with :manage_products
|
||||
managed_and_related_enterprises_granting :manage_products
|
||||
end
|
||||
|
||||
def manages_one_enterprise?
|
||||
@@ -73,11 +133,30 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def managed_and_related_enterprises_with(permission)
|
||||
managed_enterprise_ids = managed_enterprises.pluck :id
|
||||
permitting_enterprise_ids = related_enterprises_with(permission).pluck :id
|
||||
def admin?
|
||||
@user.admin?
|
||||
end
|
||||
|
||||
Enterprise.where('id IN (?)', managed_enterprise_ids + permitting_enterprise_ids)
|
||||
def managed_and_related_enterprises_granting(permission)
|
||||
if admin?
|
||||
Enterprise.scoped
|
||||
else
|
||||
managed_enterprise_ids = managed_enterprises.pluck :id
|
||||
permitting_enterprise_ids = related_enterprises_granting(permission).pluck :id
|
||||
|
||||
Enterprise.where('id IN (?)', managed_enterprise_ids + permitting_enterprise_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def managed_and_related_enterprises_with(permission)
|
||||
if admin?
|
||||
Enterprise.scoped
|
||||
else
|
||||
managed = managed_enterprises.pluck(:id)
|
||||
granting = related_enterprises_granting(permission).pluck(:id)
|
||||
granted = related_enterprises_granted(permission).pluck(:id)
|
||||
Enterprise.where(id: managed | granting | granted)
|
||||
end
|
||||
end
|
||||
|
||||
def managed_enterprises
|
||||
@@ -85,16 +164,12 @@ module OpenFoodNetwork
|
||||
@managed_enterprises = Enterprise.managed_by(@user)
|
||||
end
|
||||
|
||||
def related_enterprises_with(permission)
|
||||
parent_ids = EnterpriseRelationship.
|
||||
permitting(managed_enterprises).
|
||||
with_permission(permission).
|
||||
pluck(:parent_id)
|
||||
|
||||
Enterprise.where('id IN (?)', parent_ids)
|
||||
def coordinated_order_cycles
|
||||
return @coordinated_order_cycles unless @coordinated_order_cycles.nil?
|
||||
@coordinated_order_cycles = OrderCycle.managed_by(@user)
|
||||
end
|
||||
|
||||
def granting(permission, options={})
|
||||
def related_enterprises_granting(permission, options={})
|
||||
parent_ids = EnterpriseRelationship.
|
||||
permitting(options[:to] || managed_enterprises).
|
||||
with_permission(permission).
|
||||
@@ -103,7 +178,7 @@ module OpenFoodNetwork
|
||||
(options[:scope] || Enterprise).where('enterprises.id IN (?)', parent_ids)
|
||||
end
|
||||
|
||||
def granted(permission, options={})
|
||||
def related_enterprises_granted(permission, options={})
|
||||
child_ids = EnterpriseRelationship.
|
||||
permitted_by(options[:by] || managed_enterprises).
|
||||
with_permission(permission).
|
||||
@@ -116,8 +191,8 @@ module OpenFoodNetwork
|
||||
Spree::Product.managed_by(@user)
|
||||
end
|
||||
|
||||
def related_enterprise_products
|
||||
Spree::Product.where('supplier_id IN (?)', related_enterprises_with(:manage_products))
|
||||
def products_supplied_by(suppliers)
|
||||
Spree::Product.where('supplier_id IN (?)', suppliers)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ module OpenFoodNetwork
|
||||
|
||||
def header
|
||||
[
|
||||
"Supplier",
|
||||
"Supplier",
|
||||
"Producer Suburb",
|
||||
"Product",
|
||||
"Product Properties",
|
||||
@@ -36,6 +36,16 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
def permissions
|
||||
return @permissions unless @permissions.nil?
|
||||
@permissions = OpenFoodNetwork::Permissions.new(@user)
|
||||
end
|
||||
|
||||
def visible_products
|
||||
return @visible_products unless @visible_products.nil?
|
||||
@visible_products = permissions.visible_products
|
||||
end
|
||||
|
||||
def variants
|
||||
filter(child_variants) + filter(master_variants)
|
||||
end
|
||||
@@ -43,7 +53,7 @@ module OpenFoodNetwork
|
||||
def child_variants
|
||||
Spree::Variant.where(:is_master => false)
|
||||
.joins(:product)
|
||||
.merge(Spree::Product.managed_by(@user))
|
||||
.merge(visible_products)
|
||||
.order("spree_products.name")
|
||||
end
|
||||
|
||||
@@ -53,7 +63,7 @@ module OpenFoodNetwork
|
||||
.where("(select spree_variants.id from spree_variants as other_spree_variants
|
||||
WHERE other_spree_variants.product_id = spree_variants.product_id
|
||||
AND other_spree_variants.is_master = 'f' LIMIT 1) IS NULL")
|
||||
.merge(Spree::Product.managed_by(@user))
|
||||
.merge(visible_products)
|
||||
.order("spree_products.name")
|
||||
end
|
||||
|
||||
|
||||
@@ -4,109 +4,210 @@ require 'spree/api/testing_support/helpers'
|
||||
module Api
|
||||
describe OrderCyclesController do
|
||||
include Spree::Api::TestingSupport::Helpers
|
||||
include AuthenticationWorkflow
|
||||
render_views
|
||||
|
||||
let!(:oc1) { FactoryGirl.create(:simple_order_cycle) }
|
||||
let!(:oc2) { FactoryGirl.create(:simple_order_cycle) }
|
||||
let(:coordinator) { oc1.coordinator }
|
||||
let(:attributes) { [:id, :name, :suppliers, :distributors] }
|
||||
describe "managed" do
|
||||
let!(:oc1) { FactoryGirl.create(:simple_order_cycle) }
|
||||
let!(:oc2) { FactoryGirl.create(:simple_order_cycle) }
|
||||
let(:coordinator) { oc1.coordinator }
|
||||
let(:attributes) { [:id, :name, :suppliers, :distributors] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => current_api_user
|
||||
end
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => current_api_user
|
||||
end
|
||||
|
||||
context "as a normal user" do
|
||||
sign_in_as_user!
|
||||
context "as a normal user" do
|
||||
sign_in_as_user!
|
||||
|
||||
it "should deny me access to managed order cycles" do
|
||||
spree_get :managed, { :format => :json }
|
||||
assert_unauthorized!
|
||||
it "should deny me access to managed order cycles" do
|
||||
spree_get :managed, { :format => :json }
|
||||
assert_unauthorized!
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
sign_in_as_enterprise_user! [:coordinator]
|
||||
|
||||
it "retrieves a list of variants with appropriate attributes" do
|
||||
get :managed, { :format => :json }
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "as an administrator" do
|
||||
sign_in_as_admin!
|
||||
|
||||
it "retrieves a list of variants with appropriate attributes" do
|
||||
get :managed, { :format => :json }
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
sign_in_as_enterprise_user! [:coordinator]
|
||||
describe "accessible" do
|
||||
context "without :as parameter" do
|
||||
let(:oc_supplier) { create(:supplier_enterprise) }
|
||||
let(:oc_distributor) { create(:distributor_enterprise) }
|
||||
let(:other_supplier) { create(:supplier_enterprise) }
|
||||
let(:oc_supplier_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: oc_supplier)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let(:oc_distributor_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: oc_distributor)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let(:other_supplier_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: other_supplier)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let!(:order_cycle) { create(:simple_order_cycle, suppliers: [oc_supplier], distributors: [oc_distributor]) }
|
||||
|
||||
it "retrieves a list of variants with appropriate attributes" do
|
||||
get :managed, { :format => :json }
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
context "as the user of a supplier to an order cycle" do
|
||||
before :each do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => oc_supplier_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
context "as an administrator" do
|
||||
sign_in_as_admin!
|
||||
it "gives me access" do
|
||||
json_response.length.should == 1
|
||||
json_response[0]['id'].should == order_cycle.id
|
||||
end
|
||||
end
|
||||
|
||||
it "retrieves a list of variants with appropriate attributes" do
|
||||
get :managed, { :format => :json }
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
context "as the user of some other supplier" do
|
||||
before :each do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => other_supplier_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
context "using the accessible action to list order cycles" do
|
||||
let(:oc_supplier) { create(:supplier_enterprise) }
|
||||
let(:oc_distributor) { create(:distributor_enterprise) }
|
||||
let(:other_supplier) { create(:supplier_enterprise) }
|
||||
let(:oc_supplier_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: oc_supplier)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let(:oc_distributor_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: oc_distributor)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let(:other_supplier_user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.enterprise_roles.create(enterprise: other_supplier)
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let!(:order_cycle) { create(:simple_order_cycle, suppliers: [oc_supplier], distributors: [oc_distributor]) }
|
||||
it "does not give me access" do
|
||||
json_response.length.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
context "as the user of a supplier to an order cycle" do
|
||||
before :each do
|
||||
context "as the user of a hub for the order cycle" do
|
||||
before :each do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => oc_distributor_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "gives me access" do
|
||||
json_response.length.should == 1
|
||||
json_response[0]['id'].should == order_cycle.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the :as parameter is set to 'distributor'" do
|
||||
let(:user) { create_enterprise_user }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let!(:oc) { create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor], suppliers: [producer]) }
|
||||
|
||||
let(:params) { { format: :json, as: 'distributor' } }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => oc_supplier_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
Spree.user_class.stub :find_by_spree_api_key => user
|
||||
end
|
||||
|
||||
it "gives me access" do
|
||||
json_response.length.should == 1
|
||||
json_response[0]['id'].should == order_cycle.id
|
||||
context "as the manager of a supplier in an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: producer)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
it "does not return the order cycle" do
|
||||
expect(assigns(:order_cycles)).to_not include oc
|
||||
end
|
||||
end
|
||||
|
||||
context "as the manager of a distributor in an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: distributor)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
it "returns the order cycle" do
|
||||
expect(assigns(:order_cycles)).to include oc
|
||||
end
|
||||
end
|
||||
|
||||
context "as the manager of the coordinator of an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: coordinator)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
it "returns the order cycle" do
|
||||
expect(assigns(:order_cycles)).to include oc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as the user of some other supplier" do
|
||||
before :each do
|
||||
context "when the :as parameter is set to 'producer'" do
|
||||
let(:user) { create_enterprise_user }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let!(:oc) { create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor], suppliers: [producer]) }
|
||||
|
||||
let(:params) { { format: :json, as: 'producer' } }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => other_supplier_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
Spree.user_class.stub :find_by_spree_api_key => user
|
||||
end
|
||||
|
||||
it "does not give me access" do
|
||||
json_response.length.should == 0
|
||||
end
|
||||
end
|
||||
context "as the manager of a producer in an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: producer)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
context "as the user of a hub for the order cycle" do
|
||||
before :each do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => oc_distributor_user
|
||||
spree_get :accessible, { :template => 'bulk_index', :format => :json }
|
||||
it "returns the order cycle" do
|
||||
expect(assigns(:order_cycles)).to include oc
|
||||
end
|
||||
end
|
||||
|
||||
it "gives me access" do
|
||||
json_response.length.should == 1
|
||||
json_response[0]['id'].should == order_cycle.id
|
||||
context "as the manager of a distributor in an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: distributor)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
it "does not return the order cycle" do
|
||||
expect(assigns(:order_cycles)).to_not include oc
|
||||
end
|
||||
end
|
||||
|
||||
context "as the manager of the coordinator of an order cycle" do
|
||||
before do
|
||||
user.enterprise_roles.create(enterprise: coordinator)
|
||||
spree_get :accessible, params
|
||||
end
|
||||
|
||||
it "returns the order cycle" do
|
||||
expect(assigns(:order_cycles)).to include oc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::OrdersController do
|
||||
let!(:order) { create(:order) }
|
||||
include AuthenticationWorkflow
|
||||
|
||||
context "updating an order with line items" do
|
||||
let!(:order) { create(:order) }
|
||||
let(:line_item) { create(:line_item) }
|
||||
before { login_as_admin }
|
||||
|
||||
@@ -27,4 +28,140 @@ describe Spree::Admin::OrdersController do
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "managed" do
|
||||
render_views
|
||||
|
||||
let(:order_attributes) { [:id, :full_name, :email, :phone, :completed_at, :line_items, :distributor, :order_cycle, :number] }
|
||||
|
||||
def self.make_simple_data!
|
||||
let!(:dist1) { FactoryGirl.create(:distributor_enterprise) }
|
||||
let!(:order1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:order2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:order3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item, order: order1) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item, order: order2) }
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, order: order2) }
|
||||
let!(:line_item4) { FactoryGirl.create(:line_item, order: order3) }
|
||||
let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier, :units_product, :units_variant] }
|
||||
end
|
||||
|
||||
context "as a normal user" do
|
||||
before { controller.stub spree_current_user: create_enterprise_user }
|
||||
|
||||
make_simple_data!
|
||||
|
||||
it "should deny me access to managed orders" do
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "as an administrator" do
|
||||
make_simple_data!
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: quick_login_as_admin
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders with appropriate attributes, including line items with appropriate attributes" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of line items with appropriate attributes" do
|
||||
li_keys = json_response.first['line_items'].first.keys.map{ |key| key.to_sym }
|
||||
line_item_attributes.all?{ |attr| li_keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts orders in ascending id order" do
|
||||
ids = json_response.map{ |order| order['id'] }
|
||||
ids[0].should < ids[1]
|
||||
ids[1].should < ids[2]
|
||||
end
|
||||
|
||||
it "formats completed_at to 'yyyy-mm-dd hh:mm'" do
|
||||
json_response.map{ |order| order['completed_at'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }.should == true
|
||||
end
|
||||
|
||||
it "returns an array for line_items" do
|
||||
json_response.map{ |order| order['line_items'] }.all?{ |a| a.is_a? Array }.should == true
|
||||
end
|
||||
|
||||
it "returns quantity and max quantity at integers" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['quantity'] }.all?{ |q| q.is_a? Fixnum }.should == true
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['max_quantity'] }.all?{ |mq| mq.nil? || mq.is_a?( Fixnum ) }.should == true
|
||||
end
|
||||
|
||||
it "returns supplier object with id and name keys" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['supplier'] }.all?{ |s| s.has_key?('id') && s.has_key?('name') }.should == true
|
||||
end
|
||||
|
||||
it "returns distributor object with id and name keys" do
|
||||
json_response.map{ |order| order['distributor'] }.all?{ |d| d.has_key?('id') && d.has_key?('name') }.should == true
|
||||
end
|
||||
|
||||
it "retrieves the order number" do
|
||||
json_response.map{ |order| order['number'] }.all?{ |number| number.match("^R\\d{5,10}$") }.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:distributor2) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
|
||||
let!(:order1) { FactoryGirl.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.now, distributor: distributor1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item, order: order1, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item, order: order1, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
let!(:order2) { FactoryGirl.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.now, distributor: distributor2, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, order: order2, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
|
||||
context "producer enterprise" do
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: supplier.owner
|
||||
spree_get :managed, { :format => :json }
|
||||
end
|
||||
|
||||
it "does not display line items for which my enterprise is a supplier" do
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context "coordinator enterprise" do
|
||||
before do
|
||||
controller.stub spree_current_user: coordinator.owner
|
||||
spree_get :managed, { :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "only displays line items from orders for which my enterprise is the order_cycle coorinator" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |line_item| line_item["id"] }.should match_array [line_item1.id, line_item2.id, line_item3.id]
|
||||
end
|
||||
end
|
||||
|
||||
context "hub enterprise" do
|
||||
before do
|
||||
controller.stub spree_current_user: distributor1.owner
|
||||
spree_get :managed, { :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "only displays line items from orders for which my enterprise is a distributor" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |line_item| line_item["id"] }.should match_array [line_item1.id, line_item2.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::ReportsController do
|
||||
|
||||
|
||||
# Given two distributors and two suppliers
|
||||
let(:ba) { create(:address) }
|
||||
let(:si) { "pick up on thursday please" }
|
||||
let(:s1) { create(:supplier_enterprise, address: create(:address)) }
|
||||
let(:s2) { create(:supplier_enterprise, address: create(:address)) }
|
||||
let(:s3) { create(:supplier_enterprise, address: create(:address)) }
|
||||
let(:d1) { create(:distributor_enterprise, address: create(:address)) }
|
||||
let(:d2) { create(:distributor_enterprise, address: create(:address)) }
|
||||
let(:d3) { create(:distributor_enterprise, address: create(:address)) }
|
||||
let(:c1) { create(:distributor_enterprise) }
|
||||
let(:c2) { create(:distributor_enterprise) }
|
||||
let(:s1) { create(:supplier_enterprise) }
|
||||
let(:s2) { create(:supplier_enterprise) }
|
||||
let(:s3) { create(:supplier_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
let(:d3) { create(:distributor_enterprise) }
|
||||
let(:p1) { create(:product, price: 12.34, distributors: [d1], supplier: s1) }
|
||||
let(:p2) { create(:product, price: 23.45, distributors: [d2], supplier: s2) }
|
||||
let(:p3) { create(:product, price: 34.56, distributors: [d3], supplier: s3) }
|
||||
|
||||
# Given two order cycles with both distributors
|
||||
let(:ocA) { create(:simple_order_cycle, distributors: [d1, d2], suppliers: [s1, s2, s3], variants: [p1.master, p3.master]) }
|
||||
let(:ocB) { create(:simple_order_cycle, distributors: [d1, d2], suppliers: [s1, s2, s3], variants: [p2.master]) }
|
||||
let(:ocA) { create(:simple_order_cycle, coordinator: c1, distributors: [d1, d2], suppliers: [s1, s2, s3], variants: [p1.master, p3.master]) }
|
||||
let(:ocB) { create(:simple_order_cycle, coordinator: c2, distributors: [d1, d2], suppliers: [s1, s2, s3], variants: [p2.master]) }
|
||||
|
||||
# orderA1 can only be accessed by s1, s3 and d1
|
||||
let!(:orderA1) do
|
||||
@@ -53,15 +55,29 @@ describe Spree::Admin::ReportsController do
|
||||
order.save
|
||||
order
|
||||
end
|
||||
|
||||
# As a Distributor Enterprise user for d1
|
||||
|
||||
# As manager of a coordinator (c1)
|
||||
context "Coordinator Enterprise User" do
|
||||
before { login_as_enterprise_user [c1] }
|
||||
|
||||
describe 'Orders & Fulfillment' do
|
||||
it "shows all orders in order cycles I coordinate" do
|
||||
spree_get :orders_and_fulfillment
|
||||
|
||||
assigns(:line_items).map(&:order).should include orderA1, orderA2
|
||||
assigns(:line_items).map(&:order).should_not include orderB1, orderB2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# As a Distributor Enterprise user for d1
|
||||
context "Distributor Enterprise User" do
|
||||
before { login_as_enterprise_user [d1] }
|
||||
|
||||
describe 'Orders and Distributors' do
|
||||
it "only shows orders that I have access to" do
|
||||
spree_get :orders_and_distributors
|
||||
|
||||
|
||||
assigns(:search).result.should include(orderA1, orderB1)
|
||||
assigns(:search).result.should_not include(orderA2)
|
||||
assigns(:search).result.should_not include(orderB2)
|
||||
@@ -71,7 +87,7 @@ describe Spree::Admin::ReportsController do
|
||||
describe 'Bulk Coop' do
|
||||
it "only shows orders that I have access to" do
|
||||
spree_get :bulk_coop
|
||||
|
||||
|
||||
assigns(:search).result.should include(orderA1, orderB1)
|
||||
assigns(:search).result.should_not include(orderA2)
|
||||
assigns(:search).result.should_not include(orderB2)
|
||||
@@ -81,7 +97,7 @@ describe Spree::Admin::ReportsController do
|
||||
describe 'Payments' do
|
||||
it "only shows orders that I have access to" do
|
||||
spree_get :payments
|
||||
|
||||
|
||||
assigns(:search).result.should include(orderA1, orderB1)
|
||||
assigns(:search).result.should_not include(orderA2)
|
||||
assigns(:search).result.should_not include(orderB2)
|
||||
@@ -89,12 +105,11 @@ describe Spree::Admin::ReportsController do
|
||||
end
|
||||
|
||||
describe 'Orders & Fulfillment' do
|
||||
it "only shows orders that I have access to" do
|
||||
it "only shows orders that I distribute" do
|
||||
spree_get :orders_and_fulfillment
|
||||
|
||||
assigns(:search).result.should include(orderA1, orderB1)
|
||||
assigns(:search).result.should_not include(orderA2)
|
||||
assigns(:search).result.should_not include(orderB2)
|
||||
assigns(:line_items).map(&:order).should include orderA1, orderB1
|
||||
assigns(:line_items).map(&:order).should_not include orderA2, orderB2
|
||||
end
|
||||
|
||||
it "only shows the selected order cycle" do
|
||||
@@ -114,19 +129,31 @@ describe Spree::Admin::ReportsController do
|
||||
it "only shows product line items that I am supplying" do
|
||||
spree_get :bulk_coop
|
||||
|
||||
assigns(:line_items).map(&:product).should include(p1)
|
||||
assigns(:line_items).map(&:product).should_not include(p2)
|
||||
assigns(:line_items).map(&:product).should_not include(p3)
|
||||
assigns(:line_items).map(&:product).should include p1
|
||||
assigns(:line_items).map(&:product).should_not include p2, p3
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Orders & Fulfillment' do
|
||||
it "only shows product line items that I am supplying" do
|
||||
spree_get :orders_and_fulfillment
|
||||
context "where I have granted P-OC to the distributor" do
|
||||
before do
|
||||
create(:enterprise_relationship, parent: s1, child: d1, permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
|
||||
assigns(:line_items).map(&:product).should include(p1)
|
||||
assigns(:line_items).map(&:product).should_not include(p2)
|
||||
assigns(:line_items).map(&:product).should_not include(p3)
|
||||
it "only shows product line items that I am supplying" do
|
||||
spree_get :orders_and_fulfillment
|
||||
|
||||
assigns(:line_items).map(&:product).should include p1
|
||||
assigns(:line_items).map(&:product).should_not include p2, p3
|
||||
end
|
||||
end
|
||||
|
||||
context "where I have not granted P-OC to the distributor" do
|
||||
it "does not show me line_items I supply" do
|
||||
spree_get :orders_and_fulfillment
|
||||
|
||||
assigns(:line_items).map(&:product).should_not include p1, p2, p3
|
||||
end
|
||||
end
|
||||
|
||||
it "only shows the selected order cycle" do
|
||||
@@ -143,17 +170,17 @@ describe Spree::Admin::ReportsController do
|
||||
|
||||
it "should build distributors for the current user" do
|
||||
spree_get :products_and_inventory
|
||||
assigns(:distributors).sort.should == [d1, d2, d3].sort
|
||||
assigns(:distributors).should match_array [c1, c2, d1, d2, d3]
|
||||
end
|
||||
|
||||
it "builds suppliers for the current user" do
|
||||
spree_get :products_and_inventory
|
||||
assigns(:suppliers).sort.should == [s1, s2, s3].sort
|
||||
assigns(:suppliers).should match_array [s1, s2, s3]
|
||||
end
|
||||
|
||||
it "builds order cycles for the current user" do
|
||||
spree_get :products_and_inventory
|
||||
assigns(:order_cycles).sort.should == [ocB, ocA].sort
|
||||
assigns(:order_cycles).should match_array [ocB, ocA]
|
||||
end
|
||||
|
||||
it "assigns report types" do
|
||||
@@ -184,17 +211,17 @@ describe Spree::Admin::ReportsController do
|
||||
|
||||
it "should build distributors for the current user" do
|
||||
spree_get :customers
|
||||
assigns(:distributors).sort.should == [d1, d2, d3].sort
|
||||
assigns(:distributors).should match_array [c1, c2, d1, d2, d3]
|
||||
end
|
||||
|
||||
it "builds suppliers for the current user" do
|
||||
spree_get :customers
|
||||
assigns(:suppliers).sort.should == [s1, s2, s3].sort
|
||||
assigns(:suppliers).should match_array [s1, s2, s3]
|
||||
end
|
||||
|
||||
it "builds order cycles for the current user" do
|
||||
spree_get :customers
|
||||
assigns(:order_cycles).sort.should == [ocB, ocA].sort
|
||||
assigns(:order_cycles).should match_array [ocB, ocA]
|
||||
end
|
||||
|
||||
it "assigns report types" do
|
||||
|
||||
@@ -30,7 +30,7 @@ module Spree
|
||||
|
||||
it "does not filter when no distributor or order cycle is specified" do
|
||||
spree_get :search, q: 'Prod'
|
||||
assigns(:variants).sort.should == [p1.master, p2.master].sort
|
||||
assigns(:variants).should match_array [p1.master, p2.master]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
32
spec/controllers/spree/api/line_items_controller_spec.rb
Normal file
32
spec/controllers/spree/api/line_items_controller_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Spree::Api::LineItemsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => current_api_user
|
||||
end
|
||||
|
||||
def self.make_simple_data!
|
||||
let!(:order) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now) }
|
||||
let!(:line_item) { FactoryGirl.create(:line_item, order: order, unit_value: 500) }
|
||||
end
|
||||
|
||||
#test that when a line item is updated, an order's fees are updated too
|
||||
context "as an admin user" do
|
||||
sign_in_as_admin!
|
||||
make_simple_data!
|
||||
|
||||
context "as a line item is updated" do
|
||||
it "update distribution charge on the order" do
|
||||
line_item_params = { order_id: order.number, id: line_item.id, line_item: { id: line_item.id, unit_value: 520 }, format: :json}
|
||||
allow(controller).to receive(:order) { order }
|
||||
expect(order).to receive(:update_distribution_charge!)
|
||||
spree_post :update, line_item_params
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,127 +3,6 @@ require 'spree/api/testing_support/helpers'
|
||||
|
||||
module Spree
|
||||
describe Spree::Api::OrdersController do
|
||||
include Spree::Api::TestingSupport::Helpers
|
||||
render_views
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Spree.user_class.stub :find_by_spree_api_key => current_api_user
|
||||
end
|
||||
|
||||
let(:order_attributes) { [:id, :full_name, :email, :phone, :completed_at, :line_items, :distributor, :order_cycle, :number] }
|
||||
|
||||
def self.make_simple_data!
|
||||
let!(:dist1) { FactoryGirl.create(:distributor_enterprise) }
|
||||
let!(:order1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:order2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:order3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: dist1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item, order: order1) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item, order: order2) }
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, order: order2) }
|
||||
let!(:line_item4) { FactoryGirl.create(:line_item, order: order3) }
|
||||
let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier, :units_product, :units_variant] }
|
||||
end
|
||||
|
||||
|
||||
context "as a normal user" do
|
||||
sign_in_as_user!
|
||||
make_simple_data!
|
||||
|
||||
it "should deny me access to managed orders" do
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
assert_unauthorized!
|
||||
end
|
||||
end
|
||||
|
||||
context "as an administrator" do
|
||||
sign_in_as_admin!
|
||||
make_simple_data!
|
||||
|
||||
before :each do
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders with appropriate attributes, including line items with appropriate attributes" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of line items with appropriate attributes" do
|
||||
li_keys = json_response.first['line_items'].first.keys.map{ |key| key.to_sym }
|
||||
line_item_attributes.all?{ |attr| li_keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts orders in ascending id order" do
|
||||
ids = json_response.map{ |order| order['id'] }
|
||||
ids[0].should < ids[1]
|
||||
ids[1].should < ids[2]
|
||||
end
|
||||
|
||||
it "formats completed_at to 'yyyy-mm-dd hh:mm'" do
|
||||
json_response.map{ |order| order['completed_at'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }.should == true
|
||||
end
|
||||
|
||||
it "returns an array for line_items" do
|
||||
json_response.map{ |order| order['line_items'] }.all?{ |a| a.is_a? Array }.should == true
|
||||
end
|
||||
|
||||
it "returns quantity and max quantity at integers" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['quantity'] }.all?{ |q| q.is_a? Fixnum }.should == true
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['max_quantity'] }.all?{ |mq| mq.nil? || mq.is_a?( Fixnum ) }.should == true
|
||||
end
|
||||
|
||||
it "returns supplier object with id and name keys" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |li| li['supplier'] }.all?{ |s| s.has_key?('id') && s.has_key?('name') }.should == true
|
||||
end
|
||||
|
||||
it "returns distributor object with id and name keys" do
|
||||
json_response.map{ |order| order['distributor'] }.all?{ |d| d.has_key?('id') && d.has_key?('name') }.should == true
|
||||
end
|
||||
|
||||
it "retrieves the order number" do
|
||||
json_response.map{ |order| order['number'] }.all?{ |number| number.match("^R\\d{5,10}$") }.should == true
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:distributor1) { create(:distributor_enterprise) }
|
||||
let(:distributor2) { create(:distributor_enterprise) }
|
||||
let!(:order1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: distributor1, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item1) { FactoryGirl.create(:line_item, order: order1, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
let!(:line_item2) { FactoryGirl.create(:line_item, order: order1, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
let!(:order2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: distributor2, billing_address: FactoryGirl.create(:address) ) }
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, order: order2, product: FactoryGirl.create(:product, supplier: supplier)) }
|
||||
|
||||
context "producer enterprise" do
|
||||
sign_in_as_enterprise_user! [:supplier]
|
||||
|
||||
before :each do
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "does not display line item for which my enteprise is a supplier" do
|
||||
response.status.should == 401
|
||||
end
|
||||
end
|
||||
|
||||
context "hub enterprise" do
|
||||
sign_in_as_enterprise_user! [:distributor1]
|
||||
|
||||
before :each do
|
||||
spree_get :managed, { :template => 'bulk_index', :format => :json }
|
||||
end
|
||||
|
||||
it "retrieves a list of orders" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "only displays line items from orders for which my enterprise is a distributor" do
|
||||
json_response.map{ |order| order['line_items'] }.flatten.map{ |line_item| line_item["id"] }.should == [line_item1.id, line_item2.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,6 @@ module Spree
|
||||
let!(:product3) { FactoryGirl.create(:product, supplier: supplier) }
|
||||
let(:product_other_supplier) { FactoryGirl.create(:product, supplier: supplier2) }
|
||||
let(:attributes) { [:id, :name, :supplier, :price, :on_hand, :available_on, :permalink_live] }
|
||||
let(:unit_attributes) { [:id, :name, :group_buy_unit_size, :variant_unit] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
@@ -72,12 +71,6 @@ module Spree
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of products with attributes relating to units" do
|
||||
spree_get :show, { :id => product1.id, :template => "units_show", :format => :json }
|
||||
keys = json_response.keys.map{ |key| key.to_sym }
|
||||
unit_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts products in ascending id order" do
|
||||
spree_get :index, { :template => 'bulk_index', :format => :json }
|
||||
ids = json_response.map{ |product| product['id'] }
|
||||
|
||||
@@ -9,7 +9,6 @@ module Spree
|
||||
let!(:variant2) { FactoryGirl.create(:variant) }
|
||||
let!(:variant3) { FactoryGirl.create(:variant) }
|
||||
let(:attributes) { [:id, :options_text, :price, :on_hand, :unit_value, :unit_description, :on_demand, :display_as, :display_name] }
|
||||
let(:unit_attributes) { [:id, :unit_text, :unit_value] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
@@ -25,12 +24,6 @@ module Spree
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of variants with attributes relating to units" do
|
||||
spree_get :show, { :id => variant1.id, :template => "units_show", :format => :json }
|
||||
keys = json_response.keys.map{ |key| key.to_sym }
|
||||
unit_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "is denied access when trying to delete a variant" do
|
||||
product = create(:product)
|
||||
variant = product.master
|
||||
|
||||
@@ -183,6 +183,10 @@ FactoryGirl.define do
|
||||
end
|
||||
end
|
||||
|
||||
factory :order_with_distributor, :parent => :order do
|
||||
distributor { create(:distributor_enterprise) }
|
||||
end
|
||||
|
||||
factory :zone_with_member, :parent => :zone do
|
||||
default_tax true
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ feature %q{
|
||||
end
|
||||
|
||||
context "displaying the list of line items" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'address', completed_at: nil ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order_with_distributor, state: 'address', completed_at: nil ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3 ) }
|
||||
@@ -41,8 +41,8 @@ feature %q{
|
||||
end
|
||||
|
||||
context "displaying individual columns" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, bill_address: FactoryGirl.create(:address) ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, bill_address: nil ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, bill_address: FactoryGirl.create(:address) ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, bill_address: nil ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2, product: FactoryGirl.create(:product_with_option_types) ) }
|
||||
|
||||
@@ -57,7 +57,7 @@ feature %q{
|
||||
end
|
||||
|
||||
it "displays a column for order date" do
|
||||
page.should have_selector "th,date", text: "ORDER DATE", :visible => true
|
||||
page.should have_selector "th.date", text: "ORDER DATE", :visible => true
|
||||
page.should have_selector "td.date", text: o1.completed_at.strftime("%F %T"), :visible => true
|
||||
page.should have_selector "td.date", text: o2.completed_at.strftime("%F %T"), :visible => true
|
||||
end
|
||||
@@ -94,7 +94,7 @@ feature %q{
|
||||
end
|
||||
|
||||
context "tracking changes" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, :quantity => 5 ) }
|
||||
|
||||
before :each do
|
||||
@@ -117,7 +117,7 @@ feature %q{
|
||||
end
|
||||
|
||||
context "submitting data to the server" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, :quantity => 5 ) }
|
||||
|
||||
before :each do
|
||||
@@ -141,8 +141,22 @@ feature %q{
|
||||
admin_user = quick_login_as_admin
|
||||
end
|
||||
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, :quantity => 5 ) }
|
||||
let!(:p1) { FactoryGirl.create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [FactoryGirl.create(:variant, unit_value: 1000)] ) }
|
||||
let!(:v1) { p1.variants.first }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, variant: v1, :quantity => 5, :unit_value => 1000 ) }
|
||||
|
||||
context "modifying the weight/volume of a line item" do
|
||||
it "update-pending is added to variable 'price'" do
|
||||
visit '/admin/orders/bulk_management'
|
||||
first("div#columns_dropdown", :text => "COLUMNS").click
|
||||
first("div#columns_dropdown div.menu div.menu_item", text: "Weight/Volume").click
|
||||
page.should_not have_css "input[name='price'].update-pending"
|
||||
li1_unit_value_column = find("tr#li_#{li1.id} td.unit_value")
|
||||
li1_unit_value_column.fill_in "unit_value", :with => 1200
|
||||
page.should have_css "input[name='price'].update-pending", :visible => false
|
||||
end
|
||||
end
|
||||
|
||||
context "using column display toggle" do
|
||||
it "shows a column display toggle button, which shows a list of columns when clicked" do
|
||||
@@ -171,7 +185,7 @@ feature %q{
|
||||
context "supplier filter" do
|
||||
let!(:s1) { create(:supplier_enterprise) }
|
||||
let!(:s2) { create(:supplier_enterprise) }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, product: create(:product, supplier: s1) ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o1, product: create(:product, supplier: s2) ) }
|
||||
|
||||
@@ -205,8 +219,8 @@ feature %q{
|
||||
context "distributor filter" do
|
||||
let!(:d1) { create(:distributor_enterprise) }
|
||||
let!(:d2) { create(:distributor_enterprise) }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d2 ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d2 ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
|
||||
@@ -238,10 +252,11 @@ feature %q{
|
||||
end
|
||||
|
||||
context "order_cycle filter" do
|
||||
let!(:oc1) { FactoryGirl.create(:simple_order_cycle ) }
|
||||
let!(:oc2) { FactoryGirl.create(:simple_order_cycle ) }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, order_cycle: oc1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, order_cycle: oc2 ) }
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:oc1) { FactoryGirl.create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let!(:oc2) { FactoryGirl.create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, order_cycle: oc1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, order_cycle: oc2 ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
|
||||
@@ -255,20 +270,22 @@ feature %q{
|
||||
find("div.select2-container#s2id_order_cycle_filter").click
|
||||
order_cycle_names.each { |ocn| page.should have_selector "div.select2-drop-active ul.select2-results li", text: ocn }
|
||||
find("div.select2-container#s2id_order_cycle_filter").click
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li1.id}"
|
||||
page.should have_selector "tr#li_#{li2.id}"
|
||||
select2_select oc1.name, from: "order_cycle_filter"
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should_not have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should have_selector "#loading img.spinner"
|
||||
page.should_not have_selector "#loading img.spinner"
|
||||
page.should have_selector "tr#li_#{li1.id}"
|
||||
page.should_not have_selector "tr#li_#{li2.id}"
|
||||
end
|
||||
|
||||
it "displays all line items when 'All' is selected from order_cycle filter" do
|
||||
select2_select oc1.name, from: "order_cycle_filter"
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should_not have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li1.id}"
|
||||
page.should_not have_selector "tr#li_#{li2.id}"
|
||||
select2_select "All", from: "order_cycle_filter"
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li1.id}"
|
||||
page.should have_selector "tr#li_#{li2.id}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -281,8 +298,8 @@ feature %q{
|
||||
let!(:oc2) { FactoryGirl.create(:simple_order_cycle, suppliers: [s2], distributors: [d2] ) }
|
||||
let!(:p1) { FactoryGirl.create(:product, supplier: s1) }
|
||||
let!(:p2) { FactoryGirl.create(:product, supplier: s2) }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d1, order_cycle: oc1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d2, order_cycle: oc2 ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d1, order_cycle: oc1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d2, order_cycle: oc2 ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, product: p1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2, product: p2 ) }
|
||||
|
||||
@@ -325,9 +342,9 @@ feature %q{
|
||||
end
|
||||
|
||||
context "using quick search" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3 ) }
|
||||
@@ -352,9 +369,9 @@ feature %q{
|
||||
end
|
||||
|
||||
context "using date restriction controls" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: (Date.today - 8).strftime("%F %T") ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: (Date.today + 2).strftime("%F %T") ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: (Date.today - 8).strftime("%F %T") ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: (Date.today + 2).strftime("%F %T") ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1, :quantity => 1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2, :quantity => 2 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3, :quantity => 3 ) }
|
||||
@@ -426,8 +443,8 @@ feature %q{
|
||||
end
|
||||
|
||||
context "bulk action controls" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
|
||||
@@ -493,8 +510,8 @@ feature %q{
|
||||
|
||||
context "using action buttons" do
|
||||
context "using edit buttons" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
|
||||
@@ -512,8 +529,8 @@ feature %q{
|
||||
end
|
||||
|
||||
context "using delete buttons" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
|
||||
@@ -536,13 +553,13 @@ feature %q{
|
||||
end
|
||||
|
||||
context "clicking the link on variant name" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
let!(:p3) { FactoryGirl.create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [FactoryGirl.create(:variant, unit_value: 1000)] ) }
|
||||
let!(:v3) { p3.variants.first }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3, variant: v3, quantity: 3, max_quantity: 6 ) }
|
||||
let!(:li4) { FactoryGirl.create(:line_item, order: o2, variant: v3, quantity: 1, max_quantity: 3 ) }
|
||||
|
||||
@@ -602,8 +619,8 @@ feature %q{
|
||||
let(:s1) { create(:supplier_enterprise, name: 'First Supplier') }
|
||||
let(:d1) { create(:distributor_enterprise, name: 'First Distributor') }
|
||||
let(:d2) { create(:distributor_enterprise, name: 'Another Distributor') }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now, distributor: d2 ) }
|
||||
let!(:o1) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d1 ) }
|
||||
let!(:o2) { FactoryGirl.create(:order_with_distributor, state: 'complete', completed_at: Time.now, distributor: d2 ) }
|
||||
let!(:line_item_distributed) { FactoryGirl.create(:line_item, order: o1, product: create(:product, supplier: s1) ) }
|
||||
let!(:line_item_not_distributed) { FactoryGirl.create(:line_item, order: o2, product: create(:product, supplier: s1) ) }
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ feature %q{
|
||||
eg.name.should == 'EGEGEG'
|
||||
eg.description.should == 'This is a description'
|
||||
eg.on_front_page.should be_true
|
||||
eg.enterprises.sort.should == [e1, e2].sort
|
||||
eg.enterprises.should match_array [e1, e2]
|
||||
end
|
||||
|
||||
scenario "editing an enterprise group" do
|
||||
|
||||
@@ -50,7 +50,7 @@ feature %q{
|
||||
page.should have_relationship e1, e2, ['to add to order cycle', 'to override variant details', 'to edit profile']
|
||||
er = EnterpriseRelationship.where(parent_id: e1, child_id: e2).first
|
||||
er.should be_present
|
||||
er.permissions.map(&:name).sort.should == ['add_to_order_cycle', 'edit_profile', 'create_variant_overrides'].sort
|
||||
er.permissions.map(&:name).should match_array ['add_to_order_cycle', 'edit_profile', 'create_variant_overrides']
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ feature %q{
|
||||
page.should have_selector 'td.distributors', text: 'My distributor'
|
||||
|
||||
# And my coordinator fees should have been configured
|
||||
OrderCycle.last.coordinator_fee_ids.sort.should == [coordinator_fee1.id, coordinator_fee2.id].sort
|
||||
OrderCycle.last.coordinator_fee_ids.should match_array [coordinator_fee1.id, coordinator_fee2.id]
|
||||
|
||||
# And my supplier fees should have been configured
|
||||
OrderCycle.last.exchanges.incoming.last.enterprise_fee_ids.should == [supplier_fee2.id]
|
||||
@@ -364,7 +364,7 @@ feature %q{
|
||||
|
||||
# And it should have some variants selected
|
||||
selected_initial_variants = initial_variants.take initial_variants.size - 1
|
||||
OrderCycle.last.variants.map(&:id).sort.should == (selected_initial_variants.map(&:id) + [v1.id, v2.id]).sort
|
||||
OrderCycle.last.variants.map(&:id).should match_array (selected_initial_variants.map(&:id) + [v1.id, v2.id])
|
||||
|
||||
# And the collection details should have been updated
|
||||
OrderCycle.last.exchanges.where(pickup_time: 'New time 0', pickup_instructions: 'New instructions 0').should be_present
|
||||
@@ -568,9 +568,9 @@ feature %q{
|
||||
|
||||
flash_message.should == "Your order cycle has been created."
|
||||
order_cycle = OrderCycle.find_by_name('My order cycle')
|
||||
order_cycle.suppliers.sort.should == [supplier_managed, supplier_permitted].sort
|
||||
order_cycle.suppliers.should match_array [supplier_managed, supplier_permitted]
|
||||
order_cycle.coordinator.should == distributor_managed
|
||||
order_cycle.distributors.sort.should == [distributor_managed, distributor_permitted].sort
|
||||
order_cycle.distributors.should match_array [distributor_managed, distributor_permitted]
|
||||
end
|
||||
|
||||
scenario "editing an order cycle we can see (and for now, edit) all exchanges in the order cycle" do
|
||||
@@ -592,9 +592,9 @@ feature %q{
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.sort.should == [supplier_managed, supplier_permitted, supplier_unmanaged].sort
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
oc.distributors.sort.should == [distributor_managed, distributor_permitted, distributor_unmanaged].sort
|
||||
oc.distributors.should match_array [distributor_managed, distributor_permitted, distributor_unmanaged]
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
@@ -683,9 +683,9 @@ feature %q{
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.sort.should == [supplier_managed, supplier_permitted, supplier_unmanaged].sort
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
oc.distributors.sort.should == [distributor_managed, distributor_permitted, distributor_unmanaged].sort
|
||||
oc.distributors.should match_array [distributor_managed, distributor_permitted, distributor_unmanaged]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -736,9 +736,9 @@ feature %q{
|
||||
page.should have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
oc.suppliers.sort.should == [supplier_managed, supplier_permitted, supplier_unmanaged].sort
|
||||
oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
oc.coordinator.should == distributor_managed
|
||||
oc.distributors.sort.should == [my_distributor, distributor_managed, distributor_permitted, distributor_unmanaged].sort
|
||||
oc.distributors.should match_array [my_distributor, distributor_managed, distributor_permitted, distributor_unmanaged]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,10 +68,10 @@ feature %q{
|
||||
click_button 'Update'
|
||||
|
||||
product.reload
|
||||
product.distributors.sort.should == [@distributors[0], @distributors[2]].sort
|
||||
product.distributors.should match_array [@distributors[0], @distributors[2]]
|
||||
|
||||
|
||||
product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort
|
||||
product.product_distributions.map { |pd| pd.enterprise_fee }.should match_array [@enterprise_fees[0], @enterprise_fees[2]]
|
||||
end
|
||||
|
||||
scenario "making a product into a group buy product" do
|
||||
|
||||
@@ -211,8 +211,9 @@ feature %q{
|
||||
end
|
||||
|
||||
it "handles order cycles with nil opening or closing times" do
|
||||
oc = create(:simple_order_cycle, name: "My Order Cycle", orders_open_at: Time.now, orders_close_at: nil)
|
||||
o = create(:order, order_cycle: oc)
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: "My Order Cycle", distributors: [distributor], orders_open_at: Time.now, orders_close_at: nil)
|
||||
o = create(:order, order_cycle: oc, distributor: distributor)
|
||||
|
||||
login_to_admin_section
|
||||
visit spree.orders_and_fulfillment_admin_reports_path
|
||||
|
||||
@@ -36,7 +36,7 @@ feature 'shipping methods' do
|
||||
|
||||
sm = Spree::ShippingMethod.last
|
||||
sm.name.should == 'Carrier Pidgeon'
|
||||
sm.distributors.sort.should == [d1, d2].sort
|
||||
sm.distributors.should match_array [d1, d2]
|
||||
end
|
||||
|
||||
it "at checkout, user can only see shipping methods for their current distributor (checkout spec)"
|
||||
|
||||
@@ -22,8 +22,8 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
returnedOrderCycles = [ "oc1", "oc2", "oc3" ]
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_distributor_eq]=true").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/accessible").respond returnedOrderCycles
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[sells_in][]=own&q[sells_in][]=any").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/accessible?as=distributor&q[orders_close_at_gt]=SomeDate").respond returnedOrderCycles
|
||||
spyOn(scope, "initialiseVariables").andCallThrough()
|
||||
spyOn(scope, "fetchOrders").andReturn "nothing"
|
||||
#spyOn(returnedSuppliers, "unshift")
|
||||
@@ -33,8 +33,8 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
httpBackend.flush()
|
||||
|
||||
expect(scope.suppliers).toEqual [{ id : '0', name : 'All' }, 'list of suppliers']
|
||||
expect(scope.distributors).toEqual [ { id : '0', name : 'All' }, 'list of distributors' ]
|
||||
expect(scope.orderCycles).toEqual [ { id : '0', name : 'All' }, 'oc1', 'oc2', 'oc3' ]
|
||||
expect(scope.distributors).toEqual [ { id : '0', name : 'All' }, 'list of distributors' ]
|
||||
expect(scope.orderCycles).toEqual [ { id : '0', name : 'All' }, 'oc1', 'oc2', 'oc3' ]
|
||||
|
||||
expect(scope.initialiseVariables.calls.length).toBe 1
|
||||
expect(scope.fetchOrders.calls.length).toBe 1
|
||||
@@ -43,7 +43,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
describe "fetching orders", ->
|
||||
beforeEach ->
|
||||
scope.initialiseVariables()
|
||||
httpBackend.expectGET("/api/orders/managed?template=bulk_index;page=1;per_page=500;q[completed_at_not_null]=true;q[completed_at_gt]=SomeDate;q[completed_at_lt]=SomeDate").respond "list of orders"
|
||||
httpBackend.expectGET("/admin/orders/managed?template=bulk_index;page=1;per_page=500;q[state_not_eq]=canceled;q[completed_at_not_null]=true;q[completed_at_gt]=SomeDate;q[completed_at_lt]=SomeDate").respond "list of orders"
|
||||
|
||||
it "makes a call to dataFetcher, with current start and end date parameters", ->
|
||||
scope.fetchOrders()
|
||||
@@ -350,6 +350,33 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
spyOn(VariantUnitManager, "getUnitName").andReturn "kg"
|
||||
expect(scope.formattedValueWithUnitName(2000,unitsVariant)).toEqual "2 kg"
|
||||
|
||||
describe "updating the price upon updating the weight of a line item", ->
|
||||
|
||||
it "resets the weight if the weight is set to zero", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 0 }
|
||||
]
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], 100)).toEqual scope.filteredLineItems[0].price
|
||||
|
||||
it "updates the price if the weight is changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 200 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].units_variant.unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
sp = scope.filteredLineItems[0].price * new_value / old_value
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
it "doesn't update the price if the weight is not changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 100 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
sp = scope.filteredLineItems[0].price
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
|
||||
describe "managing pending changes", ->
|
||||
dataSubmitter = pendingChangesService = null
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
module OpenFoodNetwork
|
||||
describe CustomersReport do
|
||||
context "as a site admin" do
|
||||
let(:user) do
|
||||
let(:user) do
|
||||
user = create(:user)
|
||||
user.spree_roles << Spree::Role.find_or_create_by_name!("admin")
|
||||
user
|
||||
@@ -44,14 +44,14 @@ module OpenFoodNetwork
|
||||
it "builds a table from a list of variants" do
|
||||
a = create(:address)
|
||||
d = create(:distributor_enterprise)
|
||||
o = create(:order, distributor: d, bill_address: a)
|
||||
o = create(:order, distributor: d, bill_address: a)
|
||||
o.shipping_method = create(:shipping_method)
|
||||
|
||||
subject.stub(:orders).and_return [o]
|
||||
subject.table.should == [[
|
||||
a.firstname, a.lastname,
|
||||
[a.address1, a.address2, a.city].join(" "),
|
||||
o.email, a.phone, d.name,
|
||||
a.firstname, a.lastname,
|
||||
[a.address1, a.address2, a.city].join(" "),
|
||||
o.email, a.phone, d.name,
|
||||
[d.address.address1, d.address.address2, d.address.city].join(" "),
|
||||
o.shipping_method.name
|
||||
]]
|
||||
@@ -74,7 +74,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
context "as an enterprise user" do
|
||||
let(:user) do
|
||||
let(:user) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
user.save!
|
||||
@@ -131,7 +131,7 @@ module OpenFoodNetwork
|
||||
order2.line_items << create(:line_item, product: product2)
|
||||
|
||||
subject.stub(:params).and_return(supplier_id: supplier.id)
|
||||
subject.filter(orders).sort.should == [order1]
|
||||
subject.filter(orders).should == [order1]
|
||||
end
|
||||
|
||||
it "filters to a specific distributor" do
|
||||
@@ -141,7 +141,7 @@ module OpenFoodNetwork
|
||||
order2 = create(:order, distributor: d2)
|
||||
|
||||
subject.stub(:params).and_return(distributor_id: d1.id)
|
||||
subject.filter(orders).sort.should == [order1]
|
||||
subject.filter(orders).should == [order1]
|
||||
end
|
||||
|
||||
it "filters to a specific cycle" do
|
||||
@@ -151,7 +151,7 @@ module OpenFoodNetwork
|
||||
order2 = create(:order, order_cycle: oc2)
|
||||
|
||||
subject.stub(:params).and_return(order_cycle_id: oc1.id)
|
||||
subject.filter(orders).sort.should == [order1]
|
||||
subject.filter(orders).should == [order1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -300,8 +300,8 @@ module OpenFoodNetwork
|
||||
expect(exchange.sender).to eq sender
|
||||
expect(exchange.receiver).to eq receiver
|
||||
expect(exchange.incoming).to eq incoming
|
||||
expect(exchange.variants.sort).to eq [variant1, variant2].sort
|
||||
expect(exchange.enterprise_fees.sort).to eq [enterprise_fee1, enterprise_fee2].sort
|
||||
expect(exchange.variants).to match_array [variant1, variant2]
|
||||
expect(exchange.enterprise_fees).to match_array [enterprise_fee1, enterprise_fee2]
|
||||
|
||||
applicator.send(:touched_exchanges).should == [exchange]
|
||||
end
|
||||
@@ -345,8 +345,8 @@ module OpenFoodNetwork
|
||||
|
||||
it "updates the variants, enterprise fees and pickup information of the exchange" do
|
||||
exchange.reload
|
||||
expect(exchange.variants.sort).to eq [variant1, variant3].sort
|
||||
expect(exchange.enterprise_fees.sort).to eq [enterprise_fee2, enterprise_fee3]
|
||||
expect(exchange.variants).to match_array [variant1, variant3]
|
||||
expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3]
|
||||
expect(exchange.pickup_time).to eq 'New Pickup Time'
|
||||
expect(exchange.pickup_instructions).to eq 'New Pickup Instructions'
|
||||
expect(applicator.send(:touched_exchanges)).to eq [exchange]
|
||||
@@ -364,8 +364,8 @@ module OpenFoodNetwork
|
||||
|
||||
it "updates the variants, enterprise fees and pickup information of the exchange" do
|
||||
exchange.reload
|
||||
expect(exchange.variants.sort).to eq [variant1, variant3].sort
|
||||
expect(exchange.enterprise_fees.sort).to eq [enterprise_fee2, enterprise_fee3]
|
||||
expect(exchange.variants).to match_array [variant1, variant3]
|
||||
expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3]
|
||||
expect(exchange.pickup_time).to eq 'New Pickup Time'
|
||||
expect(exchange.pickup_instructions).to eq 'New Pickup Instructions'
|
||||
expect(applicator.send(:touched_exchanges)).to eq [exchange]
|
||||
@@ -383,8 +383,8 @@ module OpenFoodNetwork
|
||||
|
||||
it "updates the variants in the exchange, but not the fees or pickup information" do
|
||||
exchange.reload
|
||||
expect(exchange.variants.sort).to eq [variant1, variant3].sort
|
||||
expect(exchange.enterprise_fees.sort).to eq [enterprise_fee1, enterprise_fee2]
|
||||
expect(exchange.variants).to match_array [variant1, variant3]
|
||||
expect(exchange.enterprise_fees).to match_array [enterprise_fee1, enterprise_fee2]
|
||||
expect(exchange.pickup_time).to_not eq 'New Pickup Time'
|
||||
expect(exchange.pickup_instructions).to_not eq 'New Pickup Instructions'
|
||||
expect(applicator.send(:touched_exchanges)).to eq [exchange]
|
||||
|
||||
@@ -8,16 +8,71 @@ module OpenFoodNetwork
|
||||
let(:e1) { create(:enterprise) }
|
||||
let(:e2) { create(:enterprise) }
|
||||
|
||||
describe "finding managed and related enterprises granting a particular permission" do
|
||||
describe "as super admin" do
|
||||
before { allow(user).to receive(:admin?) { true } }
|
||||
|
||||
it "returns all enterprises" do
|
||||
expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "as an enterprise user" do
|
||||
let(:e3) { create(:enterprise) }
|
||||
before { allow(user).to receive(:admin?) { false } }
|
||||
|
||||
it "returns only my managed enterprises any that have granting them P-OC" do
|
||||
expect(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e1) }
|
||||
expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) { Enterprise.where(id: e3) }
|
||||
expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e3]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding managed and related enterprises granting or granted a particular permission" do
|
||||
describe "as super admin" do
|
||||
before { allow(user).to receive(:admin?) { true } }
|
||||
|
||||
it "returns all enterprises" do
|
||||
expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "as an enterprise user" do
|
||||
let(:e3) { create(:enterprise) }
|
||||
let(:e4) { create(:enterprise) }
|
||||
before { allow(user).to receive(:admin?) { false } }
|
||||
|
||||
it "returns only my managed enterprises any that have granting them P-OC" do
|
||||
expect(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e1) }
|
||||
expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) { Enterprise.where(id: e3) }
|
||||
expect(permissions).to receive(:related_enterprises_granted).with(:some_permission) { Enterprise.where(id: e4) }
|
||||
expect(permissions.send(:managed_and_related_enterprises_with, :some_permission)).to match_array [e1, e3, e4]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding enterprises that can be selected in order report filters" do
|
||||
let(:e) { double(:enterprise) }
|
||||
|
||||
it "returns managed and related enterprises with add_to_order_cycle permission" do
|
||||
expect(permissions).to receive(:managed_and_related_enterprises_with).
|
||||
with(:add_to_order_cycle).
|
||||
and_return([e])
|
||||
|
||||
expect(permissions.visible_enterprises_for_order_reports).to eq [e]
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding enterprises that can be added to an order cycle" do
|
||||
let(:e) { double(:enterprise) }
|
||||
|
||||
it "returns managed and related enterprises with add_to_order_cycle permission" do
|
||||
permissions.
|
||||
should_receive(:managed_and_related_enterprises_with).
|
||||
expect(permissions).to receive(:managed_and_related_enterprises_granting).
|
||||
with(:add_to_order_cycle).
|
||||
and_return([e])
|
||||
|
||||
permissions.order_cycle_enterprises.should == [e]
|
||||
expect(permissions.order_cycle_enterprises).to eq [e]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +81,7 @@ module OpenFoodNetwork
|
||||
|
||||
it "returns managed and related enterprises with edit_profile permission" do
|
||||
permissions.
|
||||
should_receive(:managed_and_related_enterprises_with).
|
||||
should_receive(:managed_and_related_enterprises_granting).
|
||||
with(:edit_profile).
|
||||
and_return([e])
|
||||
|
||||
@@ -43,7 +98,7 @@ module OpenFoodNetwork
|
||||
{1 => [e1.id], 2 => [e1.id, e2.id]}
|
||||
end
|
||||
|
||||
permissions.variant_override_producers.sort.should == [e1, e2].sort
|
||||
permissions.variant_override_producers.should match_array [e1, e2]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,6 +110,7 @@ module OpenFoodNetwork
|
||||
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: hub.id) }
|
||||
permissions.stub(:admin?) { false }
|
||||
end
|
||||
|
||||
it "returns enterprises as hub_id => [producer, ...]" do
|
||||
@@ -108,23 +164,53 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding managed products" do
|
||||
let!(:p1) { create(:simple_product) }
|
||||
let!(:p2) { create(:simple_product) }
|
||||
describe "finding editable products" do
|
||||
let!(:p1) { create(:simple_product, supplier: create(:supplier_enterprise) ) }
|
||||
let!(:p2) { create(:simple_product, supplier: create(:supplier_enterprise) ) }
|
||||
|
||||
before do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where('1=0') }
|
||||
permissions.stub(:related_enterprise_products) { Spree::Product.where('1=0') }
|
||||
allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0") }
|
||||
end
|
||||
|
||||
it "returns products produced by managed enterprises" do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where(id: p1) }
|
||||
permissions.managed_products.should == [p1]
|
||||
permissions.editable_products.should == [p1]
|
||||
end
|
||||
|
||||
it "returns products produced by permitted enterprises" do
|
||||
permissions.stub(:related_enterprise_products) { Spree::Product.where(id: p2) }
|
||||
permissions.managed_products.should == [p2]
|
||||
allow(permissions).to receive(:related_enterprises_granting).
|
||||
with(:manage_products) { Enterprise.where(id: p2.supplier) }
|
||||
permissions.editable_products.should == [p2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding visible products" do
|
||||
let!(:p1) { create(:simple_product, supplier: create(:supplier_enterprise) ) }
|
||||
let!(:p2) { create(:simple_product, supplier: create(:supplier_enterprise) ) }
|
||||
let!(:p3) { create(:simple_product, supplier: create(:supplier_enterprise) ) }
|
||||
|
||||
before do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where("1=0") }
|
||||
allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0") }
|
||||
allow(permissions).to receive(:related_enterprises_granting).with(:add_to_order_cycle) { Enterprise.where("1=0") }
|
||||
end
|
||||
|
||||
it "returns products produced by managed enterprises" do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where(id: p1) }
|
||||
permissions.visible_products.should == [p1]
|
||||
end
|
||||
|
||||
it "returns products produced by enterprises that have granted manage products" do
|
||||
allow(permissions).to receive(:related_enterprises_granting).
|
||||
with(:manage_products) { Enterprise.where(id: p2.supplier) }
|
||||
permissions.visible_products.should == [p2]
|
||||
end
|
||||
|
||||
it "returns products produced by enterprises that have granted P-OC" do
|
||||
allow(permissions).to receive(:related_enterprises_granting).
|
||||
with(:add_to_order_cycle) { Enterprise.where(id: p3.supplier) }
|
||||
permissions.visible_products.should == [p3]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,7 +219,7 @@ module OpenFoodNetwork
|
||||
|
||||
it "returns managed and related enterprises with manage_products permission" do
|
||||
permissions.
|
||||
should_receive(:managed_and_related_enterprises_with).
|
||||
should_receive(:managed_and_related_enterprises_granting).
|
||||
with(:manage_products).
|
||||
and_return([e])
|
||||
|
||||
@@ -148,41 +234,162 @@ module OpenFoodNetwork
|
||||
|
||||
it "returns the enterprises" do
|
||||
permissions.stub(:managed_enterprises) { e2 }
|
||||
permissions.send(:related_enterprises_with, permission).should == [e1]
|
||||
permissions.send(:related_enterprises_granting, permission).should == [e1]
|
||||
end
|
||||
|
||||
it "returns an empty array when there are none" do
|
||||
permissions.stub(:managed_enterprises) { e1 }
|
||||
permissions.send(:related_enterprises_with, permission).should == []
|
||||
permissions.send(:related_enterprises_granting, permission).should == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding enterprises that are managed or with a particular permission" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where('1=0') }
|
||||
permissions.stub(:related_enterprises_with) { Enterprise.where('1=0') }
|
||||
permissions.stub(:related_enterprises_granting) { Enterprise.where('1=0') }
|
||||
permissions.stub(:admin?) { false }
|
||||
end
|
||||
|
||||
it "returns managed enterprises" do
|
||||
permissions.should_receive(:managed_enterprises) { Enterprise.where(id: e1) }
|
||||
permissions.send(:managed_and_related_enterprises_with, permission).should == [e1]
|
||||
permissions.send(:managed_and_related_enterprises_granting, permission).should == [e1]
|
||||
end
|
||||
|
||||
it "returns permitted enterprises" do
|
||||
permissions.should_receive(:related_enterprises_with).with(permission).
|
||||
permissions.should_receive(:related_enterprises_granting).with(permission).
|
||||
and_return(Enterprise.where(id: e2))
|
||||
permissions.send(:managed_and_related_enterprises_with, permission).should == [e2]
|
||||
permissions.send(:managed_and_related_enterprises_granting, permission).should == [e2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding the supplied products of related enterprises" do
|
||||
let!(:e) { create(:enterprise) }
|
||||
let!(:p) { create(:simple_product, supplier: e) }
|
||||
describe "finding orders that are visible in reports" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:random_enterprise) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor]) }
|
||||
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor ) }
|
||||
let!(:line_item) { create(:line_item, order: order) }
|
||||
let!(:producer) { create(:supplier_enterprise) }
|
||||
|
||||
it "returns supplied products" do
|
||||
permissions.should_receive(:related_enterprises_with).with(:manage_products) { [e] }
|
||||
before do
|
||||
permissions.stub(:coordinated_order_cycles) { Enterprise.where("1=0") }
|
||||
end
|
||||
|
||||
permissions.send(:related_enterprise_products).should == [p]
|
||||
context "as the hub through which the order was placed" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: distributor) }
|
||||
end
|
||||
|
||||
it "should let me see the order" do
|
||||
expect(permissions.visible_orders).to include order
|
||||
end
|
||||
end
|
||||
|
||||
context "as the coordinator of the order cycle through which the order was placed" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: coordinator) }
|
||||
permissions.stub(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) }
|
||||
end
|
||||
|
||||
it "should let me see the order" do
|
||||
expect(permissions.visible_orders).to include order
|
||||
end
|
||||
end
|
||||
|
||||
context "as a producer which has granted P-OC to the distributor of an order" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: producer) }
|
||||
create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
|
||||
context "which contains my products" do
|
||||
before do
|
||||
line_item.product.supplier = producer
|
||||
line_item.product.save
|
||||
end
|
||||
|
||||
it "should let me see the order" do
|
||||
expect(permissions.visible_orders).to include order
|
||||
end
|
||||
end
|
||||
|
||||
context "which does not contain my products" do
|
||||
it "should not let me see the order" do
|
||||
expect(permissions.visible_orders).to_not include order
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise that is a distributor in the order cycle, but not the distributor of the order" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: random_enterprise) }
|
||||
end
|
||||
|
||||
it "should not let me see the order" do
|
||||
expect(permissions.visible_orders).to_not include order
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding line items that are visible in reports" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:coordinator) { create(:distributor_enterprise) }
|
||||
let(:random_enterprise) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor]) }
|
||||
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor ) }
|
||||
let!(:line_item1) { create(:line_item, order: order) }
|
||||
let!(:line_item2) { create(:line_item, order: order) }
|
||||
let!(:producer) { create(:supplier_enterprise) }
|
||||
|
||||
before do
|
||||
permissions.stub(:coordinated_order_cycles) { Enterprise.where("1=0") }
|
||||
end
|
||||
|
||||
context "as the hub through which the parent order was placed" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: distributor) }
|
||||
end
|
||||
|
||||
it "should let me see the line_items" do
|
||||
expect(permissions.visible_line_items).to include line_item1, line_item2
|
||||
end
|
||||
end
|
||||
|
||||
context "as the coordinator of the order cycle through which the parent order was placed" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: coordinator) }
|
||||
permissions.stub(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) }
|
||||
end
|
||||
|
||||
it "should let me see the line_items" do
|
||||
expect(permissions.visible_line_items).to include line_item1, line_item2
|
||||
end
|
||||
end
|
||||
|
||||
context "as the manager producer which has granted P-OC to the distributor of the parent order" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: producer) }
|
||||
create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle])
|
||||
|
||||
line_item1.product.supplier = producer
|
||||
line_item1.product.save
|
||||
end
|
||||
|
||||
it "should let me see the line_items pertaining to variants I produce" do
|
||||
ps = permissions.visible_line_items
|
||||
expect(ps).to include line_item1
|
||||
expect(ps).to_not include line_item2
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise that is a distributor in the order cycle, but not the distributor of the parent order" do
|
||||
before do
|
||||
permissions.stub(:managed_enterprises) { Enterprise.where(id: random_enterprise) }
|
||||
end
|
||||
|
||||
it "should not let me see the line_items" do
|
||||
expect(permissions.visible_line_items).to_not include line_item1, line_item2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
module OpenFoodNetwork
|
||||
describe ProductsAndInventoryReport do
|
||||
context "As a site admin" do
|
||||
let(:user) do
|
||||
let(:user) do
|
||||
user = create(:user)
|
||||
user.spree_roles << Spree::Role.find_or_create_by_name!("admin")
|
||||
user
|
||||
@@ -14,7 +14,7 @@ module OpenFoodNetwork
|
||||
|
||||
it "Should return headers" do
|
||||
subject.header.should == [
|
||||
"Supplier",
|
||||
"Supplier",
|
||||
"Producer Suburb",
|
||||
"Product",
|
||||
"Product Properties",
|
||||
@@ -63,7 +63,7 @@ module OpenFoodNetwork
|
||||
|
||||
context "As an enterprise user" do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:enterprise_user) do
|
||||
let(:enterprise_user) do
|
||||
user = create(:user)
|
||||
user.enterprise_roles.create(enterprise: supplier)
|
||||
user.spree_roles = []
|
||||
@@ -79,7 +79,7 @@ module OpenFoodNetwork
|
||||
variant_1 = create(:variant, product: product1)
|
||||
variant_2 = create(:variant, product: product1)
|
||||
|
||||
subject.child_variants.sort.should == [variant_1, variant_2].sort
|
||||
subject.child_variants.should match_array [variant_1, variant_2]
|
||||
end
|
||||
|
||||
it "should only return variants managed by the user" do
|
||||
@@ -87,7 +87,7 @@ module OpenFoodNetwork
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
variant_1 = create(:variant, product: product1)
|
||||
variant_2 = create(:variant, product: product2)
|
||||
|
||||
|
||||
subject.child_variants.should == [variant_2]
|
||||
end
|
||||
end
|
||||
@@ -96,15 +96,15 @@ module OpenFoodNetwork
|
||||
it "should only return variants managed by the user" do
|
||||
product1 = create(:simple_product, supplier: create(:supplier_enterprise))
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
|
||||
|
||||
subject.master_variants.should == [product2.master]
|
||||
end
|
||||
|
||||
it "doesn't return master variants with siblings" do
|
||||
product = create(:simple_product, supplier: supplier)
|
||||
create(:variant, product: product)
|
||||
|
||||
subject.master_variants.should be_empty
|
||||
create(:variant, product: product)
|
||||
|
||||
subject.master_variants.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,13 +113,13 @@ module OpenFoodNetwork
|
||||
it "should return unfiltered variants sans-params" do
|
||||
product1 = create(:simple_product, supplier: supplier)
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
subject.filter(Spree::Variant.scoped).sort.should == [product1.master, product2.master].sort
|
||||
subject.filter(Spree::Variant.scoped).should match_array [product1.master, product2.master]
|
||||
end
|
||||
it "should filter deleted products" do
|
||||
product1 = create(:simple_product, supplier: supplier)
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
product2.delete
|
||||
subject.filter(Spree::Variant.scoped).sort.should == [product1.master].sort
|
||||
subject.filter(Spree::Variant.scoped).should match_array [product1.master]
|
||||
end
|
||||
describe "based on report type" do
|
||||
it "returns only variants on hand" do
|
||||
|
||||
@@ -43,7 +43,7 @@ describe EnterpriseFee do
|
||||
ef3 = create(:enterprise_fee, calculator: Spree::Calculator::PerItem.new)
|
||||
ef4 = create(:enterprise_fee, calculator: Spree::Calculator::PriceSack.new)
|
||||
|
||||
EnterpriseFee.per_item.sort.should == [ef1, ef2, ef3, ef4].sort
|
||||
EnterpriseFee.per_item.should match_array [ef1, ef2, ef3, ef4]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ describe EnterpriseFee do
|
||||
ef1 = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new)
|
||||
ef2 = create(:enterprise_fee, calculator: Spree::Calculator::FlexiRate.new)
|
||||
|
||||
EnterpriseFee.per_order.sort.should == [ef1, ef2].sort
|
||||
EnterpriseFee.per_order.should match_array [ef1, ef2]
|
||||
end
|
||||
|
||||
it "does not return fees with any other calculator" do
|
||||
|
||||
@@ -34,7 +34,7 @@ describe EnterpriseRelationship do
|
||||
it "creates permissions with a list" do
|
||||
er = EnterpriseRelationship.create! parent: e1, child: e2, permissions_list: ['one', 'two']
|
||||
er.reload
|
||||
er.permissions.map(&:name).sort.should == ['one', 'two'].sort
|
||||
er.permissions.map(&:name).should match_array ['one', 'two']
|
||||
end
|
||||
|
||||
it "does nothing when the list is nil" do
|
||||
@@ -50,11 +50,11 @@ describe EnterpriseRelationship do
|
||||
let!(:er3) { create(:enterprise_relationship, parent: e1, child: e3) }
|
||||
|
||||
it "finds relationships that grant permissions to some enterprises" do
|
||||
EnterpriseRelationship.permitting([e1, e2]).sort.should == [er1, er2].sort
|
||||
EnterpriseRelationship.permitting([e1, e2]).should match_array [er1, er2]
|
||||
end
|
||||
|
||||
it "finds relationships that are granted by particular enterprises" do
|
||||
EnterpriseRelationship.permitted_by([e1, e2]).sort.should == [er1, er3].sort
|
||||
EnterpriseRelationship.permitted_by([e1, e2]).should match_array [er1, er3]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,7 +66,7 @@ describe EnterpriseRelationship do
|
||||
er3 = create(:enterprise_relationship, parent: e3, child: e1,
|
||||
permissions_list: ['three', 'four'])
|
||||
|
||||
EnterpriseRelationship.with_permission('two').sort.should == [er1, er2].sort
|
||||
EnterpriseRelationship.with_permission('two').should match_array [er1, er2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -118,7 +118,7 @@ describe Enterprise do
|
||||
let!(:er2) { create(:enterprise_relationship, parent_id: e.id, child_id: c.id) }
|
||||
|
||||
it "finds relatives" do
|
||||
e.relatives.sort.should == [p, c].sort
|
||||
e.relatives.should match_array [p, c]
|
||||
end
|
||||
|
||||
it "scopes relatives to visible distributors" do
|
||||
@@ -422,7 +422,7 @@ describe Enterprise do
|
||||
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]
|
||||
Enterprise.with_distributed_active_products_on_hand.should match_array [d1, d2]
|
||||
end
|
||||
|
||||
it "returns distributors with available products in stock" do
|
||||
@@ -438,7 +438,7 @@ describe Enterprise do
|
||||
create(:product, :distributors => [d4], :on_hand => 0)
|
||||
create(:product, :distributors => [d5]).delete
|
||||
|
||||
Enterprise.with_distributed_active_products_on_hand.sort.should == [d1, d2]
|
||||
Enterprise.with_distributed_active_products_on_hand.should match_array [d1, d2]
|
||||
Enterprise.with_distributed_active_products_on_hand.distinct_count.should == 2
|
||||
end
|
||||
end
|
||||
@@ -458,7 +458,7 @@ describe Enterprise do
|
||||
create(:product, :supplier => d4, :on_hand => 0)
|
||||
create(:product, :supplier => d5).delete
|
||||
|
||||
Enterprise.with_supplied_active_products_on_hand.sort.should == [d1, d2]
|
||||
Enterprise.with_supplied_active_products_on_hand.should match_array [d1, d2]
|
||||
Enterprise.with_supplied_active_products_on_hand.distinct_count.should == 2
|
||||
end
|
||||
end
|
||||
@@ -485,7 +485,7 @@ describe Enterprise do
|
||||
p1 = create(:simple_product, supplier: s1)
|
||||
p2 = create(:simple_product, supplier: s2)
|
||||
|
||||
Enterprise.supplying_variant_in([p1.master, p2.master]).sort.should == [s1, s2].sort
|
||||
Enterprise.supplying_variant_in([p1.master, p2.master]).should match_array [s1, s2]
|
||||
end
|
||||
|
||||
it "does not return duplicates" do
|
||||
@@ -558,35 +558,6 @@ describe Enterprise do
|
||||
enterprises.should include e2
|
||||
end
|
||||
end
|
||||
|
||||
describe "accessible_by" do
|
||||
it "shows only enterprises that are invloved in order cycles which are common to those managed by the given user" do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
e3 = create(:enterprise)
|
||||
e4 = create(:enterprise)
|
||||
e1.enterprise_roles.build(user: user).save
|
||||
oc = create(:simple_order_cycle, coordinator: e2, suppliers: [e1], distributors: [e3])
|
||||
|
||||
enterprises = Enterprise.accessible_by user
|
||||
enterprises.length.should == 3
|
||||
enterprises.should include e1, e2, e3
|
||||
enterprises.should_not include e4
|
||||
end
|
||||
|
||||
it "shows all enterprises for admin user" do
|
||||
user = create(:admin_user)
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.length.should == 2
|
||||
enterprises.should include e1
|
||||
enterprises.should include e2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
@@ -654,9 +625,9 @@ describe Enterprise do
|
||||
er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last
|
||||
er.should_not be_nil
|
||||
if opts[:with] == :all_permissions
|
||||
er.permissions.map(&:name).sort.should == ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides'].sort
|
||||
er.permissions.map(&:name).should match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides']
|
||||
elsif opts.key? :with
|
||||
er.permissions.map(&:name).sort.should == opts[:with].map(&:to_s).sort
|
||||
er.permissions.map(&:name).should match_array opts[:with].map(&:to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -703,7 +674,7 @@ describe Enterprise do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, distributors: [d])
|
||||
v = create(:variant, product: p)
|
||||
d.distributed_variants.sort.should == [p.master, v].sort
|
||||
d.distributed_variants.should match_array [p.master, v]
|
||||
end
|
||||
|
||||
it "finds variants distributed by order cycle" do
|
||||
@@ -725,7 +696,7 @@ describe Enterprise do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, distributors: [d])
|
||||
v = create(:variant, product: p)
|
||||
d.product_distribution_variants.sort.should == [p.master, v].sort
|
||||
d.product_distribution_variants.should match_array [p.master, v]
|
||||
end
|
||||
|
||||
it "does not find variants distributed by order cycle" do
|
||||
@@ -781,12 +752,12 @@ describe Enterprise do
|
||||
|
||||
it "gets all taxons of all distributed products" do
|
||||
Spree::Product.stub(:in_distributor).and_return [product1, product2]
|
||||
distributor.distributed_taxons.sort.should == [taxon1, taxon2].sort
|
||||
distributor.distributed_taxons.should match_array [taxon1, taxon2]
|
||||
end
|
||||
|
||||
it "gets all taxons of all supplied products" do
|
||||
Spree::Product.stub(:in_supplier).and_return [product1, product2]
|
||||
supplier.supplied_taxons.sort.should == [taxon1, taxon2].sort
|
||||
supplier.supplied_taxons.should match_array [taxon1, taxon2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -170,17 +170,17 @@ describe Exchange do
|
||||
|
||||
it "finds exchanges coming from any of a number of enterprises" do
|
||||
Exchange.from_enterprises([coordinator]).should == [outgoing_exchange]
|
||||
Exchange.from_enterprises([supplier, coordinator]).sort.should == [incoming_exchange, outgoing_exchange].sort
|
||||
Exchange.from_enterprises([supplier, coordinator]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
end
|
||||
|
||||
it "finds exchanges going to any of a number of enterprises" do
|
||||
Exchange.to_enterprises([coordinator]).should == [incoming_exchange]
|
||||
Exchange.to_enterprises([coordinator, distributor]).sort.should == [incoming_exchange, outgoing_exchange].sort
|
||||
Exchange.to_enterprises([coordinator, distributor]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
end
|
||||
|
||||
it "finds exchanges involving any of a number of enterprises" do
|
||||
Exchange.involving([supplier]).should == [incoming_exchange]
|
||||
Exchange.involving([coordinator]).sort.should == [incoming_exchange, outgoing_exchange].sort
|
||||
Exchange.involving([coordinator]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
Exchange.involving([distributor]).should == [outgoing_exchange]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ describe OrderCycle do
|
||||
oc_undated = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: nil)
|
||||
|
||||
OrderCycle.active.should == [oc_active]
|
||||
OrderCycle.inactive.sort.should == [oc_not_yet_open, oc_already_closed].sort
|
||||
OrderCycle.inactive.should match_array [oc_not_yet_open, oc_already_closed]
|
||||
OrderCycle.upcoming.should == [oc_not_yet_open]
|
||||
OrderCycle.closed.should == [oc_already_closed]
|
||||
OrderCycle.undated.should == [oc_undated]
|
||||
@@ -153,7 +153,7 @@ describe OrderCycle do
|
||||
e2 = create(:exchange, incoming: true,
|
||||
order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
|
||||
|
||||
oc.suppliers.sort.should == [e1.sender, e2.sender].sort
|
||||
oc.suppliers.should match_array [e1.sender, e2.sender]
|
||||
end
|
||||
|
||||
it "reports its distributors" do
|
||||
@@ -164,7 +164,7 @@ describe OrderCycle do
|
||||
e2 = create(:exchange, incoming: false,
|
||||
order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
|
||||
|
||||
oc.distributors.sort.should == [e1.receiver, e2.receiver].sort
|
||||
oc.distributors.should match_array [e1.receiver, e2.receiver]
|
||||
end
|
||||
|
||||
it "checks for existance of distributors" do
|
||||
@@ -215,11 +215,11 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports on the variants exchanged" do
|
||||
@oc.variants.sort.should == [@p0.master, @p1.master, @p2.master, @p2_v].sort
|
||||
@oc.variants.should match_array [@p0.master, @p1.master, @p2.master, @p2_v]
|
||||
end
|
||||
|
||||
it "reports on the variants distributed" do
|
||||
@oc.distributed_variants.sort.should == [@p1.master, @p2.master, @p2_v].sort
|
||||
@oc.distributed_variants.should match_array [@p1.master, @p2.master, @p2_v]
|
||||
end
|
||||
|
||||
it "reports on the variants distributed by a particular distributor" do
|
||||
@@ -231,7 +231,7 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports on the products exchanged" do
|
||||
@oc.products.sort.should == [@p0, @p1, @p2]
|
||||
@oc.products.should match_array [@p0, @p1, @p2]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -313,7 +313,7 @@ describe OrderCycle do
|
||||
@oc.pickup_time_for(@d2).should == '2-8pm Friday'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "finding pickup instructions for a distributor" do
|
||||
it "returns the pickup instructions" do
|
||||
@oc.pickup_instructions_for(@d1).should == "Come get it!"
|
||||
@@ -375,7 +375,7 @@ describe OrderCycle do
|
||||
|
||||
occ.coordinator_fee_ids.should_not be_empty
|
||||
occ.coordinator_fee_ids.should == oc.coordinator_fee_ids
|
||||
|
||||
|
||||
# to_h gives us a unique hash for each exchange
|
||||
# check that the clone has no additional exchanges
|
||||
occ.exchanges.map(&:to_h).all? do |ex|
|
||||
@@ -402,7 +402,7 @@ describe OrderCycle do
|
||||
describe "finding order cycles opening in the future" do
|
||||
it "should give the soonest opening order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
|
||||
OrderCycle.first_opening_for(distributor).should == oc
|
||||
end
|
||||
|
||||
@@ -411,12 +411,12 @@ describe OrderCycle do
|
||||
OrderCycle.first_opening_for(distributor).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "finding open order cycles" do
|
||||
it "should give the soonest closing order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.days.ago, orders_close_at: 11.days.from_now)
|
||||
oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.days.ago, orders_close_at: 11.days.from_now)
|
||||
oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
|
||||
OrderCycle.first_closing_for(distributor).should == oc
|
||||
end
|
||||
end
|
||||
|
||||
@@ -213,7 +213,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory], for: :report)
|
||||
should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: :report)
|
||||
end
|
||||
|
||||
it "should not be able to read other reports" do
|
||||
@@ -400,7 +400,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
should have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :report)
|
||||
should have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: :report)
|
||||
end
|
||||
|
||||
it "should not be able to read other reports" do
|
||||
|
||||
@@ -22,7 +22,7 @@ module Spree
|
||||
it "finds line items for products supplied by one of a number of enterprises" do
|
||||
LineItem.supplied_by_any([s1]).should == [li1]
|
||||
LineItem.supplied_by_any([s2]).should == [li2]
|
||||
LineItem.supplied_by_any([s1, s2]).sort.should == [li1, li2].sort
|
||||
LineItem.supplied_by_any([s1, s2]).should match_array [li1, li2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module Spree
|
||||
let(:payment) { create(:payment, source: create(:credit_card)) }
|
||||
|
||||
it "can capture and void" do
|
||||
payment.actions.sort.should == %w(capture void).sort
|
||||
payment.actions.should match_array %w(capture void)
|
||||
end
|
||||
|
||||
describe "when a payment has been taken" do
|
||||
@@ -17,7 +17,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "can void and credit" do
|
||||
payment.actions.sort.should == %w(void credit).sort
|
||||
payment.actions.should match_array %w(void credit)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -545,7 +545,7 @@ module Spree
|
||||
ot3 = create(:option_type, name: 'unit_items', presentation: 'Items')
|
||||
ot4 = create(:option_type, name: 'foo_unit_bar', presentation: 'Foo')
|
||||
|
||||
Spree::Product.all_variant_unit_option_types.sort.should == [ot1, ot2, ot3].sort
|
||||
Spree::Product.all_variant_unit_option_types.should match_array [ot1, ot2, ot3]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ module Spree
|
||||
sm.distributors << d1
|
||||
sm.distributors << d2
|
||||
|
||||
sm.reload.distributors.sort.should == [d1, d2].sort
|
||||
sm.reload.distributors.should match_array [d1, d2]
|
||||
end
|
||||
|
||||
it "finds shipping methods for a particular distributor" do
|
||||
|
||||
@@ -25,7 +25,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "returns variants in stock or on demand, but not those that are neither" do
|
||||
Variant.where(is_master: false).in_stock.sort.should == [@v_in_stock, @v_on_demand].sort
|
||||
Variant.where(is_master: false).in_stock.should match_array [@v_in_stock, @v_on_demand]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ describe VariantOverride do
|
||||
let!(:vo2) { create(:variant_override, hub: hub2, variant: v) }
|
||||
|
||||
it "finds variant overrides for a set of hubs" do
|
||||
VariantOverride.for_hubs([hub1, hub2]).sort.should == [vo1, vo2].sort
|
||||
VariantOverride.for_hubs([hub1, hub2]).should match_array [vo1, vo2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user