mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Display unit value and description for variants in BPE
This commit is contained in:
@@ -188,6 +188,10 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
else
|
||||
null
|
||||
|
||||
if product.variants
|
||||
for variant in product.variants
|
||||
variant.unit_value_with_description = "#{variant.unit_value || ''} #{variant.unit_description || ''}".trim()
|
||||
|
||||
|
||||
$scope.updateOnHand = (product) ->
|
||||
product.on_hand = $scope.onHand(product)
|
||||
@@ -291,8 +295,11 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
products = []
|
||||
if $scope.products
|
||||
products.push angular.extend {}, product for product in $scope.products
|
||||
angular.forEach products, (product) ->
|
||||
for product in products
|
||||
delete product.variant_unit_with_scale
|
||||
if product.variants
|
||||
for variant in product.variants
|
||||
delete variant.unit_value_with_description
|
||||
products
|
||||
|
||||
$scope.setMessage = (model, text, style, timeout) ->
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
%th{ 'ng-show' => 'columns.name.visible' } Name
|
||||
%th{ 'ng-show' => 'columns.supplier.visible' } Supplier
|
||||
%th{ 'ng-show' => 'columns.price.visible' } Price
|
||||
%th{ 'ng-show' => 'columns.unit.visible' } Unit
|
||||
%th{ 'ng-show' => 'columns.unit.visible' } Unit / Value
|
||||
%th{ 'ng-show' => 'columns.on_hand.visible' } On Hand
|
||||
%th{ 'ng-show' => 'columns.available_on.visible' } Av. On
|
||||
%th.actions
|
||||
@@ -70,6 +70,8 @@
|
||||
%td{ 'ng-show' => 'columns.supplier.visible' }
|
||||
%td{ 'ng-show' => 'columns.price.visible' }
|
||||
%input{ 'ng-model' => 'variant.price', 'ofn-decimal' => :true, :name => 'variant_price', 'ofn-track-variant' => 'price', :type => 'text' }
|
||||
%td{ 'ng-show' => 'columns.unit.visible' }
|
||||
%input{ 'ng-model' => 'variant.unit_value_with_description', :name => 'variant_unit_value_with_description', 'ofn-track-variant' => 'unit_value_with_description', :type => 'text' }
|
||||
%td{ 'ng-show' => 'columns.on_hand.visible' }
|
||||
%input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ofn-track-variant' => 'on_hand', :type => 'number' }
|
||||
%td{ 'ng-show' => 'columns.available_on.visible' }
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
object @variant
|
||||
|
||||
attributes :id, :options_text, :price, :on_hand
|
||||
attributes :id, :options_text, :price, :unit_value, :unit_description, :on_hand
|
||||
@@ -160,6 +160,18 @@ feature %q{
|
||||
page.should have_field "variant_price", with: "12.75"
|
||||
page.should have_field "variant_price", with: "2.5"
|
||||
end
|
||||
|
||||
it "displays a unit value field (for each variant) for each product" do
|
||||
p1 = FactoryGirl.create(:product, price: 2.0, variant_unit: "weight", variant_unit_scale: "1000")
|
||||
v1 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 12.75, unit_value: 1.2, unit_description: "(small bag)")
|
||||
v2 = FactoryGirl.create(:variant, product: p1, is_master: false, price: 2.50, unit_value: 4.8, unit_description: "(large bag)")
|
||||
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
page.should have_field "price", with: "2.0"
|
||||
page.should have_field "variant_unit_value_with_description", with: "1.2 (small bag)"
|
||||
page.should have_field "variant_unit_value_with_description", with: "4.8 (large bag)"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "create a new product" do
|
||||
|
||||
@@ -361,27 +361,51 @@ describe "AdminBulkProductsCtrl", ->
|
||||
|
||||
|
||||
describe "loading variant unit", ->
|
||||
it "sets variant_unit_with_scale by combining variant_unit and variant_unit_scale", ->
|
||||
product =
|
||||
variant_unit: "volume"
|
||||
variant_unit_scale: .001
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "volume_0.001"
|
||||
describe "setting product variant_unit_with_scale field", ->
|
||||
it "sets by combining variant_unit and variant_unit_scale", ->
|
||||
product =
|
||||
variant_unit: "volume"
|
||||
variant_unit_scale: .001
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "volume_0.001"
|
||||
|
||||
it "sets variant_unit_with_scale to null when variant_unit is null", ->
|
||||
product = {variant_unit: null, variant_unit_scale: 1000}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toBeNull()
|
||||
it "sets to null when variant_unit is null", ->
|
||||
product = {variant_unit: null, variant_unit_scale: 1000}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toBeNull()
|
||||
|
||||
it "sets variant_unit_with_scale to variant_unit when variant_unit_scale is null", ->
|
||||
product = {variant_unit: 'items', variant_unit_scale: null, variant_unit_name: 'foo'}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "items"
|
||||
it "sets to variant_unit when variant_unit_scale is null", ->
|
||||
product = {variant_unit: 'items', variant_unit_scale: null, variant_unit_name: 'foo'}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "items"
|
||||
|
||||
it "sets variant_unit_with_scale to variant_unit when variant_unit is 'items'", ->
|
||||
product = {variant_unit: 'items', variant_unit_scale: 1000, variant_unit_name: 'foo'}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "items"
|
||||
it "sets to variant_unit when variant_unit is 'items'", ->
|
||||
product = {variant_unit: 'items', variant_unit_scale: 1000, variant_unit_name: 'foo'}
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variant_unit_with_scale).toEqual "items"
|
||||
|
||||
describe "setting variant unit_value_with_description", ->
|
||||
it "sets by combining unit_value and unit_description", ->
|
||||
product =
|
||||
variants: [{id: 1, unit_value: 1, unit_description: '(bottle)'}]
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variants[0]).toEqual
|
||||
id: 1
|
||||
unit_value: 1
|
||||
unit_description: '(bottle)'
|
||||
unit_value_with_description: '1 (bottle)'
|
||||
|
||||
it "uses unit_value when description is missing", ->
|
||||
product =
|
||||
variants: [{id: 1, unit_value: 1}]
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variants[0].unit_value_with_description).toEqual '1'
|
||||
|
||||
it "uses unit_description when value is missing", ->
|
||||
product =
|
||||
variants: [{id: 1, unit_description: 'Small'}]
|
||||
scope.loadVariantUnit product
|
||||
expect(product.variants[0].unit_value_with_description).toEqual 'Small'
|
||||
|
||||
|
||||
describe "getting on_hand counts when products have variants", ->
|
||||
@@ -585,11 +609,21 @@ describe "AdminBulkProductsCtrl", ->
|
||||
it "returns an empty array when products are undefined", ->
|
||||
expect(scope.productsWithoutDerivedAttributes()).toEqual([])
|
||||
|
||||
it "does not alter products", ->
|
||||
it "does not alter original products", ->
|
||||
scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}]
|
||||
scope.productsWithoutDerivedAttributes()
|
||||
expect(scope.products).toEqual [{id: 123, variant_unit_with_scale: 'weight_1000'}]
|
||||
|
||||
describe "updating variants", ->
|
||||
it "returns variants without the unit_value_with_description field", ->
|
||||
scope.products = [{id: 123, variants: [{id: 234, unit_value_with_description: 'foo'}]}]
|
||||
expect(scope.productsWithoutDerivedAttributes()).toEqual [
|
||||
{
|
||||
id: 123
|
||||
variants: [{id: 234}]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
describe "deleting products", ->
|
||||
it "deletes products with a http delete request to /api/products/id", ->
|
||||
@@ -783,6 +817,7 @@ describe "AdminBulkProductsCtrl", ->
|
||||
variants: [
|
||||
id: 3
|
||||
name: "V1"
|
||||
unit_value_with_description: ""
|
||||
]
|
||||
|
||||
expect(scope.products).toEqual [
|
||||
@@ -800,6 +835,7 @@ describe "AdminBulkProductsCtrl", ->
|
||||
variants: [
|
||||
id: 3
|
||||
name: "V1"
|
||||
unit_value_with_description: ""
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user