Fix easy rubocop issues

This commit is contained in:
Luis Ramos
2020-08-31 12:02:33 +01:00
parent d4e4669e49
commit cf7d8067df
7 changed files with 22 additions and 13 deletions

View File

@@ -4,7 +4,7 @@ module ProductStock
extend ActiveSupport::Concern
def on_demand
if has_variants?
if variants?
raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1
variants.first.on_demand
@@ -14,7 +14,7 @@ module ProductStock
end
def on_hand
if has_variants?
if variants?
variants.map(&:on_hand).reduce(:+)
else
master.on_hand

View File

@@ -9,6 +9,10 @@ module Spree
validates :name, :presentation, presence: true
default_scope -> { order("#{table_name}.position") }
accepts_nested_attributes_for :option_values, reject_if: lambda { |ov| ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true
accepts_nested_attributes_for :option_values,
reject_if: lambda { |ov|
ov[:name].blank? || ov[:presentation].blank?
},
allow_destroy: true
end
end

View File

@@ -15,7 +15,7 @@ module Spree
alias :display_price :display_amount
def money
Spree::Money.new(amount || 0, { currency: currency })
Spree::Money.new(amount || 0, currency: currency)
end
def price

View File

@@ -68,7 +68,7 @@ module Spree
has_many :stock_items, through: :variants
delegate_belongs_to :master, :sku, :price, :currency, :display_amount, :display_price, :weight,
:height, :width, :depth, :is_master, :has_default_price?, :cost_currency,
:height, :width, :depth, :is_master, :default_price?, :cost_currency,
:price_in, :amount_in, :unit_value, :unit_description
delegate_belongs_to :master, :cost_price if Variant.table_exists? &&
Variant.column_names.include?('cost_price')
@@ -150,8 +150,12 @@ module Spree
}
scope :visible_for, lambda { |enterprise|
joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)').
joins('
LEFT OUTER JOIN spree_variants AS o_spree_variants
ON (o_spree_variants.product_id = spree_products.id)').
joins('
LEFT OUTER JOIN inventory_items AS o_inventory_items
ON (o_spree_variants.id = o_inventory_items.variant_id)').
where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true)
}
@@ -225,7 +229,7 @@ module Spree
end
# the master variant is not a member of the variants array
def has_variants?
def variants?
variants.any?
end

View File

@@ -39,7 +39,8 @@ module Spree
has_many :prices,
class_name: 'Spree::Price',
dependent: :destroy
delegate_belongs_to :default_price, :display_price, :display_amount, :price, :price=, :currency if Spree::Price.table_exists?
delegate_belongs_to :default_price, :display_price, :display_amount,
:price, :price=, :currency
has_many :exchange_variants
has_many :exchanges, through: :exchange_variants
@@ -52,7 +53,7 @@ module Spree
validates :price, numericality: { greater_than_or_equal_to: 0 },
presence: true,
if: proc { Spree::Config[:require_master_price] }
validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true } if table_exists? && column_names.include?('cost_price')
validates :cost_price, numericality: { greater_than_or_equal_to: 0, allow_nil: true }
validates :unit_value, presence: true, if: ->(variant) {
%w(weight volume).include?(variant.product.andand.variant_unit)
@@ -219,7 +220,7 @@ module Spree
option_values.detect { |o| o.option_type.name == opt_name }.try(:presentation)
end
def has_default_price?
def default_price?
!default_price.nil?
end

View File

@@ -12,7 +12,7 @@ module Spree
new_product = duplicate_product
# don't dup the actual variants, just the characterising types
new_product.option_types = product.option_types if product.has_variants?
new_product.option_types = product.option_types if product.variants?
# allow site to do some customization
new_product.__send__(:duplicate_extra, product) if new_product.respond_to?(:duplicate_extra)

View File

@@ -10,7 +10,7 @@ module Spree
taxons: [],
product_properties: [property],
master: variant,
has_variants?: false
variants?: false
end
let(:new_product) do