On save, scale from chosen unit to base unit (eg. mL to L)

This commit is contained in:
Rohan Mitchell
2014-01-14 11:13:19 +11:00
parent c43b56f3f8
commit 9442b7b5dc
2 changed files with 46 additions and 9 deletions

View File

@@ -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