mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Do not include variant_unit_with_scale in product update check. When saving products, save variant_unit and variant_unit_scale.
This commit is contained in:
@@ -252,7 +252,7 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
url: "/admin/products/bulk_update"
|
||||
data: productsToSubmit
|
||||
).success((data) ->
|
||||
if angular.toJson($scope.products) == angular.toJson(data)
|
||||
if angular.toJson($scope.productsWithoutDerivedAttributes()) == angular.toJson(data)
|
||||
$scope.resetProducts data
|
||||
$scope.displaySuccess()
|
||||
else
|
||||
@@ -266,6 +266,14 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
$scope.updateProducts productsToSubmit
|
||||
|
||||
|
||||
$scope.productsWithoutDerivedAttributes = ->
|
||||
products = []
|
||||
if $scope.products
|
||||
products.push angular.extend {}, product for product in $scope.products
|
||||
angular.forEach products, (product) ->
|
||||
delete product.variant_unit_with_scale
|
||||
products
|
||||
|
||||
$scope.setMessage = (model, text, style, timeout) ->
|
||||
model.text = text
|
||||
model.style = style
|
||||
@@ -354,6 +362,11 @@ filterSubmitProducts = (productsToFilter) ->
|
||||
if product.hasOwnProperty("price")
|
||||
filteredProduct.price = product.price
|
||||
hasUpdatableProperty = true
|
||||
if product.hasOwnProperty("variant_unit_with_scale")
|
||||
match = product.variant_unit_with_scale.match(/^([^_]+)_([\d\.]+)$/)
|
||||
filteredProduct.variant_unit = match[1]
|
||||
filteredProduct.variant_unit_scale = parseFloat(match[2])
|
||||
hasUpdatableProperty = true
|
||||
if product.hasOwnProperty("on_hand") and filteredVariants.length == 0 #only update if no variants present
|
||||
filteredProduct.on_hand = product.on_hand
|
||||
hasUpdatableProperty = true
|
||||
|
||||
Reference in New Issue
Block a user