mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #4422 from luisramos0/the_poc
New Order Cycles edit page with steps
This commit is contained in:
@@ -32,7 +32,6 @@ Metrics/LineLength:
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/inventory_items_controller.rb
|
||||
- app/controllers/admin/manager_invitations_controller.rb
|
||||
- app/controllers/admin/order_cycles_controller.rb
|
||||
- app/controllers/admin/product_import_controller.rb
|
||||
- app/controllers/admin/proxy_orders_controller.rb
|
||||
- app/controllers/admin/schedules_controller.rb
|
||||
|
||||
@@ -1,92 +1,14 @@
|
||||
angular.module('admin.orderCycles')
|
||||
.controller 'AdminCreateOrderCycleCtrl', ($scope, $filter, $window, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, ocInstance, StatusMessage) ->
|
||||
$scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id)
|
||||
$scope.supplier_enterprises = Enterprise.producer_enterprises
|
||||
$scope.distributor_enterprises = Enterprise.hub_enterprises
|
||||
$scope.supplied_products = Enterprise.supplied_products
|
||||
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
|
||||
$scope.schedules = Schedules.index({enterprise_id: ocInstance.coordinator_id})
|
||||
.controller 'AdminCreateOrderCycleCtrl', ($scope, $controller, $filter, $window, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, ocInstance, StatusMessage) ->
|
||||
$controller('AdminOrderCycleBasicCtrl', {$scope: $scope, ocInstance: ocInstance})
|
||||
|
||||
$scope.view = 'general_settings'
|
||||
|
||||
$scope.OrderCycle = OrderCycle
|
||||
$scope.order_cycle = OrderCycle.new({ coordinator_id: ocInstance.coordinator_id})
|
||||
|
||||
$scope.StatusMessage = StatusMessage
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', t("admin.unsaved_changes") if newValue
|
||||
|
||||
$scope.$watch 'order_cycle_form.$valid', (isValid) ->
|
||||
StatusMessage.setValidation(isValid)
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded && !RequestMonitor.loading
|
||||
|
||||
$scope.suppliedVariants = (enterprise_id) ->
|
||||
Enterprise.suppliedVariants(enterprise_id)
|
||||
|
||||
$scope.exchangeSelectedVariants = (exchange) ->
|
||||
OrderCycle.exchangeSelectedVariants(exchange)
|
||||
|
||||
$scope.setExchangeVariants = (exchange, variants, selected) ->
|
||||
OrderCycle.setExchangeVariants(exchange, variants, selected)
|
||||
|
||||
$scope.enterpriseTotalVariants = (enterprise) ->
|
||||
Enterprise.totalVariants(enterprise)
|
||||
|
||||
$scope.productSuppliedToOrderCycle = (product) ->
|
||||
OrderCycle.productSuppliedToOrderCycle(product)
|
||||
|
||||
$scope.variantSuppliedToOrderCycle = (variant) ->
|
||||
OrderCycle.variantSuppliedToOrderCycle(variant)
|
||||
|
||||
$scope.incomingExchangeVariantsFor = (enterprise_id) ->
|
||||
$filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id])
|
||||
|
||||
$scope.exchangeDirection = (exchange) ->
|
||||
OrderCycle.exchangeDirection(exchange)
|
||||
|
||||
$scope.enterprisesWithFees = ->
|
||||
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
|
||||
$scope.addSupplier = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addSupplier($scope.new_supplier_id)
|
||||
|
||||
$scope.addDistributor = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addDistributor($scope.new_distributor_id)
|
||||
|
||||
$scope.removeExchange = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchange(exchange)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
$scope.removeCoordinatorFee = ($event, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
|
||||
$scope.addExchangeFee = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addExchangeFee(exchange)
|
||||
|
||||
$scope.removeExchangeFee = ($event, exchange, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchangeFee(exchange, index)
|
||||
|
||||
$scope.removeDistributionOfVariant = (variant_id) ->
|
||||
OrderCycle.removeDistributionOfVariant(variant_id)
|
||||
$scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id)
|
||||
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
|
||||
|
||||
$scope.submit = ($event, destination) ->
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
OrderCycle.create(destination)
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
|
||||
@@ -1,91 +1,19 @@
|
||||
angular.module('admin.orderCycles')
|
||||
.controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, ocInstance) ->
|
||||
.controller 'AdminEditOrderCycleCtrl', ($scope, $controller, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, ocInstance) ->
|
||||
$controller('AdminOrderCycleBasicCtrl', {$scope: $scope, ocInstance: ocInstance})
|
||||
|
||||
$scope.view = 'general_settings'
|
||||
|
||||
order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
|
||||
$scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id)
|
||||
$scope.supplier_enterprises = Enterprise.producer_enterprises
|
||||
$scope.distributor_enterprises = Enterprise.hub_enterprises
|
||||
$scope.supplied_products = Enterprise.supplied_products
|
||||
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id)
|
||||
$scope.schedules = Schedules.index({enterprise_id: ocInstance.coordinator_id})
|
||||
|
||||
$scope.OrderCycle = OrderCycle
|
||||
$scope.order_cycle = OrderCycle.load(order_cycle_id)
|
||||
|
||||
$scope.StatusMessage = StatusMessage
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', t("admin.unsaved_changes") if newValue
|
||||
|
||||
$scope.$watch 'order_cycle_form.$valid', (isValid) ->
|
||||
StatusMessage.setValidation(isValid)
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded && !RequestMonitor.loading
|
||||
|
||||
$scope.suppliedVariants = (enterprise_id) ->
|
||||
Enterprise.suppliedVariants(enterprise_id)
|
||||
|
||||
$scope.exchangeSelectedVariants = (exchange) ->
|
||||
OrderCycle.exchangeSelectedVariants(exchange)
|
||||
|
||||
$scope.setExchangeVariants = (exchange, variants, selected) ->
|
||||
OrderCycle.setExchangeVariants(exchange, variants, selected)
|
||||
|
||||
$scope.enterpriseTotalVariants = (enterprise) ->
|
||||
Enterprise.totalVariants(enterprise)
|
||||
|
||||
$scope.productSuppliedToOrderCycle = (product) ->
|
||||
OrderCycle.productSuppliedToOrderCycle(product)
|
||||
|
||||
$scope.variantSuppliedToOrderCycle = (variant) ->
|
||||
OrderCycle.variantSuppliedToOrderCycle(variant)
|
||||
|
||||
$scope.incomingExchangeVariantsFor = (enterprise_id) ->
|
||||
$filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id])
|
||||
|
||||
$scope.exchangeDirection = (exchange) ->
|
||||
OrderCycle.exchangeDirection(exchange)
|
||||
|
||||
$scope.enterprisesWithFees = ->
|
||||
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
|
||||
$scope.addSupplier = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addSupplier($scope.new_supplier_id)
|
||||
|
||||
$scope.addDistributor = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addDistributor($scope.new_distributor_id)
|
||||
|
||||
$scope.removeExchange = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchange(exchange)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
$scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id)
|
||||
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id)
|
||||
|
||||
$scope.removeCoordinatorFee = ($event, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addExchangeFee = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addExchangeFee(exchange)
|
||||
|
||||
$scope.removeExchangeFee = ($event, exchange, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchangeFee(exchange, index)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.removeDistributionOfVariant = (variant_id) ->
|
||||
OrderCycle.removeDistributionOfVariant(variant_id)
|
||||
|
||||
$scope.submit = (destination) ->
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
@@ -94,6 +22,3 @@ angular.module('admin.orderCycles')
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
OrderCycle.update(destination, $scope.order_cycle_form)
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
angular.module('admin.orderCycles').controller 'AdminOrderCycleIncomingCtrl', ($scope, $controller, $location, Enterprise, ocInstance) ->
|
||||
$controller('AdminOrderCycleExchangesCtrl', {$scope: $scope, ocInstance: ocInstance, $location: $location})
|
||||
|
||||
$scope.view = 'incoming'
|
||||
|
||||
$scope.enterpriseTotalVariants = (enterprise) ->
|
||||
Enterprise.totalVariants(enterprise)
|
||||
@@ -0,0 +1,40 @@
|
||||
angular.module('admin.orderCycles')
|
||||
.controller 'AdminOrderCycleBasicCtrl', ($scope, $filter, $window, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, ocInstance, StatusMessage) ->
|
||||
$scope.StatusMessage = StatusMessage
|
||||
$scope.OrderCycle = OrderCycle
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', t("admin.unsaved_changes") if newValue
|
||||
|
||||
$scope.$watch 'order_cycle_form.$valid', (isValid) ->
|
||||
StatusMessage.setValidation(isValid)
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded && !RequestMonitor.loading
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
|
||||
# Used in panels/exchange_supplied_products.html
|
||||
$scope.suppliedVariants = (enterprise_id) ->
|
||||
Enterprise.suppliedVariants(enterprise_id)
|
||||
|
||||
# Used in panels/exchange_supplied_products.html and panels/exchange_distributed_products.html
|
||||
$scope.setExchangeVariants = (exchange, variants, selected) ->
|
||||
OrderCycle.setExchangeVariants(exchange, variants, selected)
|
||||
|
||||
# The following methods are specific to the general settings pages:
|
||||
# - simple create, simple edit and general settings pages
|
||||
|
||||
$scope.schedules = Schedules.index({enterprise_id: ocInstance.coordinator_id})
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
$scope.removeCoordinatorFee = ($event, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
@@ -0,0 +1,41 @@
|
||||
angular.module('admin.orderCycles')
|
||||
.controller 'AdminOrderCycleExchangesCtrl', ($scope, $controller, $filter, $window, $location, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, ocInstance, StatusMessage) ->
|
||||
$controller('AdminEditOrderCycleCtrl', {$scope: $scope, ocInstance: ocInstance, $location: $location})
|
||||
|
||||
$scope.supplier_enterprises = Enterprise.producer_enterprises
|
||||
$scope.distributor_enterprises = Enterprise.hub_enterprises
|
||||
$scope.supplied_products = Enterprise.supplied_products
|
||||
|
||||
$scope.exchangeSelectedVariants = (exchange) ->
|
||||
OrderCycle.exchangeSelectedVariants(exchange)
|
||||
|
||||
$scope.exchangeDirection = (exchange) ->
|
||||
OrderCycle.exchangeDirection(exchange)
|
||||
|
||||
$scope.enterprisesWithFees = ->
|
||||
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
|
||||
|
||||
$scope.removeExchange = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchange(exchange)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addExchangeFee = ($event, exchange) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addExchangeFee(exchange)
|
||||
|
||||
$scope.removeExchangeFee = ($event, exchange, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeExchangeFee(exchange, index)
|
||||
$scope.order_cycle_form.$dirty = true
|
||||
|
||||
$scope.addSupplier = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addSupplier($scope.new_supplier_id)
|
||||
|
||||
$scope.addDistributor = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addDistributor($scope.new_distributor_id)
|
||||
|
||||
$scope.removeDistributionOfVariant = (variant_id) ->
|
||||
OrderCycle.removeDistributionOfVariant(variant_id)
|
||||
@@ -0,0 +1,18 @@
|
||||
angular.module('admin.orderCycles').controller 'AdminOrderCycleOutgoingCtrl', ($scope, $controller, $filter, $location, OrderCycle, ocInstance, StatusMessage) ->
|
||||
$controller('AdminOrderCycleExchangesCtrl', {$scope: $scope, ocInstance: ocInstance, $location: $location})
|
||||
|
||||
$scope.view = 'outgoing'
|
||||
|
||||
$scope.productSuppliedToOrderCycle = (product) ->
|
||||
OrderCycle.productSuppliedToOrderCycle(product)
|
||||
|
||||
$scope.variantSuppliedToOrderCycle = (variant) ->
|
||||
OrderCycle.variantSuppliedToOrderCycle(variant)
|
||||
|
||||
$scope.incomingExchangeVariantsFor = (enterprise_id) ->
|
||||
$filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id])
|
||||
|
||||
$scope.submit = ($event, destination) ->
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
OrderCycle.update(destination, $scope.order_cycle_form) if OrderCycle.confirmNoDistributors()
|
||||
@@ -1,19 +1,12 @@
|
||||
angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, ocInstance) ->
|
||||
$scope.StatusMessage = StatusMessage
|
||||
$scope.OrderCycle = OrderCycle
|
||||
$scope.schedules = Schedules.index({enterprise_id: ocInstance.coordinator_id})
|
||||
angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, $controller, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, ocInstance) ->
|
||||
$controller('AdminOrderCycleBasicCtrl', {$scope: $scope, ocInstance: ocInstance})
|
||||
|
||||
$scope.order_cycle = OrderCycle.new {coordinator_id: ocInstance.coordinator_id}, =>
|
||||
# TODO: make this a get method, which only fetches one enterprise
|
||||
$scope.enterprises = Enterprise.index {coordinator_id: ocInstance.coordinator_id}, (enterprises) =>
|
||||
$scope.init(enterprises)
|
||||
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', t("admin.unsaved_changes") if newValue
|
||||
|
||||
$scope.$watch 'order_cycle_form.$valid', (isValid) ->
|
||||
StatusMessage.setValidation(isValid)
|
||||
|
||||
$scope.init = (enterprises) ->
|
||||
enterprise = enterprises[Object.keys(enterprises)[0]]
|
||||
OrderCycle.addSupplier enterprise.id
|
||||
@@ -26,33 +19,10 @@ angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl"
|
||||
|
||||
OrderCycle.order_cycle.coordinator_id = enterprise.id
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded && !RequestMonitor.loading
|
||||
|
||||
$scope.removeDistributionOfVariant = angular.noop
|
||||
|
||||
$scope.setExchangeVariants = (exchange, variants, selected) ->
|
||||
OrderCycle.setExchangeVariants(exchange, variants, selected)
|
||||
|
||||
$scope.suppliedVariants = (enterprise_id) ->
|
||||
Enterprise.suppliedVariants(enterprise_id)
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
$scope.removeCoordinatorFee = ($event, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
|
||||
$scope.submit = ($event, destination) ->
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
OrderCycle.mirrorIncomingToOutgoingProducts()
|
||||
OrderCycle.create(destination)
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
OrderCycle.create(destination) if OrderCycle.confirmNoDistributors()
|
||||
|
||||
@@ -1,51 +1,21 @@
|
||||
angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", ($scope, $location, $window, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, StatusMessage, ocInstance) ->
|
||||
angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", ($scope, $controller, $location, $window, OrderCycle, Enterprise, EnterpriseFee, Schedules, RequestMonitor, StatusMessage, ocInstance) ->
|
||||
$controller('AdminOrderCycleBasicCtrl', {$scope: $scope, ocInstance: ocInstance})
|
||||
|
||||
$scope.orderCycleId = ->
|
||||
$location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
|
||||
|
||||
$scope.StatusMessage = StatusMessage
|
||||
$scope.enterprises = Enterprise.index(order_cycle_id: $scope.orderCycleId())
|
||||
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.orderCycleId())
|
||||
$scope.schedules = Schedules.index({enterprise_id: ocInstance.coordinator_id})
|
||||
$scope.OrderCycle = OrderCycle
|
||||
$scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) =>
|
||||
$scope.init()
|
||||
|
||||
$scope.$watch 'order_cycle_form.$dirty', (newValue) ->
|
||||
StatusMessage.display 'notice', t("admin.unsaved_changes") if newValue
|
||||
|
||||
$scope.$watch 'order_cycle_form.$valid', (isValid) ->
|
||||
StatusMessage.setValidation(isValid)
|
||||
|
||||
$scope.loaded = ->
|
||||
Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded && !RequestMonitor.loading
|
||||
|
||||
$scope.init = ->
|
||||
$scope.outgoing_exchange = OrderCycle.order_cycle.outgoing_exchanges[0]
|
||||
|
||||
$scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
|
||||
$scope.removeDistributionOfVariant = angular.noop
|
||||
|
||||
$scope.setExchangeVariants = (exchange, variants, selected) ->
|
||||
OrderCycle.setExchangeVariants(exchange, variants, selected)
|
||||
|
||||
$scope.suppliedVariants = (enterprise_id) ->
|
||||
Enterprise.suppliedVariants(enterprise_id)
|
||||
|
||||
$scope.addCoordinatorFee = ($event) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
$scope.removeCoordinatorFee = ($event, index) ->
|
||||
$event.preventDefault()
|
||||
OrderCycle.removeCoordinatorFee(index)
|
||||
|
||||
$scope.submit = ($event, destination) ->
|
||||
$event.preventDefault()
|
||||
StatusMessage.display 'progress', t('js.saving')
|
||||
OrderCycle.mirrorIncomingToOutgoingProducts()
|
||||
OrderCycle.update(destination, $scope.order_cycle_form)
|
||||
|
||||
$scope.cancel = (destination) ->
|
||||
$window.location = destination
|
||||
OrderCycle.update(destination, $scope.order_cycle_form) if OrderCycle.confirmNoDistributors()
|
||||
|
||||
@@ -148,10 +148,12 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S
|
||||
this.order_cycle
|
||||
|
||||
create: (destination) ->
|
||||
return unless @confirmNoDistributors()
|
||||
oc = new OrderCycleResource({order_cycle: this.dataForSubmit()})
|
||||
oc.$create (data) ->
|
||||
$window.location = destination
|
||||
if destination? && destination.length != 0
|
||||
$window.location = destination
|
||||
else if data.edit_path?
|
||||
$window.location = data.edit_path
|
||||
, (response) ->
|
||||
if response.data.errors?
|
||||
StatusMessage.display('failure', response.data.errors[0])
|
||||
@@ -159,7 +161,6 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S
|
||||
StatusMessage.display('failure', t('js.order_cycles.create_failure'))
|
||||
|
||||
update: (destination, form) ->
|
||||
return unless @confirmNoDistributors()
|
||||
oc = new OrderCycleResource({order_cycle: this.dataForSubmit()})
|
||||
oc.$update {order_cycle_id: this.order_cycle.id, reloading: (if destination? then 1 else 0)}, (data) =>
|
||||
form.$setPristine() if form
|
||||
@@ -173,7 +174,6 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S
|
||||
else
|
||||
StatusMessage.display('failure', t('js.order_cycles.update_failure'))
|
||||
|
||||
|
||||
confirmNoDistributors: ->
|
||||
if @order_cycle.outgoing_exchanges.length == 0
|
||||
confirm t('js.order_cycles.no_distributors')
|
||||
|
||||
@@ -2,6 +2,7 @@ module Admin
|
||||
class OrderCyclesController < ResourceController
|
||||
include OrderCyclesHelper
|
||||
|
||||
prepend_before_filter :set_order_cycle_id, only: [:incoming, :outgoing]
|
||||
before_filter :load_data_for_index, only: :index
|
||||
before_filter :require_coordinator, only: :new
|
||||
before_filter :remove_protected_attrs, only: [:update]
|
||||
@@ -12,9 +13,10 @@ module Admin
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json do
|
||||
render_as_json @collection, ams_prefix: params[:ams_prefix],
|
||||
current_user: spree_current_user,
|
||||
subscriptions_count: SubscriptionsCount.new(@collection)
|
||||
render_as_json @collection,
|
||||
ams_prefix: params[:ams_prefix],
|
||||
current_user: spree_current_user,
|
||||
subscriptions_count: SubscriptionsCount.new(@collection)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,12 +44,17 @@ module Admin
|
||||
|
||||
if @order_cycle_form.save
|
||||
flash[:notice] = I18n.t(:order_cycles_create_notice)
|
||||
render json: { success: true }
|
||||
render json: { success: true,
|
||||
edit_path: main_app.admin_order_cycle_incoming_path(@order_cycle) }
|
||||
else
|
||||
render json: { errors: @order_cycle.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def set_order_cycle_id
|
||||
params[:id] = params[:order_cycle_id]
|
||||
end
|
||||
|
||||
def update
|
||||
@order_cycle_form = OrderCycleForm.new(@order_cycle, params, spree_current_user)
|
||||
|
||||
@@ -64,9 +71,10 @@ module Admin
|
||||
|
||||
def bulk_update
|
||||
if order_cycle_set.andand.save
|
||||
render_as_json @order_cycles, ams_prefix: 'index',
|
||||
current_user: spree_current_user,
|
||||
subscriptions_count: SubscriptionsCount.new(@collection)
|
||||
render_as_json @order_cycles,
|
||||
ams_prefix: 'index',
|
||||
current_user: spree_current_user,
|
||||
subscriptions_count: SubscriptionsCount.new(@collection)
|
||||
else
|
||||
order_cycle = order_cycle_set.collection.find{ |oc| oc.errors.present? }
|
||||
render json: { errors: order_cycle.errors.full_messages }, status: :unprocessable_entity
|
||||
@@ -94,20 +102,8 @@ module Admin
|
||||
return Enterprise.where("1=0") unless json_request?
|
||||
return order_cycles_from_set if params[:order_cycle_set]
|
||||
|
||||
ocs = if params[:as] == "distributor"
|
||||
OrderCycle.preload(:schedules).ransack(params[:q]).result.
|
||||
involving_managed_distributors_of(spree_current_user).order('updated_at DESC')
|
||||
elsif params[:as] == "producer"
|
||||
OrderCycle.preload(:schedules).ransack(params[:q]).result.
|
||||
involving_managed_producers_of(spree_current_user).order('updated_at DESC')
|
||||
else
|
||||
OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user)
|
||||
end
|
||||
|
||||
ocs.undated |
|
||||
ocs.soonest_closing |
|
||||
ocs.soonest_opening |
|
||||
ocs.closed
|
||||
ocs = order_cycles
|
||||
ocs.undated | ocs.soonest_closing | ocs.soonest_opening | ocs.closed
|
||||
end
|
||||
|
||||
def collection_actions
|
||||
@@ -116,21 +112,60 @@ module Admin
|
||||
|
||||
private
|
||||
|
||||
def order_cycles
|
||||
if params[:as] == "distributor"
|
||||
order_cycles_as_distributor
|
||||
elsif params[:as] == "producer"
|
||||
order_cycles_as_producer
|
||||
else
|
||||
order_cycles_as_both
|
||||
end
|
||||
end
|
||||
|
||||
def order_cycles_as_distributor
|
||||
OrderCycle.
|
||||
preload(:schedules).
|
||||
ransack(params[:q]).
|
||||
result.
|
||||
involving_managed_distributors_of(spree_current_user).
|
||||
order('updated_at DESC')
|
||||
end
|
||||
|
||||
def order_cycles_as_producer
|
||||
OrderCycle.
|
||||
preload(:schedules).
|
||||
ransack(params[:q]).
|
||||
result.
|
||||
involving_managed_producers_of(spree_current_user).
|
||||
order('updated_at DESC')
|
||||
end
|
||||
|
||||
def order_cycles_as_both
|
||||
OrderCycle.
|
||||
preload(:schedules).
|
||||
ransack(params[:q]).
|
||||
result.
|
||||
accessible_by(spree_current_user)
|
||||
end
|
||||
|
||||
def load_data_for_index
|
||||
if json_request?
|
||||
# Split ransack params into all those that currently exist and new ones to limit returned ocs to recent or undated
|
||||
# Split ransack params into all those that currently exist and new ones
|
||||
# to limit returned ocs to recent or undated
|
||||
orders_close_at_gt = params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago
|
||||
params[:q] = {
|
||||
g: [params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true }]
|
||||
g: [params.delete(:q) || {}, { m: 'or',
|
||||
orders_close_at_gt: orders_close_at_gt,
|
||||
orders_close_at_null: true }]
|
||||
}
|
||||
@collection = collection
|
||||
end
|
||||
end
|
||||
|
||||
def require_coordinator
|
||||
if params[:coordinator_id] && @order_cycle.coordinator = permitted_coordinating_enterprises_for(@order_cycle).find_by_id(params[:coordinator_id])
|
||||
return
|
||||
end
|
||||
@order_cycle.coordinator =
|
||||
permitted_coordinating_enterprises_for(@order_cycle).find_by_id(params[:coordinator_id])
|
||||
return if params[:coordinator_id] && @order_cycle.coordinator
|
||||
|
||||
available_coordinators = permitted_coordinating_enterprises_for(@order_cycle)
|
||||
case available_coordinators.count
|
||||
@@ -140,7 +175,9 @@ module Admin
|
||||
when 1
|
||||
@order_cycle.coordinator = available_coordinators.first
|
||||
else
|
||||
flash[:error] = I18n.t(:order_cycles_no_permission_to_create_error) if params[:coordinator_id]
|
||||
if params[:coordinator_id]
|
||||
flash[:error] = I18n.t(:order_cycles_no_permission_to_create_error)
|
||||
end
|
||||
render :set_coordinator
|
||||
end
|
||||
end
|
||||
@@ -164,7 +201,9 @@ module Admin
|
||||
params[:order_cycle].delete :coordinator_id
|
||||
|
||||
unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
|
||||
params[:order_cycle].delete_if{ |k, _v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym }
|
||||
params[:order_cycle].delete_if do |k, _v|
|
||||
[:name, :orders_open_at, :orders_close_at].include? k.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -189,7 +228,8 @@ module Admin
|
||||
def require_order_cycle_set_params
|
||||
return if params[:order_cycle_set]
|
||||
|
||||
render json: { errors: t('admin.order_cycles.bulk_update.no_data') }, status: :unprocessable_entity
|
||||
render json: { errors: t('admin.order_cycles.bulk_update.no_data') },
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def ams_prefix_whitelist
|
||||
|
||||
@@ -192,7 +192,7 @@ class AbilityDecorator
|
||||
end
|
||||
|
||||
def add_order_cycle_management_abilities(user)
|
||||
can [:admin, :index, :read, :edit, :update], OrderCycle do |order_cycle|
|
||||
can [:admin, :index, :read, :edit, :update, :incoming, :outgoing], OrderCycle do |order_cycle|
|
||||
OrderCycle.accessible_by(user).include? order_cycle
|
||||
end
|
||||
can [:admin, :index, :create], Schedule
|
||||
|
||||
@@ -1,49 +1,9 @@
|
||||
= render 'wizard_progress'
|
||||
|
||||
%fieldset.no-border-bottom
|
||||
%legend{ align: 'center'}= t('spree.general_settings')
|
||||
|
||||
= render 'name_and_timing_form', f: f
|
||||
|
||||
-if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
|
||||
= render 'coordinator_fees', f: f
|
||||
|
||||
%h2= t('.incoming')
|
||||
%table.exchanges
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.supplier')
|
||||
%th
|
||||
=t('.products')
|
||||
= surround '(', ')' do
|
||||
%a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('incoming')"}
|
||||
%span{'ng-show' => "OrderCycle.showProducts['incoming']"}= t(:collapse_all)
|
||||
%span{'ng-hide' => "OrderCycle.showProducts['incoming']"}= t(:expand_all)
|
||||
%th= t('.receival_details')
|
||||
%th= t('.fees')
|
||||
%th.actions
|
||||
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
|
||||
= render 'exchange_form', f: f, type: 'supplier'
|
||||
|
||||
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
|
||||
= render 'add_exchange_form', f: f, type: 'supplier'
|
||||
|
||||
%h2= t('.outgoing')
|
||||
%table.exchanges
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.distributor')
|
||||
%th
|
||||
= t('.products')
|
||||
= surround '(', ')' do
|
||||
%a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('outgoing')"}
|
||||
%span{'ng-show' => "OrderCycle.showProducts['outgoing']"}= t(:collapse_all)
|
||||
%span{'ng-hide' => "OrderCycle.showProducts['outgoing']"}= t(:expand_all)
|
||||
%th{ ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } }
|
||||
= t('.tags')
|
||||
%th= t('.delivery_details')
|
||||
%th= t('.fees')
|
||||
%th.actions
|
||||
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'}
|
||||
= render 'exchange_form', f: f, type: 'distributor'
|
||||
|
||||
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
|
||||
= render 'add_exchange_form', f: f, type: 'distributor'
|
||||
|
||||
.actions
|
||||
%span{'ng-hide' => 'loaded()'}= t(:loading)
|
||||
|
||||
3
app/views/admin/order_cycles/_wizard_progress.html.haml
Normal file
3
app/views/admin/order_cycles/_wizard_progress.html.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
%ul.wizard-progress
|
||||
%li{ ng: { repeat: "step in ['general_settings','incoming','outgoing']", class: '{current: view==step}' } }
|
||||
{{ "admin.order_cycles.wizard_progress."+ step | t }}
|
||||
@@ -21,7 +21,7 @@
|
||||
#advanced_settings{ hidden: true }
|
||||
= render partial: "/admin/order_cycles/advanced_settings"
|
||||
|
||||
%h1
|
||||
- content_for :page_title do
|
||||
= t :edit_order_cycle
|
||||
|
||||
- ng_controller = order_cycles_simple_form ? 'AdminSimpleEditOrderCycleCtrl' : 'AdminEditOrderCycleCtrl'
|
||||
@@ -29,9 +29,13 @@
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f|
|
||||
|
||||
%save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" }
|
||||
%input.red{ type: "button", value: t(:update), ng: { click: "submit($event, null)", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input.red{ type: "button", value: t('.update_and_close'), ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t(:cancel)}' : '#{t(:close)}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
%input.red{ type: "button", value: t('.save'), ng: { click: "submit($event, null)", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
- if order_cycles_simple_form
|
||||
%input.red{ type: "button", value: t('.save_and_back_to_list'), ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
- else
|
||||
%input.red{ type: "button", value: t('.save_and_next'), ng: { click: "submit($event, '#{main_app.admin_order_cycle_incoming_path(@order_cycle)}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", value: t('.next'), ng: { click: "cancel('#{main_app.admin_order_cycle_incoming_path(@order_cycle)}')", disabled: "order_cycle_form.$dirty" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t('.cancel')}' : '#{t('.back_to_list')}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
|
||||
- if order_cycles_simple_form
|
||||
= render 'simple_form', f: f
|
||||
|
||||
39
app/views/admin/order_cycles/incoming.html.haml
Normal file
39
app/views/admin/order_cycles/incoming.html.haml
Normal file
@@ -0,0 +1,39 @@
|
||||
- content_for :page_title do
|
||||
= t :edit_order_cycle
|
||||
|
||||
= admin_inject_order_cycle_instance
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => 'AdminOrderCycleIncomingCtrl', name: 'order_cycle_form'} do |f|
|
||||
|
||||
= render 'wizard_progress'
|
||||
|
||||
%save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" }
|
||||
%input{ type: "button", value: t('.previous'), ng: { click: "cancel('#{main_app.edit_admin_order_cycle_path(@order_cycle)}')", disabled: "order_cycle_form.$dirty" } }
|
||||
%input.red{ type: "button", value: t('.save'), ng: { click: "submit($event, null)", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input.red{ type: "button", value: t('.save_and_next'), ng: { click: "submit($event, '#{main_app.admin_order_cycle_outgoing_path(@order_cycle)}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", value: t('.next'), ng: { click: "cancel('#{main_app.admin_order_cycle_outgoing_path(@order_cycle)}')", disabled: "order_cycle_form.$dirty" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t('.cancel')}' : '#{t('.back_to_list')}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
|
||||
%fieldset.no-border-bottom
|
||||
%legend{ align: 'center'}= t('.incoming')
|
||||
|
||||
%table.exchanges
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.supplier')
|
||||
%th
|
||||
= t('.products')
|
||||
= surround '(', ')' do
|
||||
%a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('incoming')"}
|
||||
%span{'ng-show' => "OrderCycle.showProducts['incoming']"}= t(:collapse_all)
|
||||
%span{'ng-hide' => "OrderCycle.showProducts['incoming']"}= t(:expand_all)
|
||||
%th= t('.receival_details')
|
||||
%th= t('.fees')
|
||||
%th.actions
|
||||
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'}
|
||||
= render 'exchange_form', f: f, type: 'supplier'
|
||||
|
||||
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
|
||||
= render 'add_exchange_form', f: f, type: 'supplier'
|
||||
|
||||
.actions
|
||||
%span{'ng-hide' => 'loaded()'}= t(:loading)
|
||||
@@ -7,8 +7,10 @@
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f|
|
||||
|
||||
%save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" }
|
||||
%input.red{ type: "button", value: t(:create), ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? 'Cancel' : 'Close'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
- if order_cycles_simple_form
|
||||
- custom_redirect_path = main_app.admin_order_cycles_path
|
||||
%input.red{ type: "button", value: t('.create'), ng: { click: "submit($event, '#{custom_redirect_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t('.cancel')}' : '#{t('.back_to_list')}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
|
||||
- if order_cycles_simple_form
|
||||
= render 'simple_form', f: f
|
||||
|
||||
40
app/views/admin/order_cycles/outgoing.html.haml
Normal file
40
app/views/admin/order_cycles/outgoing.html.haml
Normal file
@@ -0,0 +1,40 @@
|
||||
- content_for :page_title do
|
||||
= t :edit_order_cycle
|
||||
|
||||
= admin_inject_order_cycle_instance
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => 'AdminOrderCycleOutgoingCtrl', name: 'order_cycle_form'} do |f|
|
||||
|
||||
= render 'wizard_progress'
|
||||
|
||||
%save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" }
|
||||
%input{ type: "button", value: t('.previous'), ng: { click: "cancel('#{main_app.admin_order_cycle_incoming_path(@order_cycle)}')", disabled: "order_cycle_form.$dirty" } }
|
||||
%input.red{ type: "button", value: t('.save'), ng: { click: "submit($event, null)", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input.red{ type: "button", value: t('.save_and_back_to_list'), ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t('.cancel')}' : '#{t('.back_to_list')}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
|
||||
%fieldset.no-border-bottom
|
||||
%legend{ align: 'center'}= t('.outgoing')
|
||||
|
||||
%table.exchanges
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.distributor')
|
||||
%th
|
||||
= t('.products')
|
||||
= surround '(', ')' do
|
||||
%a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('outgoing')"}
|
||||
%span{'ng-show' => "OrderCycle.showProducts['outgoing']"}= t(:collapse_all)
|
||||
%span{'ng-hide' => "OrderCycle.showProducts['outgoing']"}= t(:expand_all)
|
||||
%th{ ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } }
|
||||
= t('.tags')
|
||||
%th= t('.delivery_details')
|
||||
%th= t('.fees')
|
||||
%th.actions
|
||||
%tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'}
|
||||
= render 'exchange_form', f: f, type: 'distributor'
|
||||
|
||||
- if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator
|
||||
= render 'add_exchange_form', f: f, type: 'distributor'
|
||||
|
||||
.actions
|
||||
%span{'ng-hide' => 'loaded()'}= t(:loading)
|
||||
@@ -888,10 +888,36 @@ en:
|
||||
loading_flash:
|
||||
loading_order_cycles: LOADING ORDER CYCLES
|
||||
loading: LOADING...
|
||||
new:
|
||||
create: "Create"
|
||||
cancel: "Cancel"
|
||||
back_to_list: "Back To List"
|
||||
edit:
|
||||
advanced_settings: Advanced Settings
|
||||
update_and_close: Update and Close
|
||||
choose_products_from: 'Choose Products From:'
|
||||
advanced_settings: "Advanced Settings"
|
||||
save: "Save"
|
||||
save_and_next: "Save and Next"
|
||||
next: "Next"
|
||||
cancel: "Cancel"
|
||||
back_to_list: "Back To List"
|
||||
save_and_back_to_list: "Save and Back to List"
|
||||
choose_products_from: "Choose Products From:"
|
||||
incoming:
|
||||
previous: "Previous"
|
||||
save: "Save"
|
||||
save_and_next: "Save and Next"
|
||||
next: "Next"
|
||||
cancel: "Cancel"
|
||||
back_to_list: "Back To List"
|
||||
outgoing:
|
||||
previous: "Previous"
|
||||
save: "Save"
|
||||
save_and_back_to_list: "Save and Back to List"
|
||||
cancel: "Cancel"
|
||||
back_to_list: "Back To List"
|
||||
wizard_progress:
|
||||
general_settings: "1. General Settings"
|
||||
incoming: "2. Incoming Products"
|
||||
outgoing: "3. Outgoing Products"
|
||||
exchange_form:
|
||||
pickup_time_tip: When orders from this OC will be ready for the customer
|
||||
pickup_instructions_placeholder: "Pick-up instructions"
|
||||
|
||||
@@ -9,6 +9,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
resources :order_cycles do
|
||||
post :bulk_update, on: :collection, as: :bulk_update
|
||||
get :incoming
|
||||
get :outgoing
|
||||
|
||||
member do
|
||||
get :clone
|
||||
|
||||
@@ -111,10 +111,20 @@ module Admin
|
||||
context "when creation is successful" do
|
||||
before { allow(form_mock).to receive(:save) { true } }
|
||||
|
||||
it "returns success: true" do
|
||||
# mock build_resource so that we can control the edit_path
|
||||
OrderCyclesController.class_eval do
|
||||
def build_resource
|
||||
order_cycle = OrderCycle.new
|
||||
order_cycle.id = 1
|
||||
order_cycle
|
||||
end
|
||||
end
|
||||
|
||||
it "returns success: true and a valid edit path" do
|
||||
spree_post :create, params
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['success']).to be true
|
||||
expect(json_response['edit_path']).to eq "/admin/order_cycles/1/incoming"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -196,6 +196,9 @@ feature '
|
||||
click_button 'Add coordinator fee'
|
||||
select 'Coord fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
|
||||
click_button 'Create'
|
||||
expect(page).to have_content 'Your order cycle has been created.'
|
||||
|
||||
# I should not be able to add a blank supplier
|
||||
expect(page).to have_select 'new_supplier_id', selected: ''
|
||||
expect(page).to have_button 'Add supplier', disabled: true
|
||||
@@ -218,6 +221,8 @@ feature '
|
||||
select 'My supplier', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id'
|
||||
select 'Supplier fee', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
click_button 'Save and Next'
|
||||
|
||||
# And I add a distributor with the same products
|
||||
select 'My distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
@@ -239,14 +244,9 @@ feature '
|
||||
select 'My distributor', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id'
|
||||
select 'Distributor fee', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
# And I click Create
|
||||
click_button 'Create'
|
||||
|
||||
# Then my order cycle should have been created
|
||||
expect(page).to have_content 'Your order cycle has been created.'
|
||||
click_button 'Save and Back to List'
|
||||
|
||||
oc = OrderCycle.last
|
||||
|
||||
toggle_columns "Producers", "Shops"
|
||||
|
||||
expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos"
|
||||
@@ -316,9 +316,6 @@ feature '
|
||||
fill_in 'order_cycle_orders_open_at', with: order_cycle_opening_time
|
||||
fill_in 'order_cycle_orders_close_at', with: order_cycle_closing_time
|
||||
|
||||
# CAN'T CHANGE COORDINATOR ANYMORE
|
||||
# select 'My coordinator', from: 'order_cycle_coordinator_id'
|
||||
|
||||
# And I configure some coordinator fees
|
||||
click_button 'Add coordinator fee'
|
||||
select 'Coord fee 1', from: 'order_cycle_coordinator_fee_0_id'
|
||||
@@ -327,6 +324,9 @@ feature '
|
||||
click_link 'order_cycle_coordinator_fee_2_remove'
|
||||
select 'Coord fee 2', from: 'order_cycle_coordinator_fee_1_id'
|
||||
|
||||
click_button 'Save and Next'
|
||||
expect(page).to have_content 'Your order cycle has been updated.'
|
||||
|
||||
# And I add a supplier and some products
|
||||
select 'My supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
@@ -347,6 +347,8 @@ feature '
|
||||
select 'My supplier', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_id'
|
||||
select 'Supplier fee 2', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
click_button 'Save and Next'
|
||||
|
||||
# And I add a distributor and some products
|
||||
select 'My distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
@@ -378,15 +380,10 @@ feature '
|
||||
select 'My distributor', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_id'
|
||||
select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
|
||||
|
||||
# And I click Update
|
||||
expect(page).to have_selector "#save-bar"
|
||||
click_button 'Update and Close'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
expect(page).to have_content 'Your order cycle has been updated.'
|
||||
click_button 'Save and Back to List'
|
||||
|
||||
oc = OrderCycle.last
|
||||
|
||||
toggle_columns "Producers", "Shops"
|
||||
|
||||
expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos"
|
||||
@@ -439,6 +436,8 @@ feature '
|
||||
expect(page.find('#order_cycle_orders_close_at').value).to eq(oc.orders_close_at.to_s)
|
||||
expect(page).to have_content "COORDINATOR #{oc.coordinator.name}"
|
||||
|
||||
click_button 'Next'
|
||||
|
||||
# And I should see the suppliers
|
||||
expect(page).to have_selector 'td.supplier_name', text: oc.suppliers.first.name
|
||||
expect(page).to have_selector 'td.supplier_name', text: oc.suppliers.last.name
|
||||
@@ -465,6 +464,8 @@ feature '
|
||||
expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_id', selected: supplier.name
|
||||
expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_fee_id', selected: supplier.enterprise_fees.first.name
|
||||
|
||||
click_button 'Next'
|
||||
|
||||
# And I should see the distributors
|
||||
expect(page).to have_selector 'td.distributor_name', text: oc.distributors.first.name
|
||||
expect(page).to have_selector 'td.distributor_name', text: oc.distributors.last.name
|
||||
@@ -505,13 +506,15 @@ feature '
|
||||
|
||||
# When I edit the first order cycle, the exchange should appear as incoming
|
||||
quick_login_as_admin
|
||||
visit edit_admin_order_cycle_path(oc_incoming)
|
||||
expect(page).to have_selector 'table.exchanges tr.supplier'
|
||||
visit admin_order_cycle_incoming_path(oc_incoming)
|
||||
expect(page).to have_selector 'table.exchanges tr.supplier'
|
||||
visit admin_order_cycle_outgoing_path(oc_incoming)
|
||||
expect(page).not_to have_selector 'table.exchanges tr.distributor'
|
||||
|
||||
# And when I edit the second order cycle, the exchange should appear as outgoing
|
||||
visit edit_admin_order_cycle_path(oc_outgoing)
|
||||
expect(page).to have_selector 'table.exchanges tr.distributor'
|
||||
visit admin_order_cycle_outgoing_path(oc_outgoing)
|
||||
expect(page).to have_selector 'table.exchanges tr.distributor'
|
||||
visit admin_order_cycle_incoming_path(oc_outgoing)
|
||||
expect(page).not_to have_selector 'table.exchanges tr.supplier'
|
||||
end
|
||||
|
||||
@@ -689,6 +692,9 @@ feature '
|
||||
visit admin_order_cycles_path
|
||||
click_link 'New Order Cycle'
|
||||
|
||||
[distributor_unmanaged.name, supplier_managed.name, supplier_unmanaged.name].each do |enterprise_name|
|
||||
expect(page).not_to have_select 'coordinator_id', with_options: [enterprise_name]
|
||||
end
|
||||
select2_select 'Managed distributor', from: 'coordinator_id'
|
||||
click_button "Continue >"
|
||||
|
||||
@@ -698,6 +704,13 @@ feature '
|
||||
expect(page).not_to have_select2 'schedule_ids', with_options: [schedule_of_other_managed_distributor.name]
|
||||
multi_select2_select schedule.name, from: 'schedule_ids'
|
||||
|
||||
click_button 'Add coordinator fee'
|
||||
select 'Managed distributor fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
expect(page).to have_select 'new_supplier_id'
|
||||
expect(page).not_to have_select 'new_supplier_id', with_options: [supplier_unmanaged.name]
|
||||
select 'Managed supplier', from: 'new_supplier_id'
|
||||
click_button 'Add supplier'
|
||||
select 'Permitted supplier', from: 'new_supplier_id'
|
||||
@@ -706,9 +719,10 @@ feature '
|
||||
select_incoming_variant supplier_managed, 0, variant_managed
|
||||
select_incoming_variant supplier_permitted, 1, variant_permitted
|
||||
|
||||
click_button 'Add coordinator fee'
|
||||
select 'Managed distributor fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
click_button 'Save and Next'
|
||||
|
||||
expect(page).to have_select 'new_distributor_id'
|
||||
expect(page).not_to have_select 'new_distributor_id', with_options: [distributor_unmanaged.name]
|
||||
select 'Managed distributor', from: 'new_distributor_id'
|
||||
click_button 'Add distributor'
|
||||
select 'Permitted distributor', from: 'new_distributor_id'
|
||||
@@ -719,24 +733,15 @@ feature '
|
||||
fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'pickup time 2'
|
||||
fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'pickup instructions'
|
||||
|
||||
# Should only have suppliers / distributors listed which the user is managing or
|
||||
# has E2E permission to add products to order cycles
|
||||
expect(page).not_to have_select 'new_supplier_id', with_options: [supplier_unmanaged.name]
|
||||
expect(page).not_to have_select 'new_distributor_id', with_options: [distributor_unmanaged.name]
|
||||
|
||||
[distributor_unmanaged.name, supplier_managed.name, supplier_unmanaged.name].each do |enterprise_name|
|
||||
expect(page).not_to have_select 'order_cycle_coordinator_id', with_options: [enterprise_name]
|
||||
end
|
||||
|
||||
page.find("table.exchanges tr.distributor-#{distributor_managed.id} td.tags").click
|
||||
within ".exchange-tags" do
|
||||
find(:css, "tags-input .tags input").set "wholesale\n"
|
||||
end
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
expect(flash_message).to eq("Your order cycle has been created.")
|
||||
click_button 'Save and Back to List'
|
||||
order_cycle = OrderCycle.find_by_name('My order cycle')
|
||||
expect(page).to have_input "oc#{order_cycle.id}[name]", value: order_cycle.name
|
||||
|
||||
expect(order_cycle.suppliers).to match_array [supplier_managed, supplier_permitted]
|
||||
expect(order_cycle.coordinator).to eq(distributor_managed)
|
||||
expect(order_cycle.distributors).to match_array [distributor_managed, distributor_permitted]
|
||||
@@ -745,39 +750,6 @@ feature '
|
||||
expect(exchange.tag_list).to eq(["wholesale"])
|
||||
end
|
||||
|
||||
scenario "editing an order cycle we can see (and for now, edit) all exchanges in the order cycle" do
|
||||
# TODO: when we add the editable scope to variant permissions, we should test that
|
||||
# exchanges with enterprises who have not granted P-OC to the coordinator are not
|
||||
# editable, but at this point we cannot distiguish between visible and editable
|
||||
# variants.
|
||||
|
||||
oc = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
|
||||
|
||||
visit edit_admin_order_cycle_path(oc)
|
||||
|
||||
fill_in 'order_cycle_name', with: 'Coordinated'
|
||||
|
||||
# I should be able to see but not edit exchanges for supplier_unmanaged or distributor_unmanaged
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_managed.id}"
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_permitted.id}"
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_unmanaged.id}"
|
||||
expect(page).to have_selector 'tr.supplier', count: 3
|
||||
|
||||
expect(page).to have_selector "tr.distributor-#{distributor_managed.id}"
|
||||
expect(page).to have_selector "tr.distributor-#{distributor_permitted.id}"
|
||||
expect(page).to have_selector "tr.distributor-#{distributor_unmanaged.id}"
|
||||
expect(page).to have_selector 'tr.distributor', count: 3
|
||||
|
||||
# When I save, then those exchanges should remain
|
||||
click_button 'Update'
|
||||
expect(page).to have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
expect(oc.coordinator).to eq(distributor_managed)
|
||||
expect(oc.distributors).to match_array [distributor_managed, distributor_permitted, distributor_unmanaged]
|
||||
end
|
||||
|
||||
scenario "editing an order cycle" do
|
||||
oc = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
|
||||
distributor_managed.update_attribute(:enable_subscriptions, true)
|
||||
@@ -788,15 +760,18 @@ feature '
|
||||
multi_select2_select schedule.name, from: 'schedule_ids'
|
||||
expect(page).not_to have_select2 'schedule_ids', with_options: [schedule_of_other_managed_distributor.name]
|
||||
|
||||
# When I remove all the exchanges and save
|
||||
click_button 'Save and Next'
|
||||
|
||||
# When I remove all incoming exchanges
|
||||
page.find("tr.supplier-#{supplier_managed.id} a.remove-exchange").click
|
||||
page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click
|
||||
click_button 'Save and Next'
|
||||
|
||||
# And I remove all outgoing exchanges
|
||||
page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click
|
||||
page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click
|
||||
click_button 'Update'
|
||||
|
||||
# Then the exchanges should be removed
|
||||
expect(page).to have_content "Your order cycle has been updated."
|
||||
click_button 'Save and Back to List'
|
||||
expect(page).to have_input "oc#{oc.id}[name]", value: oc.name
|
||||
|
||||
oc.reload
|
||||
expect(oc.suppliers).to eq([supplier_unmanaged])
|
||||
@@ -848,14 +823,14 @@ feature '
|
||||
{ distributor_managed.id.to_s => [v1.id] }
|
||||
end
|
||||
|
||||
visit edit_admin_order_cycle_path(oc)
|
||||
|
||||
# I should only see exchanges for supplier_managed AND
|
||||
# distributor_managed and distributor_permitted (who I have given permission to) AND
|
||||
# and distributor_unmanaged (who distributes my products)
|
||||
visit admin_order_cycle_incoming_path(oc)
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_managed.id}"
|
||||
expect(page).to have_selector 'tr.supplier', count: 1
|
||||
|
||||
visit admin_order_cycle_outgoing_path(oc)
|
||||
expect(page).to have_selector "tr.distributor-#{distributor_managed.id}"
|
||||
expect(page).to have_selector "tr.distributor-#{distributor_permitted.id}"
|
||||
expect(page).to have_selector 'tr.distributor', count: 2
|
||||
@@ -875,7 +850,7 @@ feature '
|
||||
expect(page).not_to have_selector "table.exchanges tr.distributor-#{distributor_managed.id} td.tags"
|
||||
|
||||
# When I save, any exchanges that I can't manage remain
|
||||
click_button 'Update'
|
||||
click_button 'Save'
|
||||
expect(page).to have_content "Your order cycle has been updated."
|
||||
|
||||
oc.reload
|
||||
@@ -916,15 +891,15 @@ feature '
|
||||
{ supplier_managed.id.to_s => [v1.id] }
|
||||
end
|
||||
|
||||
visit edit_admin_order_cycle_path(oc)
|
||||
|
||||
# I should see exchanges for my_distributor, and the incoming exchanges supplying the variants in it
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_managed.id}"
|
||||
expect(page).to have_selector 'tr.supplier', count: 1
|
||||
|
||||
visit admin_order_cycle_outgoing_path(oc)
|
||||
expect(page).to have_selector "tr.distributor-#{my_distributor.id}"
|
||||
expect(page).to have_selector 'tr.distributor', count: 1
|
||||
|
||||
visit admin_order_cycle_incoming_path(oc)
|
||||
expect(page).to have_selector "tr.supplier-#{supplier_managed.id}"
|
||||
expect(page).to have_selector 'tr.supplier', count: 1
|
||||
|
||||
# Open the products list for managed_supplier's incoming exchange
|
||||
within "tr.supplier-#{supplier_managed.id}" do
|
||||
page.find("td.products").click
|
||||
@@ -937,12 +912,12 @@ feature '
|
||||
# I should be able to see but not toggle v2, because I don't have permission
|
||||
expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true
|
||||
|
||||
expect(page).to have_selector "table.exchanges tr.distributor-#{my_distributor.id} td.tags"
|
||||
|
||||
# When I save, any exchange that I can't manage remains
|
||||
click_button 'Update'
|
||||
click_button 'Save and Next'
|
||||
expect(page).to have_content "Your order cycle has been updated."
|
||||
|
||||
expect(page).to have_selector "table.exchanges tr.distributor-#{my_distributor.id} td.tags"
|
||||
|
||||
oc.reload
|
||||
expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
|
||||
expect(oc.coordinator).to eq(distributor_managed)
|
||||
@@ -1099,11 +1074,11 @@ feature '
|
||||
select 'that fee', from: 'order_cycle_coordinator_fee_0_id'
|
||||
|
||||
# When I update, or update and close, both work
|
||||
click_button 'Update'
|
||||
click_button 'Save'
|
||||
expect(page).to have_content 'Your order cycle has been updated.'
|
||||
|
||||
fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'yyz'
|
||||
click_button 'Update and Close'
|
||||
click_button 'Save and Back to List'
|
||||
|
||||
# Then my order cycle should have been updated
|
||||
expect(page).to have_content 'Your order cycle has been updated.'
|
||||
|
||||
@@ -8,46 +8,23 @@ describe 'AdminCreateOrderCycleCtrl', ->
|
||||
|
||||
beforeEach ->
|
||||
scope =
|
||||
order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty'])
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
OrderCycle =
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
|
||||
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
|
||||
toggleProducts: jasmine.createSpy('toggleProducts')
|
||||
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
removeExchange: jasmine.createSpy('removeExchange')
|
||||
addCoordinatorFee: jasmine.createSpy('addCoordinatorFee')
|
||||
removeCoordinatorFee: jasmine.createSpy('removeCoordinatorFee')
|
||||
addExchangeFee: jasmine.createSpy('addExchangeFee')
|
||||
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
|
||||
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
|
||||
create: jasmine.createSpy('create')
|
||||
new: jasmine.createSpy('new').and.returnValue "my order cycle"
|
||||
Enterprise =
|
||||
index: jasmine.createSpy('index').and.returnValue('enterprises list')
|
||||
supplied_products: 'supplied products'
|
||||
suppliedVariants: jasmine.createSpy('suppliedVariants').and.returnValue('supplied variants')
|
||||
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy('index').and.returnValue('enterprise fees list')
|
||||
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminCreateOrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
|
||||
it 'Loads enterprises and supplied products', ->
|
||||
it 'Loads enterprises', ->
|
||||
expect(Enterprise.index).toHaveBeenCalled()
|
||||
expect(scope.enterprises).toEqual('enterprises list')
|
||||
expect(scope.supplied_products).toEqual('supplied products')
|
||||
|
||||
it 'Loads enterprise fees', ->
|
||||
expect(EnterpriseFee.index).toHaveBeenCalled()
|
||||
@@ -56,104 +33,6 @@ describe 'AdminCreateOrderCycleCtrl', ->
|
||||
it 'Loads order cycles', ->
|
||||
expect(scope.order_cycle).toEqual('my order cycle')
|
||||
|
||||
describe 'Reporting when all resources are loaded', ->
|
||||
beforeEach inject (RequestMonitor) ->
|
||||
RequestMonitor.loading = false
|
||||
Enterprise.loaded = true
|
||||
EnterpriseFee.loaded = true
|
||||
OrderCycle.loaded = true
|
||||
|
||||
it 'returns true when all resources are loaded', ->
|
||||
expect(scope.loaded()).toBe(true)
|
||||
|
||||
it 'returns false otherwise', ->
|
||||
EnterpriseFee.loaded = false
|
||||
expect(scope.loaded()).toBe(false)
|
||||
|
||||
it "delegates suppliedVariants to Enterprise", ->
|
||||
expect(scope.suppliedVariants('enterprise_id')).toEqual('supplied variants')
|
||||
expect(Enterprise.suppliedVariants).toHaveBeenCalledWith('enterprise_id')
|
||||
|
||||
it 'Delegates exchangeSelectedVariants to OrderCycle', ->
|
||||
expect(scope.exchangeSelectedVariants('exchange')).toEqual('variants selected')
|
||||
expect(OrderCycle.exchangeSelectedVariants).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it "delegates setExchangeVariants to OrderCycle", ->
|
||||
scope.setExchangeVariants('exchange', 'variants', 'selected')
|
||||
expect(OrderCycle.setExchangeVariants).toHaveBeenCalledWith('exchange', 'variants', 'selected')
|
||||
|
||||
it 'Delegates enterpriseTotalVariants to Enterprise', ->
|
||||
expect(scope.enterpriseTotalVariants('enterprise')).toEqual('variants total')
|
||||
expect(Enterprise.totalVariants).toHaveBeenCalledWith('enterprise')
|
||||
|
||||
it 'Delegates productSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.productSuppliedToOrderCycle('product')).toEqual('product supplied')
|
||||
expect(OrderCycle.productSuppliedToOrderCycle).toHaveBeenCalledWith('product')
|
||||
|
||||
it 'Delegates variantSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
|
||||
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Delegates exchangeDirection to OrderCycle', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle that have fees', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
2: {id: 2, name: 'Pepper Tree Place'}
|
||||
3: {id: 3, name: 'South East'}
|
||||
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2])
|
||||
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
|
||||
expect(scope.enterprisesWithFees()).toEqual([
|
||||
{id: 2, name: 'Pepper Tree Place'}
|
||||
])
|
||||
|
||||
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
|
||||
scope.enterpriseFeesForEnterprise('123')
|
||||
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
|
||||
|
||||
it 'Adds order cycle suppliers', ->
|
||||
scope.new_supplier_id = 'new supplier id'
|
||||
scope.addSupplier(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
|
||||
|
||||
it 'Adds order cycle distributors', ->
|
||||
scope.new_distributor_id = 'new distributor id'
|
||||
scope.addDistributor(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
|
||||
|
||||
it 'Removes order cycle exchanges', ->
|
||||
scope.removeExchange(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Adds coordinator fees', ->
|
||||
scope.addCoordinatorFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addCoordinatorFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes coordinator fees', ->
|
||||
scope.removeCoordinatorFee(event, 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeCoordinatorFee).toHaveBeenCalledWith(0)
|
||||
|
||||
it 'Adds exchange fees', ->
|
||||
scope.addExchangeFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addExchangeFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes exchange fees', ->
|
||||
scope.removeExchangeFee(event, 'exchange', 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
|
||||
|
||||
it 'Removes distribution of a variant', ->
|
||||
scope.removeDistributionOfVariant('variant')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Submits the order cycle via OrderCycle create', ->
|
||||
eventMock = {preventDefault: jasmine.createSpy()}
|
||||
scope.submit(eventMock,'/admin/order_cycles')
|
||||
|
||||
@@ -18,29 +18,12 @@ describe 'AdminEditOrderCycleCtrl', ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
OrderCycle =
|
||||
load: jasmine.createSpy('load')
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
|
||||
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
|
||||
toggleProducts: jasmine.createSpy('toggleProducts')
|
||||
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
removeExchange: jasmine.createSpy('removeExchange')
|
||||
addCoordinatorFee: jasmine.createSpy('addCoordinatorFee')
|
||||
removeCoordinatorFee: jasmine.createSpy('removeCoordinatorFee')
|
||||
addExchangeFee: jasmine.createSpy('addExchangeFee')
|
||||
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
|
||||
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
|
||||
update: jasmine.createSpy('update')
|
||||
Enterprise =
|
||||
index: jasmine.createSpy('index').and.returnValue('enterprises list')
|
||||
supplied_products: 'supplied products'
|
||||
suppliedVariants: jasmine.createSpy('suppliedVariants').and.returnValue('supplied variants')
|
||||
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
|
||||
EnterpriseFee =
|
||||
index: jasmine.createSpy('index').and.returnValue('enterprise fees list')
|
||||
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
@@ -50,7 +33,6 @@ describe 'AdminEditOrderCycleCtrl', ->
|
||||
it 'Loads enterprises and supplied products', ->
|
||||
expect(Enterprise.index).toHaveBeenCalled()
|
||||
expect(scope.enterprises).toEqual('enterprises list')
|
||||
expect(scope.supplied_products).toEqual('supplied products')
|
||||
|
||||
it 'Loads enterprise fees', ->
|
||||
expect(EnterpriseFee.index).toHaveBeenCalled()
|
||||
@@ -59,107 +41,12 @@ describe 'AdminEditOrderCycleCtrl', ->
|
||||
it 'Loads order cycles', ->
|
||||
expect(OrderCycle.load).toHaveBeenCalledWith('27')
|
||||
|
||||
describe 'Reporting when all resources are loaded', ->
|
||||
beforeEach inject (RequestMonitor) ->
|
||||
RequestMonitor.loading = false
|
||||
Enterprise.loaded = true
|
||||
EnterpriseFee.loaded = true
|
||||
OrderCycle.loaded = true
|
||||
|
||||
it 'returns true when all resources are loaded', ->
|
||||
expect(scope.loaded()).toBe(true)
|
||||
|
||||
it 'returns false otherwise', ->
|
||||
EnterpriseFee.loaded = false
|
||||
expect(scope.loaded()).toBe(false)
|
||||
|
||||
it "delegates suppliedVariants to Enterprise", ->
|
||||
expect(scope.suppliedVariants('enterprise_id')).toEqual('supplied variants')
|
||||
expect(Enterprise.suppliedVariants).toHaveBeenCalledWith('enterprise_id')
|
||||
|
||||
it 'Delegates exchangeSelectedVariants to OrderCycle', ->
|
||||
expect(scope.exchangeSelectedVariants('exchange')).toEqual('variants selected')
|
||||
expect(OrderCycle.exchangeSelectedVariants).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it "delegates setExchangeVariants to OrderCycle", ->
|
||||
scope.setExchangeVariants('exchange', 'variants', 'selected')
|
||||
expect(OrderCycle.setExchangeVariants).toHaveBeenCalledWith('exchange', 'variants', 'selected')
|
||||
|
||||
it 'Delegates totalVariants to Enterprise', ->
|
||||
expect(scope.enterpriseTotalVariants('enterprise')).toEqual('variants total')
|
||||
expect(Enterprise.totalVariants).toHaveBeenCalledWith('enterprise')
|
||||
|
||||
it 'Delegates productSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.productSuppliedToOrderCycle('product')).toEqual('product supplied')
|
||||
expect(OrderCycle.productSuppliedToOrderCycle).toHaveBeenCalledWith('product')
|
||||
|
||||
it 'Delegates variantSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
|
||||
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Delegates exchangeDirection to OrderCycle', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle that have fees', ->
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
2: {id: 2, name: 'Pepper Tree Place'}
|
||||
3: {id: 3, name: 'South East'}
|
||||
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2])
|
||||
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
|
||||
expect(scope.enterprisesWithFees()).toEqual([
|
||||
{id: 2, name: 'Pepper Tree Place'}
|
||||
])
|
||||
|
||||
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
|
||||
scope.enterpriseFeesForEnterprise('123')
|
||||
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
|
||||
|
||||
it 'Adds order cycle suppliers', ->
|
||||
scope.new_supplier_id = 'new supplier id'
|
||||
scope.addSupplier(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
|
||||
|
||||
it 'Adds order cycle distributors', ->
|
||||
scope.new_distributor_id = 'new distributor id'
|
||||
scope.addDistributor(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
|
||||
|
||||
it 'Removes order cycle exchanges', ->
|
||||
scope.removeExchange(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange')
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Adds coordinator fees', ->
|
||||
scope.addCoordinatorFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addCoordinatorFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes coordinator fees', ->
|
||||
scope.removeCoordinatorFee(event, 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeCoordinatorFee).toHaveBeenCalledWith(0)
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Adds exchange fees', ->
|
||||
scope.addExchangeFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addExchangeFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes exchange fees', ->
|
||||
scope.removeExchangeFee(event, 'exchange', 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Removes distribution of a variant', ->
|
||||
scope.removeDistributionOfVariant('variant')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
|
||||
|
||||
it 'Submits the order cycle via OrderCycle update', ->
|
||||
eventMock = {preventDefault: jasmine.createSpy()}
|
||||
scope.submit(eventMock,'/admin/order_cycles')
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
describe 'AdminOrderCycleIncomingCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
location = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
EnterpriseFee = null
|
||||
|
||||
beforeEach ->
|
||||
scope =
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
Enterprise =
|
||||
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminOrderCycleIncomingCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
it 'Delegates totalVariants to Enterprise', ->
|
||||
expect(scope.enterpriseTotalVariants('enterprise')).toEqual('variants total')
|
||||
expect(Enterprise.totalVariants).toHaveBeenCalledWith('enterprise')
|
||||
@@ -0,0 +1,63 @@
|
||||
describe 'AdminOrderCycleBasicCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
location = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
EnterpriseFee = null
|
||||
|
||||
beforeEach ->
|
||||
scope =
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
OrderCycle =
|
||||
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
|
||||
addCoordinatorFee: jasmine.createSpy('addCoordinatorFee')
|
||||
removeCoordinatorFee: jasmine.createSpy('removeCoordinatorFee')
|
||||
Enterprise =
|
||||
suppliedVariants: jasmine.createSpy('suppliedVariants').and.returnValue('supplied variants')
|
||||
EnterpriseFee =
|
||||
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminOrderCycleBasicCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
describe 'Reporting when all resources are loaded', ->
|
||||
beforeEach inject (RequestMonitor) ->
|
||||
RequestMonitor.loading = false
|
||||
Enterprise.loaded = true
|
||||
EnterpriseFee.loaded = true
|
||||
OrderCycle.loaded = true
|
||||
|
||||
it 'returns true when all resources are loaded', ->
|
||||
expect(scope.loaded()).toBe(true)
|
||||
|
||||
it 'returns false otherwise', ->
|
||||
EnterpriseFee.loaded = false
|
||||
expect(scope.loaded()).toBe(false)
|
||||
|
||||
it "delegates suppliedVariants to Enterprise", ->
|
||||
expect(scope.suppliedVariants('enterprise_id')).toEqual('supplied variants')
|
||||
expect(Enterprise.suppliedVariants).toHaveBeenCalledWith('enterprise_id')
|
||||
|
||||
it "delegates setExchangeVariants to OrderCycle", ->
|
||||
scope.setExchangeVariants('exchange', 'variants', 'selected')
|
||||
expect(OrderCycle.setExchangeVariants).toHaveBeenCalledWith('exchange', 'variants', 'selected')
|
||||
|
||||
it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', ->
|
||||
scope.enterpriseFeesForEnterprise('123')
|
||||
expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123)
|
||||
|
||||
it 'Adds coordinator fees', ->
|
||||
scope.addCoordinatorFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addCoordinatorFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes coordinator fees', ->
|
||||
scope.removeCoordinatorFee(event, 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeCoordinatorFee).toHaveBeenCalledWith(0)
|
||||
@@ -0,0 +1,95 @@
|
||||
describe 'AdminOrderCycleExchangesCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
location = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
EnterpriseFee = null
|
||||
|
||||
beforeEach ->
|
||||
scope =
|
||||
order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty', '$setPristine'])
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
event =
|
||||
preventDefault: jasmine.createSpy('preventDefault')
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
OrderCycle =
|
||||
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
|
||||
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
|
||||
addSupplier: jasmine.createSpy('addSupplier')
|
||||
addDistributor: jasmine.createSpy('addDistributor')
|
||||
removeExchange: jasmine.createSpy('removeExchange')
|
||||
addExchangeFee: jasmine.createSpy('addExchangeFee')
|
||||
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
|
||||
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
|
||||
Enterprise =
|
||||
supplied_products: 'supplied products'
|
||||
EnterpriseFee =
|
||||
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminOrderCycleExchangesCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
it 'Loads supplied products', ->
|
||||
expect(scope.supplied_products).toEqual('supplied products')
|
||||
|
||||
it 'Delegates exchangeSelectedVariants to OrderCycle', ->
|
||||
expect(scope.exchangeSelectedVariants('exchange')).toEqual('variants selected')
|
||||
expect(OrderCycle.exchangeSelectedVariants).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Delegates exchangeDirection to OrderCycle', ->
|
||||
expect(scope.exchangeDirection('exchange')).toEqual('exchange direction')
|
||||
expect(OrderCycle.exchangeDirection).toHaveBeenCalledWith('exchange')
|
||||
|
||||
it 'Finds enterprises participating in the order cycle that have fees', ->
|
||||
# this is inhetited from order_cycle_basic_controller
|
||||
scope.enterpriseFeesForEnterprise = (enterprise_id) ->
|
||||
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
|
||||
scope.enterprises =
|
||||
1: {id: 1, name: 'Eaterprises'}
|
||||
2: {id: 2, name: 'Pepper Tree Place'}
|
||||
3: {id: 3, name: 'South East'}
|
||||
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2])
|
||||
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
|
||||
expect(scope.enterprisesWithFees()).toEqual([
|
||||
{id: 2, name: 'Pepper Tree Place'}
|
||||
])
|
||||
|
||||
it 'Removes order cycle exchanges', ->
|
||||
scope.removeExchange(event, 'exchange')
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchange).toHaveBeenCalledWith('exchange')
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Adds exchange fees', ->
|
||||
scope.addExchangeFee(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addExchangeFee).toHaveBeenCalled()
|
||||
|
||||
it 'Removes exchange fees', ->
|
||||
scope.removeExchangeFee(event, 'exchange', 0)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
|
||||
expect(scope.order_cycle_form.$dirty).toEqual true
|
||||
|
||||
it 'Adds order cycle suppliers', ->
|
||||
scope.new_supplier_id = 'new supplier id'
|
||||
scope.addSupplier(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addSupplier).toHaveBeenCalledWith('new supplier id')
|
||||
|
||||
it 'Adds order cycle distributors', ->
|
||||
scope.new_distributor_id = 'new distributor id'
|
||||
scope.addDistributor(event)
|
||||
expect(event.preventDefault).toHaveBeenCalled()
|
||||
expect(OrderCycle.addDistributor).toHaveBeenCalledWith('new distributor id')
|
||||
|
||||
it 'Removes distribution of a variant', ->
|
||||
scope.removeDistributionOfVariant('variant')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
describe 'AdminOrderCycleOutgoingCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
location = null
|
||||
OrderCycle = null
|
||||
Enterprise = null
|
||||
EnterpriseFee = null
|
||||
|
||||
beforeEach ->
|
||||
scope =
|
||||
$watch: jasmine.createSpy('$watch')
|
||||
location =
|
||||
absUrl: ->
|
||||
'example.com/admin/order_cycles/27/edit'
|
||||
OrderCycle =
|
||||
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied')
|
||||
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
|
||||
ocInstance = {}
|
||||
|
||||
module('admin.orderCycles')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'AdminOrderCycleOutgoingCtrl', {$scope: scope, $location: location, OrderCycle: OrderCycle, Enterprise: Enterprise, EnterpriseFee: EnterpriseFee, ocInstance: ocInstance}
|
||||
|
||||
it 'Delegates productSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.productSuppliedToOrderCycle('product')).toEqual('product supplied')
|
||||
expect(OrderCycle.productSuppliedToOrderCycle).toHaveBeenCalledWith('product')
|
||||
|
||||
it 'Delegates variantSuppliedToOrderCycle to OrderCycle', ->
|
||||
expect(scope.variantSuppliedToOrderCycle('variant')).toEqual('variant supplied')
|
||||
expect(OrderCycle.variantSuppliedToOrderCycle).toHaveBeenCalledWith('variant')
|
||||
@@ -348,17 +348,28 @@ describe 'OrderCycle service', ->
|
||||
beforeEach ->
|
||||
spyOn(OrderCycle, 'confirmNoDistributors').and.returnValue true
|
||||
|
||||
it 'redirects to the destination page on success', ->
|
||||
it 'redirects to the given destination on success', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
$httpBackend.expectPOST('/admin/order_cycles.json', {
|
||||
order_cycle: 'this is the submit data'
|
||||
}).respond {success: true}
|
||||
}).respond {success: true, edit_path: "/edit/path"}
|
||||
|
||||
OrderCycle.create('/destination/page')
|
||||
$httpBackend.flush()
|
||||
expect($window.location).toEqual('/destination/page')
|
||||
|
||||
it 'redirects to the edit_path on success if no destination is given', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
$httpBackend.expectPOST('/admin/order_cycles.json', {
|
||||
order_cycle: 'this is the submit data'
|
||||
}).respond {success: true, edit_path: "/edit/path"}
|
||||
|
||||
OrderCycle.create()
|
||||
$httpBackend.flush()
|
||||
expect($window.location).toEqual('/edit/path')
|
||||
|
||||
it 'does not redirect on error', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
|
||||
Reference in New Issue
Block a user