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

This commit is contained in:
luisramos0
2019-02-18 15:46:40 +00:00
parent 12eab1bfa9
commit 30967a5ffa
3 changed files with 6 additions and 3 deletions

View File

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

View File

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

View File

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