When BOM is 'item', do not update sumOfUnitValues with scale

since scale is always `1`, but return a value

+ update tests as well
This commit is contained in:
Jean-Baptiste Bellet
2022-04-25 15:53:38 +02:00
parent 3553cc0d9f
commit a4afeeaa3d
2 changed files with 9 additions and 12 deletions

View File

@@ -211,11 +211,11 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
$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" )
scale = $scope.selectedUnitsProduct.variant_unit_scale
sumOfUnitValues = sumOfUnitValues * scale unless scale == 28.35 || scale == 453.6
if $scope.selectedUnitsProduct.hasOwnProperty("group_buy_unit_size")&& $scope.selectedUnitsProduct.group_buy_unit_size > 0 &&
$scope.selectedUnitsProduct.hasOwnProperty("variant_unit")
if $scope.selectedUnitsProduct.variant_unit == "weight" || $scope.selectedUnitsProduct.variant_unit == "volume"
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
''

View File

@@ -207,13 +207,7 @@ describe "LineItemsCtrl", ->
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.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'", ->
it "calls Math.round() if variant_unit is 'weight', 'volume', or items", ->
spyOn(Math,"round")
scope.selectedUnitsProduct = { variant_unit: "weight", group_buy_unit_size: 10 }
scope.fulfilled()
@@ -221,6 +215,9 @@ describe "LineItemsCtrl", ->
scope.selectedUnitsProduct = { variant_unit: "volume", group_buy_unit_size: 10 }
scope.fulfilled()
expect(Math.round).toHaveBeenCalled()
scope.selectedUnitsProduct = { variant_unit: "items", group_buy_unit_size: 10 }
scope.fulfilled()
expect(Math.round).toHaveBeenCalled()
describe "returns the quantity of fulfilled group buy units", ->