Merge branch 'new-product-form'

Conflicts:
	app/assets/javascripts/admin/admin.js.coffee
This commit is contained in:
Rohan Mitchell
2014-05-24 17:14:32 +10:00
40 changed files with 341 additions and 103 deletions

View File

@@ -1,3 +1,3 @@
window.Admin = angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown"]).config ($httpProvider) ->
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown"]).config ($httpProvider) ->
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"

View File

@@ -16,5 +16,6 @@
//= require admin/spree_auth
//= require admin/spree_promo
//= require ./admin
//= require ./products/products
//= require_tree .

View File

@@ -1,4 +1,4 @@
Admin.controller "AdminOrderMgmtCtrl", [
angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges"
($scope, $http, dataFetcher, blankOption, pendingChanges) ->

View File

@@ -1,4 +1,4 @@
Admin.controller "AdminProductEditCtrl", [
angular.module("ofn.admin").controller "AdminProductEditCtrl", [
"$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts"
($scope, $timeout, $http, dataFetcher, DirtyProducts) ->
$scope.updateStatusMessage =

View File

@@ -0,0 +1,5 @@
angular.module("ofn.admin").controller "enterprisesDashboardCtrl", [
"$scope"
($scope) ->
$scope.activeTab = "hubs"
]

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
angular.module("ofn.admin").directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
restrict: "A"
scope:
path: "@ofnConfirmLinkPath"

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
angular.module("ofn.admin").directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
restrict: "A"
link: (scope, element, attrs) ->
handler = ofnConfirmHandler scope, -> scope.fetchOrders()

View File

@@ -1,4 +1,4 @@
Admin.directive "datepicker", ->
angular.module("ofn.admin").directive "datepicker", ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
element.datepicker

View File

@@ -1,4 +1,4 @@
Admin.directive "datetimepicker", ->
angular.module("ofn.admin").directive "datetimepicker", ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
element.datetimepicker

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnDecimal", ->
angular.module("ofn.admin").directive "ofnDecimal", ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
numRegExp = /^\d+(\.\d+)?$/

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnLineItemUpdAttr", [
angular.module("ofn.admin").directive "ofnLineItemUpdAttr", [
"switchClass", "pendingChanges"
(switchClass, pendingChanges) ->
require: "ngModel"

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnSelect2MinSearch", ->
angular.module("ofn.admin").directive "ofnSelect2MinSearch", ->
require: 'ngModel'
link: (scope, element, attrs, ngModel) ->
element.select2

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnTaxonAutocomplete", (Taxons) ->
angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) ->
# Adapted from Spree's existing taxon autocompletion
require: "ngModel"
link: (scope,element,attrs,ngModel) ->

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnToggleColumn", ->
angular.module("ofn.admin").directive "ofnToggleColumn", ->
link: (scope, element, attrs) ->
element.addClass "selected" if scope.column.visible
element.click "click", ->

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnToggleVariants", ->
angular.module("ofn.admin").directive "ofnToggleVariants", ->
link: (scope, element, attrs) ->
if scope.displayProperties[scope.product.id].showVariants
element.removeClass "icon-chevron-right"

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) ->
angular.module("ofn.admin").directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
ngModel.$parsers.push (viewValue) ->

View File

@@ -1,4 +1,4 @@
Admin.directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) ->
angular.module("ofn.admin").directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) ->
require: "ngModel"
link: (scope, element, attrs, ngModel) ->
ngModel.$parsers.push (viewValue) ->

View File

@@ -1,4 +1,4 @@
Admin.filter "rangeArray", ->
angular.module("ofn.admin").filter "rangeArray", ->
return (input,start,end) ->
input.push(i) for i in [start..end]
input

View File

@@ -1,4 +1,4 @@
Admin.filter "selectFilter", (blankOption) ->
angular.module("ofn.admin").filter "selectFilter", (blankOption) ->
return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) ->
filtered = []
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) &&

View File

@@ -1,4 +1,4 @@
Admin.filter "variantFilter", ->
angular.module("ofn.admin").filter "variantFilter", ->
return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) ->
filtered = []
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) ||

View File

@@ -0,0 +1 @@
angular.module("admin.products", [])

View File

