From 30967a5ffae2f33ee4a75791be1eb581fe7dfe24 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 18 Feb 2019 15:46:40 +0000 Subject: [PATCH] Fix bulk product edit page. on_hand and on_demand should never be mixed on the server side, the UI can make the decision to show on_demand on the on_hand column if on_demand is true --- app/serializers/api/admin/product_serializer.rb | 3 ++- app/serializers/api/admin/variant_serializer.rb | 3 ++- .../spree/admin/products/index/_products_variant.html.haml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/serializers/api/admin/product_serializer.rb b/app/serializers/api/admin/product_serializer.rb index e84588128f..5ef3a27d4e 100644 --- a/app/serializers/api/admin/product_serializer.rb +++ b/app/serializers/api/admin/product_serializer.rb @@ -25,7 +25,8 @@ class Api::Admin::ProductSerializer < ActiveModel::Serializer end def on_hand - object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : I18n.t(:on_demand) + return 0 if object.on_hand.nil? + object.on_hand end def price diff --git a/app/serializers/api/admin/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb index 3fc22b98d4..9be1b3662b 100644 --- a/app/serializers/api/admin/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -4,7 +4,8 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer has_many :variant_overrides def on_hand - object.on_hand.nil? ? 0 : ( object.on_hand.to_f.finite? ? object.on_hand : I18n.t(:on_demand) ) + return 0 if object.on_hand.nil? + object.on_hand end def price diff --git a/app/views/spree/admin/products/index/_products_variant.html.haml b/app/views/spree/admin/products/index/_products_variant.html.haml index c4c0412eef..584e9f3610 100644 --- a/app/views/spree/admin/products/index/_products_variant.html.haml +++ b/app/views/spree/admin/products/index/_products_variant.html.haml @@ -16,7 +16,8 @@ %input{ 'ng-model' => 'variant.price', 'ofn-decimal' => :true, :name => 'variant_price', 'ofn-track-variant' => 'price', :type => 'text' } %td{ 'ng-show' => 'columns.on_hand.visible' } %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-if' => '!variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } - %span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-if' => 'variant.on_demand' } + %span{ :name => 'variant_on_hand', 'ng-if' => 'variant.on_demand' } + = t(:on_demand) %td{ 'ng-show' => 'columns.on_demand.visible' } %input.field{ 'ng-model' => 'variant.on_demand', :name => 'variant_on_demand', 'ofn-track-variant' => 'on_demand', :type => 'checkbox' } %td{ 'ng-show' => 'columns.category.visible' }