mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #8987 from jibees/8981-BOM-correct-value-for-current-and-max-fullfilled
BOM: correct max and current fulfilled units values
This commit is contained in:
@@ -182,9 +182,9 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
|
||||
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" )
|
||||
scale = $scope.getScale($scope.selectedUnitsProduct, $scope.selectedUnitsVariant)
|
||||
sumOfUnitValues = sumOfUnitValues / scale if scale == 28.35 || scale == 453.6 # divide by scale if smallest unit
|
||||
$scope.roundToThreeDecimals(sumOfUnitValues / $scope.selectedUnitsProduct.group_buy_unit_size * $scope.selectedUnitsVariant.unit_value)
|
||||
scale = $scope.selectedUnitsProduct.variant_unit_scale
|
||||
sumOfUnitValues = sumOfUnitValues * scale unless scale == 28.35 || scale == 453.6
|
||||
$scope.roundToThreeDecimals(sumOfUnitValues / $scope.selectedUnitsProduct.group_buy_unit_size)
|
||||
else
|
||||
''
|
||||
|
||||
|
||||
@@ -169,15 +169,19 @@ describe "LineItemsCtrl", ->
|
||||
scope.fulfilled()
|
||||
expect(Math.round).toHaveBeenCalled()
|
||||
|
||||
it "returns the quantity of fulfilled group buy units", ->
|
||||
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 1000 }
|
||||
scope.selectedUnitsVariant = { unit_value: 1 }
|
||||
expect(scope.fulfilled(1500)).toEqual 1.5
|
||||
|
||||
it "returns the quantity of fulfilled group buy units by volume", ->
|
||||
scope.selectedUnitsProduct = { variant_unit: "volume", group_buy_unit_size: 5000 }
|
||||
scope.selectedUnitsVariant = { unit_value: 1000 }
|
||||
expect(scope.fulfilled(5)).toEqual 1
|
||||
describe "returns the quantity of fulfilled group buy units", ->
|
||||
runs = [
|
||||
{ selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 1000, variant_unit_scale: 1 }, arg: 1500, expected: 1.5 },
|
||||
{ selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 60000, variant_unit_scale: 1000 }, arg: 9, expected: 0.15 },
|
||||
{ selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 60000, variant_unit_scale: 1 }, arg: 9000, expected: 0.15 }
|
||||
{ selectedUnitsProduct: { variant_unit: "weight", group_buy_unit_size: 5, variant_unit_scale: 28.35 }, arg: 12, expected: 2.4},
|
||||
{ selectedUnitsProduct: { variant_unit: "volume", group_buy_unit_size: 5000, variant_unit_scale: 1 }, arg: 5, expected: 0.001}
|
||||
];
|
||||
runs.forEach ({selectedUnitsProduct, arg, expected}) ->
|
||||
it "returns the quantity of fulfilled group buy units, group_buy_unit_size: " + selectedUnitsProduct.group_buy_unit_size + ", arg: " + arg + ", scale: " + selectedUnitsProduct.variant_unit_scale , ->
|
||||
scope.selectedUnitsProduct = selectedUnitsProduct
|
||||
expect(scope.fulfilled(arg)).toEqual expected
|
||||
|
||||
describe "allFinalWeightVolumesPresent()", ->
|
||||
it "returns false if the unit_value of any item in filteredLineItems does not exist", ->
|
||||
|
||||
@@ -823,9 +823,9 @@ describe '
|
||||
expect(page).to have_text "Max Quantity Ordered"
|
||||
expect(page).to have_text "9000 g"
|
||||
expect(page).to have_text "Current Fulfilled Units"
|
||||
expect(page).to have_text "800"
|
||||
expect(page).to have_text "0.8"
|
||||
expect(page).to have_text "Max Fulfilled Units"
|
||||
expect(page).to have_text "1800"
|
||||
expect(page).to have_text "1.8"
|
||||
expect(page).to have_selector "div.shared_resource", visible: true
|
||||
within "div.shared_resource" do
|
||||
expect(page).to have_selector "span", text: "Shared Resource?"
|
||||
|
||||
Reference in New Issue
Block a user