mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
On save, scale from chosen unit to base unit (eg. mL to L)
This commit is contained in:
@@ -299,14 +299,16 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
product.variant_unit_scale = null
|
||||
if product.variants
|
||||
for id, variant of product.variants
|
||||
$scope.packVariant variant
|
||||
$scope.packVariant product, variant
|
||||
|
||||
|
||||
$scope.packVariant = (variant) ->
|
||||
$scope.packVariant = (product, variant) ->
|
||||
if variant.hasOwnProperty("unit_value_with_description")
|
||||
match = variant.unit_value_with_description.match(/^([\d\.]+|)( |)(.*)$/)
|
||||
if match
|
||||
variant.unit_value = parseFloat(match[1]) || null
|
||||
product = $scope.findProduct(product.id)
|
||||
variant.unit_value = parseFloat(match[1]) || null
|
||||
variant.unit_value *= product.variant_unit_scale if variant.unit_value
|
||||
variant.unit_description = match[3]
|
||||
|
||||
|
||||
@@ -323,6 +325,12 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
delete variant.options_text
|
||||
products_filtered
|
||||
|
||||
|
||||
$scope.findProduct = (id) ->
|
||||
products = (product for product in $scope.products when product.id == id)
|
||||
if products.length == 0 then null else products[0]
|
||||
|
||||
|
||||
$scope.setMessage = (model, text, style, timeout) ->
|
||||
model.text = text
|
||||
model.style = style
|
||||
|
||||
Reference in New Issue
Block a user