mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Group Buy panel on BOM takes changes to final_weight_volumes into account
This commit is contained in:
@@ -132,17 +132,17 @@ angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
|
||||
$scope.sumUnitValues = ->
|
||||
sum = $scope.filteredLineItems.reduce (sum,lineItem) ->
|
||||
sum = sum + lineItem.quantity * lineItem.units_variant.unit_value
|
||||
sum = sum + lineItem.final_weight_volume
|
||||
, 0
|
||||
|
||||
$scope.sumMaxUnitValues = ->
|
||||
sum = $scope.filteredLineItems.reduce (sum,lineItem) ->
|
||||
sum = sum + Math.max(lineItem.max_quantity,lineItem.quantity) * lineItem.units_variant.unit_value
|
||||
sum = sum + Math.max(lineItem.max_quantity,lineItem.original_quantity) * lineItem.units_variant.unit_value
|
||||
, 0
|
||||
|
||||
$scope.allUnitValuesPresent = ->
|
||||
$scope.allFinalWeightVolumesPresent = ->
|
||||
for i,lineItem of $scope.filteredLineItems
|
||||
return false if !lineItem.units_variant.hasOwnProperty('unit_value') || !(lineItem.units_variant.unit_value > 0)
|
||||
return false if !lineItem.hasOwnProperty('final_weight_volume') || !(lineItem.final_weight_volume > 0)
|
||||
true
|
||||
|
||||
# How is this different to OptionValueNamer#name?
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
%span.two.columns Max Fulfilled Units
|
||||
%span.two.columns {{ fulfilled(sumMaxUnitValues()) }}
|
||||
.one.column.omega
|
||||
%div{ :class => "eight columns alpha", 'ng-hide' => 'allUnitValuesPresent()' }
|
||||
%div{ :class => "eight columns alpha", 'ng-hide' => 'allFinalWeightVolumesPresent()' }
|
||||
%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" }
|
||||
|
||||
@@ -261,59 +261,56 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 1000 }
|
||||
expect(scope.fulfilled(1500)).toEqual 1.5
|
||||
|
||||
describe "allUnitValuesPresent()", ->
|
||||
describe "allFinalWeightVolumesPresent()", ->
|
||||
it "returns false if the unit_value of any item in filteredLineItems does not exist", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 1000 } }
|
||||
{ units_variant: { unit_value: 2000 } }
|
||||
{ units_variant: { unit_yayay: 1000 } }
|
||||
{ final_weight_volume: 1000 }
|
||||
{ final_weight_volume: 3000 }
|
||||
{ final_weight_yayaya: 2000 }
|
||||
]
|
||||
expect(scope.allUnitValuesPresent()).toEqual false
|
||||
expect(scope.allFinalWeightVolumesPresent()).toEqual false
|
||||
|
||||
it "returns false if the unit_value of any item in filteredLineItems is not a number greater than 0", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 0 } }
|
||||
{ units_variant: { unit_value: 2000 } }
|
||||
{ units_variant: { unit_value: 1000 } }
|
||||
{ final_weight_volume: 0 }
|
||||
{ final_weight_volume: 3000 }
|
||||
{ final_weight_volume: 2000 }
|
||||
]
|
||||
expect(scope.allUnitValuesPresent()).toEqual false
|
||||
expect(scope.allFinalWeightVolumesPresent()).toEqual false
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 'lala' } }
|
||||
{ units_variant: { unit_value: 2000 } }
|
||||
{ units_variant: { unit_value: 1000 } }
|
||||
{ final_weight_volume: 'lalala' }
|
||||
{ final_weight_volume: 3000 }
|
||||
{ final_weight_volume: 2000 }
|
||||
]
|
||||
expect(scope.allUnitValuesPresent()).toEqual false
|
||||
expect(scope.allFinalWeightVolumesPresent()).toEqual false
|
||||
|
||||
it "returns true if the unit_value of all items in filteredLineItems are numbers greater than 0", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 } }
|
||||
{ units_variant: { unit_value: 2000 } }
|
||||
{ units_variant: { unit_value: 1000 } }
|
||||
{ final_weight_volume: 1000 }
|
||||
{ final_weight_volume: 3000 }
|
||||
{ final_weight_volume: 2000 }
|
||||
]
|
||||
expect(scope.allUnitValuesPresent()).toEqual true
|
||||
expect(scope.allFinalWeightVolumesPresent()).toEqual true
|
||||
|
||||
describe "sumUnitValues()", ->
|
||||
it "returns the sum of the product of unit_value and quantity for specified line_items", ->
|
||||
it "returns the sum of the final_weight_volumes line_items", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 1 }, quantity: 2 }
|
||||
{ units_variant: { unit_value: 2 }, quantity: 3 }
|
||||
{ units_variant: { unit_value: 3 }, quantity: 7 }
|
||||
{ final_weight_volume: 2 }
|
||||
{ final_weight_volume: 7 }
|
||||
{ final_weight_volume: 21 }
|
||||
]
|
||||
sp0 = scope.filteredLineItems[0].units_variant.unit_value * scope.filteredLineItems[0].quantity
|
||||
sp1 = scope.filteredLineItems[1].units_variant.unit_value * scope.filteredLineItems[1].quantity
|
||||
sp2 = scope.filteredLineItems[2].units_variant.unit_value * scope.filteredLineItems[2].quantity
|
||||
expect(scope.sumUnitValues()).toEqual (sp0 + sp1 + sp2)
|
||||
expect(scope.sumUnitValues()).toEqual 30
|
||||
|
||||
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 }
|
||||
{ units_variant: { unit_value: 1 }, original_quantity: 2, max_quantity: 5 }
|
||||
{ units_variant: { unit_value: 2 }, original_quantity: 3, max_quantity: 1 }
|
||||
{ units_variant: { unit_value: 3 }, original_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)
|
||||
sp0 = scope.filteredLineItems[0].units_variant.unit_value * Math.max(scope.filteredLineItems[0].original_quantity, scope.filteredLineItems[0].max_quantity)
|
||||
sp1 = scope.filteredLineItems[1].units_variant.unit_value * Math.max(scope.filteredLineItems[1].original_quantity, scope.filteredLineItems[1].max_quantity)
|
||||
sp2 = scope.filteredLineItems[2].units_variant.unit_value * Math.max(scope.filteredLineItems[2].original_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", ->
|
||||
|
||||
Reference in New Issue
Block a user