mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Fix easy rubocop issues
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -10,7 +10,7 @@ module Spree
|
||||
taxons: [],
|
||||
product_properties: [property],
|
||||
master: variant,
|
||||
has_variants?: false
|
||||
variants?: false
|
||||
end
|
||||
|
||||
let(:new_product) do
|
||||
|
||||
Reference in New Issue
Block a user