@@ -0,0 +1,46 @@
angular.module("admin.products")
.controller "unitsCtrl", ($scope) ->
$scope.product = { master: {} }
$scope.$watch ->
$scope.product.variant_unit_with_scale
, ->
if $scope.product.variant_unit_with_scale
match = $scope.product.variant_unit_with_scale.match(/^([^_]+)_([\d\.]+)$/)
if match
$scope.product.variant_unit = match[1]
$scope.product.variant_unit_scale = parseFloat(match[2])
else
$scope.product.variant_unit = $scope.product.variant_unit_with_scale
$scope.product.variant_unit_scale = null
else
$scope.product.variant_unit = $scope.product.variant_unit_scale = null
$scope.$watch ->
$scope.product.master.unit_value_with_description
, ->
if $scope.product.master.hasOwnProperty("unit_value_with_description")
match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/)
if match
$scope.product.master.unit_value = parseFloat(match[1])
$scope.product.master.unit_value = null if isNaN($scope.product.master.unit_value)
$scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale
$scope.product.master.unit_description = match[3]
$scope.variant_unit_options = [
["Weight (g)", "weight_1"],
["Weight (kg)", "weight_1000"],
["Weight (T)", "weight_1000000"],
["Volume (mL)", "volume_0.001"],
["Volume (L)", "volume_1"],
["Volume (ML)", "volume_1000000"],
["Items", "items"]
]
$scope.hasVariants = (product) ->
Object.keys(product.variants).length > 0
$scope.hasUnit = (product) ->
product.variant_unit_with_scale?

View File

@@ -1,2 +1,2 @@
Admin.value "blankOption", ->
angular.module("ofn.admin").value "blankOption", ->
{ id: "0", name: "All" }

View File

@@ -1,4 +1,4 @@
Admin.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) ->
angular.module("ofn.admin").factory "ofnConfirmHandler", (pendingChanges, $compile, $q) ->
return (scope, callback) ->
template = "<div id='dialog-div' style='padding: 10px'><h6>Unsaved changes currently exist, save now or ignore?</h6></div>"
dialogDiv = $compile(template)(scope)

View File

