mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
BOM: view information about max quantities ordered
This commit is contained in:
@@ -230,6 +230,11 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
sum = sum + lineItem.quantity * lineItem.units_variant.unit_value
|
||||
, 0
|
||||
|
||||
$scope.sumMaxUnitValues = ->
|
||||
sum = $scope.filteredLineItems.reduce (sum,lineItem) ->
|
||||
sum = sum + Math.max(lineItem.max_quantity,lineItem.quantity) * lineItem.units_variant.unit_value
|
||||
, 0
|
||||
|
||||
$scope.allUnitValuesPresent = ->
|
||||
for i,lineItem of $scope.filteredLineItems
|
||||
return false if !lineItem.units_variant.hasOwnProperty('unit_value') || !(lineItem.units_variant.unit_value > 0)
|
||||
@@ -262,12 +267,12 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
else
|
||||
''
|
||||
|
||||
$scope.fulfilled = ->
|
||||
$scope.fulfilled = (sumOfUnitValues) ->
|
||||
# A Units Variant is an API object which holds unit properies of a variant
|
||||
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.selectedUnitsProduct.group_buy_unit_size * 1000)/1000
|
||||
Math.round( sumOfUnitValues / $scope.selectedUnitsProduct.group_buy_unit_size * 1000)/1000
|
||||
else
|
||||
''
|
||||
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
sharedDirectivesModule = angular.module("ofn.shared_directives", [])
|
||||
|
||||
sharedDirectivesModule.directive "datetimepicker", [
|
||||
"$parse"
|
||||
($parse) ->
|
||||
return (
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
element.datetimepicker
|
||||
dateFormat: "yy-mm-dd"
|
||||
timeFormat: "HH:mm:ss"
|
||||
stepMinute: 15
|
||||
onSelect: (dateText, inst) ->
|
||||
scope.$apply (scope) ->
|
||||
# Fires ngModel.$parsers
|
||||
ngModel.$setViewValue dateText
|
||||
)
|
||||
]
|
||||
sharedDirectivesModule.directive "datetimepicker", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
element.datetimepicker
|
||||
dateFormat: "yy-mm-dd"
|
||||
timeFormat: "HH:mm:ss"
|
||||
stepMinute: 15
|
||||
onSelect: (dateText, inst) ->
|
||||
scope.$apply (scope) ->
|
||||
# Fires ngModel.$parsers
|
||||
ngModel.$setViewValue dateText
|
||||
|
||||
sharedDirectivesModule.directive "ofnSelect2MinSearch", [
|
||||
->
|
||||
|
||||
@@ -28,4 +28,13 @@ div#group_buy_calculation {
|
||||
padding: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
width: 95%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.row span {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
@@ -28,33 +28,42 @@
|
||||
%label{ :for => 'order_cycle_filter' }Order Cycle
|
||||
%br
|
||||
%select{ :class => "three columns alpha", :id => 'order_cycle_filter', 'ofn-select2-min-search' => 5, 'ng-model' => 'orderCycleFilter', 'ng-options' => 'oc.name for oc in orderCycles'}
|
||||
%div#group_buy_calculation{ :class => "sixteen columns alpha", 'ng-show' => 'unitsVariantSelected()' }
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%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 = {};selectedUnitsProduct = {}' } Clear
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" }
|
||||
Group Buy Unit Size
|
||||
%span{ :class => "two columns omega" }
|
||||
{{ formattedValueWithUnitName( selectedUnitsProduct.group_buy_unit_size, selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" }
|
||||
Fulfilled Units
|
||||
%span{ :class => "two columns omega" }
|
||||
{{ fulfilled() }}
|
||||
%div{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" }
|
||||
Total Units Ordered
|
||||
%span{ :class => "two columns omega" }
|
||||
{{ formattedValueWithUnitName( sumUnitValues(), selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%div.shared_resource{ :class => "seven columns alpha" }
|
||||
%span{ :class => "five columns alpha" } Shared Resource?
|
||||
%span{ :class => 'two columns omega' }
|
||||
%div#group_buy_calculation{ :class => "fifteen columns alpha", 'ng-show' => 'unitsVariantSelected()' }
|
||||
%div.shared_resource{ :class => "four columns alpha" }
|
||||
%span{ :class => 'three columns omega' }
|
||||
%input{ type: 'checkbox', :id => 'shared_resource', 'ng-model' => 'sharedResource'}
|
||||
%div{ :class => "seven columns alpha", 'ng-hide' => 'allUnitValuesPresent()' }
|
||||
%span{ :class => "seven columns alpha", style: 'color:red' }
|
||||
Shared Resource?
|
||||
%div{ :class => "seven columns omega" }
|
||||
%h6{ :class => "seven columns alpha", 'ng-show' => 'sharedResource', style: 'text-align: center;' } {{ selectedUnitsProduct.name + ": ALL" }}
|
||||
%h6{ :class => "seven columns alpha", 'ng-hide' => 'sharedResource', style: 'text-align: center;' } {{ selectedUnitsVariant.unit_text }}
|
||||
%div{ :class => "four columns alpha" }
|
||||
%h6{ :class => "four columns alpha", :style => 'text-align: right;' }
|
||||
%a{ 'ng-click' => 'selectedUnitsVariant = {};selectedUnitsProduct = {};sharedResource=false;' } Clear
|
||||
%hr
|
||||
.row{ :style => 'font-weight: bold'}
|
||||
%span{ :class => "three columns omega" }
|
||||
Group Buy Unit Size
|
||||
%span{ :class => "three columns omega" }
|
||||
Total Quantity Ordered
|
||||
%span{ :class => "three columns omega" }
|
||||
Max Quantity Ordered
|
||||
%span{ :class => "three columns omega" }
|
||||
Fulfilled Units
|
||||
%span{ :class => "three columns alpha" }
|
||||
Max Fulfilled Units
|
||||
.row
|
||||
%span{ :class => "three columns omega" }
|
||||
{{ formattedValueWithUnitName( selectedUnitsProduct.group_buy_unit_size, selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%span{ :class => "three columns omega" }
|
||||
{{ formattedValueWithUnitName( sumUnitValues(), selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%span{ :class => "three columns omega" }
|
||||
{{ formattedValueWithUnitName( sumMaxUnitValues(), selectedUnitsProduct, selectedUnitsVariant ) }}
|
||||
%span{ :class => "three columns omega" }
|
||||
{{ fulfilled(sumUnitValues()) }}
|
||||
%span{ :class => "three columns alpha" }
|
||||
{{ fulfilled(sumMaxUnitValues()) }}
|
||||
%div{ :class => "eight columns alpha", 'ng-hide' => 'allUnitValuesPresent()' }
|
||||
%span{ :class => "eight columns alpha", style: 'color:red' }
|
||||
WARNING: Some variants do not have a unit value
|
||||
%hr{ :class => "sixteen columns alpha", :style => "margin-bottom: 15px" }
|
||||
%div.loading{ :class => "sixteen columns alpha", 'ng-show' => 'loading' }
|
||||
@@ -121,7 +130,7 @@
|
||||
%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 }}
|
||||
%td.max{ 'ng-show' => 'columns.max.visible' } {{ line_item.max_quantity }}
|
||||
%td.actions
|
||||
%a{ 'ng-click' => "deleteLineItem(line_item)", :class => "delete-line-item icon-trash no-text" }
|
||||
%input{ :type => "button", 'value' => 'Update', 'ng-click' => 'pendingChanges.submitAll()' }
|
||||
@@ -486,8 +486,8 @@ feature %q{
|
||||
let!(:p3) { FactoryGirl.create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [FactoryGirl.create(:variant, unit_value: 1000)] ) }
|
||||
let!(:v3) { p3.variants.first }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3, variant: v3, quantity: 3 ) }
|
||||
let!(:li4) { FactoryGirl.create(:line_item, order: o2, variant: v3, quantity: 1 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3, variant: v3, quantity: 3, max_quantity: 6 ) }
|
||||
let!(:li4) { FactoryGirl.create(:line_item, order: o2, variant: v3, quantity: 1, max_quantity: 3 ) }
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
@@ -500,12 +500,16 @@ feature %q{
|
||||
page.should have_selector "div#group_buy_calculation", :visible => true
|
||||
|
||||
within "div#group_buy_calculation" do
|
||||
page.should have_text "Group Buy Unit"
|
||||
page.should have_text "Group Buy Unit Size"
|
||||
page.should have_text "5 kg"
|
||||
page.should have_text "Total Quantity Ordered"
|
||||
page.should have_text "4 kg"
|
||||
page.should have_text "Max Quantity Ordered"
|
||||
page.should have_text "9 kg"
|
||||
page.should have_text "Fulfilled Units"
|
||||
page.should have_text "0.8"
|
||||
page.should have_text "Total Units Ordered"
|
||||
page.should have_text "4 kg"
|
||||
page.should have_text "Max Fulfilled Units"
|
||||
page.should have_text "1.8"
|
||||
page.should have_selector "div.shared_resource", :visible => true
|
||||
within "div.shared_resource" do
|
||||
page.should have_selector "span", :text => "Shared Resource?"
|
||||
|
||||
@@ -257,9 +257,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
|
||||
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()
|
||||
expect(scope.fulfilled(1500)).toEqual 1.5
|
||||
|
||||
describe "allUnitValuesPresent()", ->
|
||||
it "returns false if the unit_value of any item in filteredLineItems does not exist", ->
|
||||
@@ -304,6 +302,18 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
sp2 = scope.filteredLineItems[2].units_variant.unit_value * scope.filteredLineItems[2].quantity
|
||||
expect(scope.sumUnitValues()).toEqual (sp0 + sp1 + sp2)
|
||||
|
||||
describe "sumMaxUnitValues()", ->
|
||||
it "returns the sum of the product of unit_value and maxOf(max_quantity,quantity) for specified line_items", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 1 }, quantity: 2, max_quantity: 5 }
|
||||
{ units_variant: { unit_value: 2 }, quantity: 3, max_quantity: 1 }
|
||||
{ units_variant: { unit_value: 3 }, quantity: 7, max_quantity: 10 }
|
||||
]
|
||||
sp0 = scope.filteredLineItems[0].units_variant.unit_value * Math.max(scope.filteredLineItems[0].quantity, scope.filteredLineItems[0].max_quantity)
|
||||
sp1 = scope.filteredLineItems[1].units_variant.unit_value * Math.max(scope.filteredLineItems[1].quantity, scope.filteredLineItems[1].max_quantity)
|
||||
sp2 = scope.filteredLineItems[2].units_variant.unit_value * Math.max(scope.filteredLineItems[2].quantity, scope.filteredLineItems[2].max_quantity)
|
||||
expect(scope.sumMaxUnitValues()).toEqual (sp0 + sp1 + sp2)
|
||||
|
||||
describe "formatting a value based upon the properties of a specified Units Variant", ->
|
||||
# A Units Variant is an API object which holds unit properies of a variant
|
||||
|
||||
|
||||
Reference in New Issue
Block a user