mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
WIP: Bulk calculation box work with shared resources
This commit is contained in:
@@ -119,7 +119,9 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.quickSearch = ""
|
||||
$scope.bulkActions = [ { name: "Delete", callback: $scope.deleteLineItems } ]
|
||||
$scope.selectedBulkAction = $scope.bulkActions[0]
|
||||
$scope.selectedUnitsProduct = {};
|
||||
$scope.selectedUnitsVariant = {};
|
||||
$scope.sharedResource = false
|
||||
$scope.predicate = ""
|
||||
$scope.reverse = false
|
||||
$scope.optionTabs =
|
||||
@@ -229,7 +231,8 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
changeTo = !$scope.allBoxesChecked()
|
||||
lineItem.checked = changeTo for lineItem in $scope.filteredLineItems
|
||||
|
||||
$scope.setSelectedUnitsVariant = (unitsVariant) ->
|
||||
$scope.setSelectedUnitsVariant = (unitsProduct,unitsVariant) ->
|
||||
$scope.selectedUnitsProduct = unitsProduct
|
||||
$scope.selectedUnitsVariant = unitsVariant
|
||||
|
||||
$scope.sumUnitValues = (lineItems) ->
|
||||
@@ -256,25 +259,25 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
'volume': {0.001: 'mL', 1.0: 'L', 1000000.0: 'ML'}
|
||||
unitNames[unitType][scale]
|
||||
|
||||
$scope.formattedValueWithUnitName = (value, unitsVariant) ->
|
||||
$scope.formattedValueWithUnitName = (value, unitsProduct, unitsVariant) ->
|
||||
# A Units Variant is an API object which holds unit properies of a variant
|
||||
if unitsVariant.hasOwnProperty("variant_unit") && (unitsVariant.variant_unit == "weight" || unitsVariant.variant_unit == "volume") && value > 0
|
||||
scale = $scope.getScale(value, unitsVariant.variant_unit)
|
||||
Math.round(value/scale * 1000)/1000 + " " + $scope.getUnitName(scale,unitsVariant.variant_unit)
|
||||
if unitsProduct.hasOwnProperty("variant_unit") && (unitsProduct.variant_unit == "weight" || unitsProduct.variant_unit == "volume") && value > 0
|
||||
scale = $scope.getScale(value, unitsProduct.variant_unit)
|
||||
Math.round(value/scale * 1000)/1000 + " " + $scope.getUnitName(scale,unitsProduct.variant_unit)
|
||||
else
|
||||
''
|
||||
|
||||
$scope.fulfilled = ->
|
||||
# A Units Variant is an API object which holds unit properies of a variant
|
||||
if $scope.selectedUnitsVariant.hasOwnProperty("group_buy_unit_size") && $scope.selectedUnitsVariant.group_buy_unit_size > 0 &&
|
||||
$scope.selectedUnitsVariant.hasOwnProperty("variant_unit") &&
|
||||
( $scope.selectedUnitsVariant.variant_unit == "weight" || $scope.selectedUnitsVariant.variant_unit == "volume" )
|
||||
Math.round( $scope.sumUnitValues( $scope.filteredLineItems ) / $scope.selectedUnitsVariant.group_buy_unit_size * 1000)/1000
|
||||
if $scope.selectedUnitsProduct.hasOwnProperty("group_buy_unit_size") && $scope.selectedUnitsProduct.group_buy_unit_size > 0 &&
|
||||
$scope.selectedUnitsProduct.hasOwnProperty("variant_unit") &&
|
||||
( $scope.selectedUnitsProduct.variant_unit == "weight" || $scope.selectedUnitsProduct.variant_unit == "volume" )
|
||||
Math.round( $scope.sumUnitValues( $scope.filteredLineItems ) / $scope.selectedUnitsProduct.group_buy_unit_size * 1000)/1000
|
||||
else
|
||||
''
|
||||
|
||||
$scope.unitsVariantSelected = ->
|
||||
angular.equals($scope.selectedUnitsVariant,{})
|
||||
!angular.equals($scope.selectedUnitsVariant,{})
|
||||
|
||||
$scope.shiftTab = (tab) ->
|
||||
$scope.visibleTab.visible = false unless $scope.visibleTab == tab || $scope.visibleTab == undefined
|
||||
@@ -282,17 +285,21 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.visibleTab = tab
|
||||
]
|
||||
|
||||
orderManagementModule.filter "selectFilter", [
|
||||
"blankOption"
|
||||
(blankOption) ->
|
||||
return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle,selectedUnitsVariant) ->
|
||||
orderManagementModule.filter "selectFilter", (blankOption) ->
|
||||
return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) ->
|
||||
filtered = []
|
||||
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,blankOption()) || lineItem.supplier == selectedSupplier) &&
|
||||
(angular.equals(selectedDistributor,blankOption()) || lineItem.order.distributor == selectedDistributor) &&
|
||||
(angular.equals(selectedOrderCycle,blankOption()) || lineItem.order.order_cycle == selectedOrderCycle) &&
|
||||
(angular.equals(selectedUnitsVariant,{}) || lineItem.units_variant.unit_text == selectedUnitsVariant.unit_text )
|
||||
(angular.equals(selectedOrderCycle,blankOption()) || lineItem.order.order_cycle == selectedOrderCycle)
|
||||
filtered
|
||||
]
|
||||
|
||||
orderManagementModule.filter "variantFilter", ->
|
||||
return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) ->
|
||||
filtered = []
|
||||
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) ||
|
||||
(lineItem.units_product.id == selectedUnitsProduct.id && (sharedResource || lineItem.units_variant.id == selectedUnitsVariant.id ) ) )
|
||||
filtered
|
||||
|
||||
|
||||
orderManagementModule.factory "dataSubmitter", [
|
||||
"$http", "$q", "switchClass"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
%div{ 'ng-app' => 'ofn.bulk_order_management', 'ng-controller' => 'AdminOrderMgmtCtrl', 'ng-init' => "initialise('#{@spree_api_key}');loading=true;" }
|
||||
%div{ 'ng-show' => '!spree_api_key_ok' }
|
||||
{{ api_error_msg }}
|
||||
.option_tab_titles{ :class => "nine columns alpha" }
|
||||
.option_tab_titles{ :class => "sixteen columns alpha" }
|
||||
%h6{ :class => "three columns alpha", 'ng-repeat' => "tab in optionTabs", "ng-click" => "shiftTab(tab)", "ng-class" => "tab.visible && 'selected' || !tab.visible && 'unselected'"}
|
||||
{{ tab.title }}
|
||||
.filters{ :class => "nine columns alpha", 'ng-show' => 'optionTabs.filters.visible' }
|
||||
@@ -36,16 +36,18 @@
|
||||
%ul.column-list{ :class => "nine columns alpha" }
|
||||
%li.column-list-item{ :class => "three columns alpha", 'ofn-toggle-column' => 'column', 'ng-repeat' => 'column in columns' }
|
||||
{{ column.name }}
|
||||
%div#group_buy_calculation{ :class => "seven columns alpha", 'ng-hide' => 'unitsVariantSelected()' }
|
||||
%div{ :class => "nine columns alpha", 'ng-show' => '!optionTabs.filters.visible && !optionTabs.column_toggle.visible && unitsVariantSelected()' } .
|
||||
%div#group_buy_calculation{ :class => "seven columns alpha", 'ng-show' => 'unitsVariantSelected()' }
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%h6{ :class => "five columns alpha" } {{ selectedUnitsVariant.unit_text }}
|
||||
%h6{ :class => "five columns alpha", 'ng-show' => 'sharedResource' } {{ selectedUnitsProduct.name + ": ALL" }}
|
||||
%h6{ :class => "five columns alpha", 'ng-hide' => 'sharedResource' } {{ selectedUnitsVariant.unit_text }}
|
||||
%h6{ :class => "two column omega" }
|
||||
%a{ 'ng-click' => 'selectedUnitsVariant = {}' } Clear
|
||||
%a{ 'ng-click' => 'selectedUnitsVariant = {};selectedUnitsProduct = {}' } Clear
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" }
|
||||
Group Buy Unit
|
||||
Group Buy Unit Size
|
||||
%span{ :class => "two columns omega" }
|
||||
{{ formattedValueWithUnitName( selectedUnitsVariant.group_buy_unit_size, selectedUnitsVariant ) }}
|
||||
{{ formattedValueWithUnitName( selectedUnitsProduct.group_buy_unit_size, selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" }
|
||||
Fulfilled Units
|
||||
@@ -55,7 +57,11 @@
|
||||
%span{ :class => "five columns alpha" }
|
||||
Total Units Ordered
|
||||
%span{ :class => "two columns omega" }
|
||||
{{ formattedValueWithUnitName( sumUnitValues( filteredLineItems ), selectedUnitsVariant ) }}
|
||||
{{ formattedValueWithUnitName( sumUnitValues( filteredLineItems ), selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%div.shared_resource{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" } Shared Resource?
|
||||
%span{ :class => 'two columns omega' }
|
||||
%input{ type: 'checkbox', :id => 'shared_resource', 'ng-model' => 'sharedResource'}
|
||||
%hr{ :class => "sixteen columns alpha", :style => "margin-bottom: 15px" }
|
||||
%div.loading{ :class => "sixteen columns alpha", 'ng-show' => 'loading' }
|
||||
%h4 Loading Line Items...
|
||||
@@ -94,7 +100,7 @@
|
||||
%th.actions
|
||||
Ask?
|
||||
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
|
||||
%tr.line_item{ 'ng-repeat' => "line_item in filteredLineItems = ( lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter:selectedUnitsVariant | orderBy:predicate:reverse )", 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%tr.line_item{ 'ng-repeat' => "line_item in filteredLineItems = ( lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter | variantFilter:selectedUnitsProduct:selectedUnitsVariant:sharedResource | orderBy:predicate:reverse )", 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%td.bulk
|
||||
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked' }
|
||||
%td.order_no{ 'ng-show' => 'columns.order_no.visible' } {{ line_item.order.number }}
|
||||
@@ -105,7 +111,7 @@
|
||||
%td.producer{ 'ng-show' => 'columns.producer.visible' } {{ line_item.supplier.name }}
|
||||
%td.hub{ 'ng-show' => 'columns.hub.visible' } {{ line_item.order.distributor.name }}
|
||||
%td.variant{ 'ng-show' => 'columns.variant.visible' }
|
||||
%a{ 'ng-click' => "setSelectedUnitsVariant(line_item.units_variant)" } {{ line_item.units_variant.unit_text }}
|
||||
%a{ 'ng-click' => "setSelectedUnitsVariant(line_item.units_product,line_item.units_variant)" } {{ line_item.units_variant.unit_text }}
|
||||
%td.quantity{ 'ng-show' => 'columns.quantity.visible' }
|
||||
%input{ :type => 'number', :name => 'quantity', 'ng-model' => "line_item.quantity", 'ofn-line-item-upd-attr' => "quantity" }
|
||||
%td.max{ 'ng-show' => 'columns.max.visible' } {{ line_item.max }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
object @line_item
|
||||
attributes :id, :quantity, :max_quantity
|
||||
node( :supplier ) { |li| partial 'spree/api/enterprises/bulk_show', :object => li.product.supplier }
|
||||
node( :units_product ) { |li| partial 'spree/api/products/units_show', :object => li.product }
|
||||
node( :units_variant ) { |li| partial 'spree/api/variants/units_show', :object => li.variant }
|
||||
2
app/views/spree/api/products/units_show.v1.rabl
Normal file
2
app/views/spree/api/products/units_show.v1.rabl
Normal file
@@ -0,0 +1,2 @@
|
||||
object @product
|
||||
attributes :id, :name, :group_buy_unit_size, :variant_unit
|
||||
@@ -2,5 +2,3 @@ object @variant
|
||||
attributes :id
|
||||
node( :unit_text ) { |v| v.product.name + (v.options_text.empty? ? "" : ": " + v.options_text) }
|
||||
node( :unit_value ) { |v| v.unit_value }
|
||||
node( :group_buy_unit_size ) { |v| v.product.group_buy_unit_size }
|
||||
node( :variant_unit ) { |v| v.product.variant_unit }
|
||||
|
||||
@@ -15,7 +15,7 @@ module Spree
|
||||
let!(:line_item3) { FactoryGirl.create(:line_item, order: order2) }
|
||||
let!(:line_item4) { FactoryGirl.create(:line_item, order: order3) }
|
||||
let(:order_attributes) { [:id, :full_name, :email, :phone, :completed_at, :line_items, :distributor, :order_cycle, :number] }
|
||||
let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier, :units_variant] }
|
||||
let(:line_item_attributes) { [:id, :quantity, :max_quantity, :supplier, :units_product, :units_variant] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
|
||||
@@ -10,6 +10,7 @@ module Spree
|
||||
let!(:product2) { FactoryGirl.create(:product) }
|
||||
let!(:product3) { FactoryGirl.create(:product) }
|
||||
let(:attributes) { [:id, :name, :supplier, :price, :on_hand, :available_on, :permalink_live] }
|
||||
let(:unit_attributes) { [:id, :name, :group_buy_unit_size, :variant_unit] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
@@ -23,6 +24,12 @@ module Spree
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "retrieves a list of products with attributes relating to units" do
|
||||
spree_get :show, { :id => product1.id, :template => "units_show", :format => :json }
|
||||
keys = json_response.keys.map{ |key| key.to_sym }
|
||||
unit_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts products in ascending id order" do
|
||||
spree_get :index, { :template => 'bulk_index', :format => :json }
|
||||
ids = json_response.map{ |product| product['id'] }
|
||||
|
||||
@@ -10,7 +10,7 @@ module Spree
|
||||
let!(:variant2) { FactoryGirl.create(:variant) }
|
||||
let!(:variant3) { FactoryGirl.create(:variant) }
|
||||
let(:attributes) { [:id, :options_text, :price, :on_hand] }
|
||||
let(:unit_attributes) { [:id, :unit_text, :unit_value, :group_buy_unit_size, :variant_unit] }
|
||||
let(:unit_attributes) { [:id, :unit_text, :unit_value] }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
@@ -24,12 +24,10 @@ module Spree
|
||||
attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
context "retrieving unit attributes" do
|
||||
it "retrieves a list of variants with attributes relating to units" do
|
||||
spree_get :show, { :id => variant1.id, :template => "units_show", :format => :json }
|
||||
keys = json_response.keys.map{ |key| key.to_sym }
|
||||
unit_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
it "retrieves a list of variants with attributes relating to units" do
|
||||
spree_get :show, { :id => variant1.id, :template => "units_show", :format => :json }
|
||||
keys = json_response.keys.map{ |key| key.to_sym }
|
||||
unit_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
#it "sorts variants in ascending id order" do
|
||||
# spree_get :index, { :template => 'bulk_index', :format => :json }
|
||||
|
||||
@@ -534,6 +534,11 @@ feature %q{
|
||||
page.should have_text "0.8"
|
||||
page.should have_text "Total Units Ordered"
|
||||
page.should have_text "4 kg"
|
||||
page.should have_selector "div.shared_resource", :visible => true
|
||||
within "div.shared_resource" do
|
||||
page.should have_selector "span", :text => "Shared Resource?"
|
||||
page.should have_selector "input#shared_resource"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -262,28 +262,28 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
expect(scope.fulfilled()).toEqual ''
|
||||
|
||||
it "returns '' if selectedUnitsVariant has no property 'group_buy_unit_size' or group_buy_unit_size is 0", ->
|
||||
scope.selectedUnitsVariant = { variant_unit: "weight", group_buy_unit_size: 0 }
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 0 }
|
||||
expect(scope.fulfilled()).toEqual ''
|
||||
scope.selectedUnitsVariant = { variant_unit: "weight" }
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight" }
|
||||
expect(scope.fulfilled()).toEqual ''
|
||||
|
||||
it "returns '', and does not call Math.round if variant_unit is 'items'", ->
|
||||
spyOn(Math,"round")
|
||||
scope.selectedUnitsVariant = { variant_unit: "items", group_buy_unit_size: 10 }
|
||||
scope.selectedUnitsProduct = { variant_unit: "items", group_buy_unit_size: 10 }
|
||||
expect(scope.fulfilled()).toEqual ''
|
||||
expect(Math.round).not.toHaveBeenCalled()
|
||||
|
||||
it "calls Math.round() if variant_unit is 'weight' or 'volume'", ->
|
||||
spyOn(Math,"round")
|
||||
scope.selectedUnitsVariant = { variant_unit: "weight", group_buy_unit_size: 10 }
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 10 }
|
||||
scope.fulfilled()
|
||||
expect(Math.round).toHaveBeenCalled()
|
||||
scope.selectedUnitsVariant = { variant_unit: "volume", group_buy_unit_size: 10 }
|
||||
scope.selectedUnitsProduct = { variant_unit: "volume", group_buy_unit_size: 10 }
|
||||
scope.fulfilled()
|
||||
expect(Math.round).toHaveBeenCalled()
|
||||
|
||||
it "returns the correct quantity of fulfilled group buy units", ->
|
||||
scope.selectedUnitsVariant = { variant_unit: "weight", group_buy_unit_size: 1000 }
|
||||
it "returns the quantity of fulfilled group buy units", ->
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 1000 }
|
||||
spyOn(scope,"sumUnitValues").andReturn 1500
|
||||
expect(scope.fulfilled()).toEqual 1.5
|
||||
expect(scope.sumUnitValues).toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user