@@ -1,4 +1,4 @@
Admin.factory "dataFetcher", [
angular.module("ofn.admin").factory "dataFetcher", [
"$http", "$q"
($http, $q) ->
return (dataLocation) ->

View File

@@ -1,4 +1,4 @@
Admin.factory "dataSubmitter", [
angular.module("ofn.admin").factory "dataSubmitter", [
"$http", "$q", "switchClass"
($http, $q, switchClass) ->
return (changeObj) ->

View File

@@ -1,4 +1,4 @@
Admin.factory "DirtyProducts", ($parse) ->
angular.module("ofn.admin").factory "DirtyProducts", ($parse) ->
# Temporary service to track changes in products on admin bulk product edit
dirtyProducts = {}

View File

@@ -1,4 +1,4 @@
Admin.factory "pendingChanges",[
angular.module("ofn.admin").factory "pendingChanges",[
"dataSubmitter"
(dataSubmitter) ->
pendingChanges: {}

View File

@@ -1,4 +1,4 @@
Admin.factory "switchClass", [
angular.module("ofn.admin").factory "switchClass", [
"$timeout"
($timeout) ->
return (element,classToAdd,removeClasses,timeout) ->

View File

@@ -1,4 +1,4 @@
Admin.factory "Taxons", ($resource) ->
angular.module("ofn.admin").factory "Taxons", ($resource) ->
resource = $resource "/admin/taxons/search"
return {

View File

@@ -4,7 +4,23 @@ div.dashboard_item
.centered
text-align: center
.text-icon
margin-top: 8px
display: block
font-size: 16px
font-weight: bold
color: #fff
padding: 0px 6px
border-radius: 10px
&.green
background-color: #9fc820
&.red
background-color: #DA5354
&.orange
background-color: #DA7F52
div.header
height: 50px
border-radius: 6px 6px 0px 0px
border: 1px solid #5498da
position: relative
@@ -26,16 +42,41 @@ div.dashboard_item
h3
color: #DA7F52
h3
padding: 10px 5px 10px 3%
h3.alpha
height: 100%
padding: 10px 5px 0px 3%
a
border-radius: 0px 4px 0px 0px
margin-left: 8px
height: 100%
padding: 15px 2px 0px 2px
.tabs
height: 30px
border: solid #5498da
border-width: 0px 0px 1px 0px
margin-top: 3px
div.dashboard_tab
cursor: pointer
height: 30px
color: #fff
background-color: #5498da
padding: 5px 5px 0px 5px
text-align: center
font-weight: bold
border: solid #5498da
border-width: 1px 1px 0px 1px
&:hover
background-color: #9fc820
&.selected
color: #5498da
background-color: #fff
.list
max-height: 250px
overflow-y: auto
overflow-x: hidden
.list-title
border: solid #5498da
@@ -50,10 +91,11 @@ div.dashboard_item
.list-item
border: solid #5498da
border-width: 0px 1px 0px 1px
height: 38px
span.alpha
font-weight: bold
margin-left: -3px
padding: 10px 2px 10px 5%
padding: 10px 2px 0px 5%
span.omega
padding-right: 13px
margin-right: -3px
@@ -94,10 +136,13 @@ div.dashboard_item
color: #fff
.icon-ok-sign
color: #fff
.text-icon
&.green
color: #9fc820
background-color: #fff
a.button
color: #fff
padding: 15px 15px
font-size: 110%
font-weight: bold
text-align: center
@@ -110,4 +155,5 @@ div.dashboard_item
&:hover
background-color: #9fc820
&.bottom
border-radius: 0px 0px 6px 6px
border-radius: 0px 0px 6px 6px
padding: 15px 15px

View File

@@ -17,10 +17,22 @@ div.sidebar_item
.list
max-height: 400px
overflow-y: auto
.list-item
overflow-x: hidden
border: solid #5498da
border-width: 0px 1px 0px 1px
&.red
color: #DA5354
border: solid #DA5354
border-width: 0px 3px 0px 3px
.list-item
&.odd
background-color: #fcf6ef
&:hover
background-color: #9fc820
a
color: #DA5354
.list-item
span.alpha
font-weight: bold
margin-left: -3px
@@ -29,16 +41,12 @@ div.sidebar_item
max-width: 160px
text-overflow: ellipsis
span.omega
padding: 8px 13px 8px 0px
padding: 8px 18px 8px 0px
margin-right: -3px
text-align: right
.icon-remove-sign
color: #DA5354
font-size: 18px
&.red
color: #DA5354
border: solid #DA5354
border-width: 0px 3px 0px 3px
&.even
background-color: #fff
&.odd

View File

@@ -123,6 +123,14 @@ class Enterprise < ActiveRecord::Base
self.supplied_products.where('count_on_hand > 0').present?
end
def supplied_and_active_products_on_hand
self.supplied_products.where('spree_products.count_on_hand > 0').active
end
def active_products_in_order_cycles
self.supplied_and_active_products_on_hand.in_an_active_order_cycle
end
def to_param
"#{id}-#{name.parameterize}"
end

View File

@@ -75,6 +75,12 @@ Spree::Product.class_eval do
scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner.
merge(Exchange.outgoing).
where('order_cycles.id = ?', order_cycle) }
scope :in_an_active_order_cycle, lambda { with_order_cycles_inner.
merge(OrderCycle.active).
merge(Exchange.outgoing).
where('order_cycles.id IS NOT NULL') }
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped

View File

@@ -0,0 +1,56 @@
/ replace "fieldset[data-hook='new_product']"
%fieldset{ id: "new_product" }
%legend{align: "center"}= t(:new_product)
.row
= f.field_container :name do
= f.label :name, t(:name)
%span.required *
%br/
= f.text_field :name, :class => 'fullwidth title'
= f.error_message_on :name
.row
.alpha.six.columns
= f.field_container :supplier do
= f.label :supplier
%span.required *
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
= f.error_message_on :supplier
.five.columns
= f.field_container :price do
= f.label :price, t(:price)
%span.required *
%br/
= f.text_field :price, :class => 'fullwidth'
= f.error_message_on :price
.five.columns.omega
= f.field_container :on_hand do
= f.label :on_hand, t(:on_hand)
%span.required *
%br/
= f.text_field :on_hand, :class => 'fullwidth'
= f.error_message_on :on_hand
.row{ 'ng-controller' => 'unitsCtrl' }
.six.columns.alpha
= f.label :variant_unit_with_scale, :units
%select.select2.fullwidth{ id: 'product_variant_unit_with_scale', 'ng-model' => 'product.variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' }
%option{'value' => '', 'ng-hide' => "hasUnit(product)"}
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit', name: 'product[variant_unit]' }
%input{ type: 'hidden', 'ng-value' => 'product.variant_unit_scale', name: 'product[variant_unit_scale]' }
.five.columns
= f.label :product_unit_value_with_description, :value
%input.fullwidth{ id: 'product_unit_value_with_description', 'ng-model' => 'product.master.unit_value_with_description', :type => 'text', :placeholder => 'eg. 2', 'ng-disabled' => "!hasUnit(product)" }
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_value', name: 'product[unit_value]' }
%input{ type: 'hidden', 'ng-value' => 'product.master.unit_description', name: 'product[unit_description]' }
.five.columns.omega{ 'ng-show' => "product.variant_unit_with_scale == 'items'" }
= f.label :product_variant_unit_name, :unit_name
%input.fullwidth{ id: 'product_variant_unit_name','ng-model' => 'product.variant_unit_name', :name => 'product[variant_unit_name]', :placeholder => 'eg. bunches', :type => 'text' }
#product-from-prototype.clearfix{"data-hook" => "product-from-prototype"}
= render :file => 'spree/admin/prototypes/show' if @prototype
= render :partial => 'spree/admin/shared/new_resource_links'
:javascript
angular.element(document.getElementById("new_product")).ready(function() {
angular.bootstrap(document.getElementById("new_product"), ['admin.products']);
});

View File

@@ -1,59 +1,63 @@
- payment_methods_color = @payment_methods.count > 0 ? (@enterprise.payment_methods.count > 0 ? "blue" : "red") : "red"
.sidebar_item.four.columns.alpha#payment_methods
.four.columns.alpha.header{ class: "#{@payment_methods.count > 0 ? "blue" : "red"}" }
.four.columns.alpha.header{ class: "#{payment_methods_color}" }
%span.four.columns.alpha.centered Payment Methods
- if @payment_methods.count > 0
.four.columns.alpha.list
.four.columns.alpha.list{ class: "#{payment_methods_color}" }
- if @payment_methods.count > 0
-# = hidden_field_tag "enterprise[payment_method_ids][]", []
- @payment_methods.each do |payment_method|
%a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_payment_method_path(payment_method)}" }
%span.three.columns.alpha
= payment_method.name
%span.one.column.omega
= f.check_box :payment_method_ids, { :multiple => true }, payment_method.id, nil
- else
.four.columns.alpha.list-item.red
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{new_admin_payment_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" }
= f.check_box :payment_method_ids, { multiple: true }, payment_method.id, nil
- else
.four.columns.alpha.list-item
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{new_admin_payment_method_path}", class: "#{payment_methods_color}" }
CREATE NEW
%span.icon-arrow-right
- shipping_methods_color = @shipping_methods.count > 0 ? (@enterprise.shipping_methods.count > 0 ? "blue" : "red") : "red"
.sidebar_item.four.columns.alpha#shipping_methods
.four.columns.alpha.header{ class: "#{@shipping_methods.count > 0 ? "blue" : "red"}" }
.four.columns.alpha.header{ class: "#{shipping_methods_color}" }
%span.four.columns.alpha.centered Shipping Methods
- if @shipping_methods.count > 0
.four.columns.alpha.list
.four.columns.alpha.list{ class: "#{shipping_methods_color}" }
- if @shipping_methods.count > 0
- @shipping_methods.each do |shipping_method|
%a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_shipping_method_path(shipping_method)}" }
%span.three.columns.alpha
= shipping_method.name
%span.one.column.omega
= f.check_box :shipping_method_ids, { :multiple => true }, shipping_method.id, nil
- else
.four.columns.alpha.list-item.red
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{new_admin_shipping_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" }
- else
.four.columns.alpha.list-item
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{new_admin_shipping_method_path}", class: "#{shipping_methods_color}" }
CREATE NEW
%span.icon-arrow-right
- enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red"
.sidebar_item.four.columns.alpha#enterprise_fees
.four.columns.alpha.header{ class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" }
.four.columns.alpha.header{ class: "#{enterprise_fees_color}" }
%span.four.columns.alpha.centered Enterprise Fees
- if @enterprise_fees.count > 0
.four.columns.alpha.list
.four.columns.alpha.list{ class: "#{enterprise_fees_color}" }
- if @enterprise_fees.count > 0
- @enterprise_fees.each do |enterprise_fee|
%a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.admin_enterprise_fees_path}" }
%span.three.columns.alpha
= enterprise_fee.name
%span.one.column.omega
&nbsp;
- else
.four.columns.alpha.list-item.red
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{main_app.admin_enterprise_fees_path}", class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" }
- else
.four.columns.alpha.list-item.red
%span.three.columns.alpha None Available
%span.one.column.omega
%span.icon-remove-sign
%a.four.columns.alpha.button{ href: "#{main_app.admin_enterprise_fees_path}", class: "#{enterprise_fees_color}" }
CREATE NEW
%span.icon-arrow-right

View File

@@ -1,11 +1,15 @@
%div.dashboard_item.sixteen.columns.alpha#enterprises
%div.dashboard_item.sixteen.columns.alpha#enterprises{ 'ng-app' => 'ofn.admin', 'ng-controller' => "enterprisesDashboardCtrl" }
%div.header.sixteen.columns.alpha{ :class => "#{@enterprises.count > 0 ? "" : "red"}"}
%h3.thirteen.columns.alpha My Enterprises
- if @enterprises.any?
%a.three.columns.omega.icon-plus.button.blue{ href: "#{main_app.new_admin_enterprise_path}" }
%a.three.columns.omega.icon-plus.button.blue.white-bottom{ href: "#{main_app.new_admin_enterprise_path}" }
CREATE NEW
- else
%a.with-tip{ title: "Enterprises are Producers and/or Hubs and are the basic unit of organisation within the Open Food Network." } What's this?
- if @enterprises.any?
%div.sixteen.columns.alpha.tabs
%div.dashboard_tab.eight.columns.alpha.blue{ ng: { class: "{selected: activeTab == 'hubs'}", click: "activeTab = 'hubs'" } } HUBS
%div.dashboard_tab.eight.columns.omega.blue{ ng: { class: "{selected: activeTab == 'producers'}", click: "activeTab = 'producers'" } } PRODUCERS
- if @enterprises.empty?
%div.sixteen.columns.alpha.list-item.red
%span.text.fifteen.columns.alpha You don't have any enterprises yet.
@@ -15,40 +19,69 @@
CREATE A NEW ENTERPRISE
%span.icon-arrow-right
- else
%div.sixteen.columns.alpha.list-title
%span.five.columns.alpha Name
%span.centered.three.columns Payment Methods
%span.centered.three.columns Shipping Methods
%span.centered.three.columns Enterprise Fees
%div.sixteen.columns.alpha.list
- @enterprises.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." }
-else
%span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" }
%span.two.columns.omega.right
%span.icon-arrow-right
%div.hubs_tab{ ng: { show: "activeTab == 'hubs'"} }
%div.sixteen.columns.alpha.list-title
%span.five.columns.alpha Name
%span.centered.three.columns Payment Methods
%span.centered.three.columns Shipping Methods
%span.centered.three.columns Enterprise Fees
%div.sixteen.columns.alpha.list
- @enterprises.is_distributor.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." }
-else
%span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" }
%span.two.columns.omega.right
%span.icon-arrow-right
%div.producers_tab{ ng: { show: "activeTab == 'producers'"} }
%div.list-title.sixteen.columns.alpha
%span.five.columns.alpha Name
%span.centered.three.columns Total Products
%span.centered.three.columns Active Products
%span.centered.three.columns Products in OCs
%div.sixteen.columns.alpha.list
- @enterprises.is_primary_producer.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_products.not_deleted.count > 0 ? "green" : "red" }" }
= enterprise.supplied_products.not_deleted.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_and_active_products_on_hand.count > 0 ? "green" : "red" }" }
= enterprise.supplied_and_active_products_on_hand.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.active_products_in_order_cycles.count > 0 ? "green" : "orange" }" }
= enterprise.active_products_in_order_cycles.count
%span.one.column.omega &nbsp;
%span.two.columns.omega.right
%span.icon-arrow-right
%a.sixteen.columns.alpha.button.bottom.blue{ href: "#{main_app.admin_enterprises_path}" }
MANAGE MY ENTERPRISES
%span.icon-arrow-right

View File

@@ -1,4 +1,4 @@
<%= tab :overview, :route => :admin, :icon => 'icon-dashboard' %>
<%= tab :dashboard, :route => :admin, :icon => 'icon-dashboard' %>
<%= tab :orders, :payments, :creditcard_payments, :shipments, :credit_cards, :return_authorizations, :url => admin_orders_path('q[s]' => 'completed_at desc'), :icon => 'icon-shopping-cart' %>
<%= tab :products , :option_types, :properties, :prototypes, :variants, :product_properties, :taxons, :url => bulk_edit_admin_products_path, :icon => 'icon-th-large' %>
<%= tab :reports, :icon => 'icon-file' %>

View File

@@ -338,6 +338,16 @@ describe Enterprise do
end
end
describe "supplied_and_active_products_on_hand" do
it "find only active products which are in stock" do
supplier = create(:supplier_enterprise)
inactive_product = create(:product, supplier: supplier, on_hand: 1, available_on: Date.tomorrow)
out_of_stock_product = create(:product, supplier: supplier, on_hand: 0, available_on: Date.yesterday)
p1 = create(:product, supplier: supplier, on_hand: 1, available_on: Date.yesterday)
supplier.supplied_and_active_products_on_hand.should == [p1]
end
end
describe "finding variants distributed by the enterprise" do
it "finds the master variant" do
d = create(:distributor_enterprise)

View File

@@ -230,6 +230,20 @@ module Spree
end
end
describe "in_an_active_order_cycle" do
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d2 = create(:distributor_enterprise)
d3 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
p3 = create(:product)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_close_at: 1.day.ago)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow)
Product.in_an_active_order_cycle.should == [p3]
end
end
describe "access roles" do
before(:each) do
@e1 = create(:enterprise)