mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Inspecting 1483 files
........................................................................................................................C..................................................................................................................C...........CC.C..........................................C......C..........C.........................C......................CC..........C........................................................................................................................C.......................................................................................................C........................................................C...........................................................................................................................................C......................................C.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Offenses:
app/controllers/spree/admin/products_controller.rb:183:11: C: [Corrected] Rails/WhereNot: Use where.not(spree_variants: { import_date: nil }) instead of manually constructing negated SQL in where.
where('spree_variants.import_date IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/concerns/permalink_generator.rb:37:26: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
scope_with_deleted.where('id != ?', id)
^^^^^^^^^^^^^^^^^^^^
app/models/concerns/permalink_generator.rb:37:40: C: [Corrected] Style/HashSyntax: Omit the hash value.
scope_with_deleted.where.not(id: id)
^^
app/models/enterprise.rb:152:7: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: ready_enterprises }) instead of manually constructing negated SQL in where.
where("enterprises.id NOT IN (?)", ready_enterprises)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:158:31: C: [Corrected] Rails/WhereNot: Use where.not(sells: 'none') instead of manually constructing negated SQL in where.
scope :is_distributor, -> { where('sells != ?', 'none') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:479:17: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
dups = dups.where('id != ?', id) unless new_record?
^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:534:43: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: self }) instead of manually constructing negated SQL in where.
enterprises = owner.owned_enterprises.where('enterprises.id != ?', self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise.rb:583:7: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: id }) instead of manually constructing negated SQL in where.
where('enterprises.id != ?', id).
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_fee.rb:40:24: C: [Corrected] Rails/WhereNot: Use where.not(spree_calculators: { type: PER_ORDER_CALCULATORS }) instead of manually constructing negated SQL in where.
joins(:calculator).where('spree_calculators.type NOT IN (?)', PER_ORDER_CALCULATORS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/enterprise_relationship.rb:78:19: C: [Corrected] Rails/WhereNot: Use where.not(name: perms) instead of manually constructing negated SQL in where.
permissions.where('name NOT IN (?)', perms).destroy_all
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/product_import/inventory_reset_strategy.rb:27:16: C: [Corrected] Rails/WhereNot: Use where.not(id: excluded_items_ids) instead of manually constructing negated SQL in where.
relation.where('id NOT IN (?)', excluded_items_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/proxy_order.rb:19:25: C: [Corrected] Rails/WhereNot: Use where.not(proxy_orders: { canceled_at: nil }) instead of manually constructing negated SQL in where.
scope :canceled, -> { where('proxy_orders.canceled_at IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/credit_card.rb:26:39: C: [Corrected] Rails/WhereNot: Use where.not(gateway_customer_profile_id: nil) instead of manually constructing negated SQL in where.
scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/product.rb:166:9: C: [Corrected] Rails/WhereNot: Use where.not(order_cycles: { id: nil }) instead of manually constructing negated SQL in where.
where('order_cycles.id IS NOT NULL')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/variant.rb:94:30: C: [Corrected] Rails/WhereNot: Use where.not(deleted_at: nil) instead of manually constructing negated SQL in where.
scope :deleted, lambda { where('deleted_at IS NOT NULL') }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/variant.rb:165:43: C: [Corrected] Rails/WhereNot: Use where.not(spree_prices: { amount: nil }) instead of manually constructing negated SQL in where.
where('spree_prices.amount IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/models/spree/zone.rb:141:19: C: [Corrected] Rails/WhereNot: Use where.not(id: id) instead of manually constructing negated SQL in where.
Spree::Zone.where('id != ?', id).update_all(default_tax: false) if default_tax
^^^^^^^^^^^^^^^^^^^^
app/models/spree/zone.rb:141:33: C: [Corrected] Style/HashSyntax: Omit the hash value.
Spree::Zone.where.not(id: id).update_all(default_tax: false) if default_tax
^^
app/models/variant_override.rb:32:7: C: [Corrected] Rails/WhereNot: Use where.not(variant_overrides: { import_date: nil }) instead of manually constructing negated SQL in where.
where('variant_overrides.import_date IS NOT NULL').
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/cap_quantity.rb:45:22: C: [Corrected] Rails/WhereNot: Use where.not(variant_id: available_variants_for.select(&:id)) instead of manually constructing negated SQL in where.
order.line_items.where('variant_id NOT IN (?)', available_variants_for.select(&:id))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
engines/catalog/app/services/catalog/product_import/products_reset_strategy.rb:32:18: C: [Corrected] Rails/WhereNot: Use where.not(spree_variants: { id: excluded_items_ids }) instead of manually constructing negated SQL in where.
relation.where('spree_variants.id NOT IN (?)', excluded_items_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb:78:18: C: [Corrected] Rails/WhereNot: Use where.not(order_cycle_id: order_cycle_ids) instead of manually constructing negated SQL in where.
orphaned.where('order_cycle_id NOT IN (?)', order_cycle_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:27:14: C: [Corrected] Rails/WhereNot: Use where.not(enterprises: { id: nil }) instead of manually constructing negated SQL in where.
.where("enterprises.id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:39:14: C: [Corrected] Rails/WhereNot: Use where.not(enterprise_id: nil) instead of manually constructing negated SQL in where.
.where("enterprise_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/reporting/reports/users_and_enterprises/base.rb:40:14: C: [Corrected] Rails/WhereNot: Use where.not(user_id: nil) instead of manually constructing negated SQL in where.
.where("user_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/tasks/data/anonymize_data.rake:50:16: C: [Corrected] Rails/WhereNot: Use where.not(user_id: nil) instead of manually constructing negated SQL in where.
Customer.where("user_id IS NOT NULL")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1483 files inspected, 26 offenses detected, 26 offenses corrected
92 lines
2.4 KiB
Ruby
92 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spree/localized_number'
|
|
|
|
class VariantOverride < ApplicationRecord
|
|
extend Spree::LocalizedNumber
|
|
include StockSettingsOverrideValidation
|
|
|
|
self.belongs_to_required_by_default = false
|
|
|
|
acts_as_taggable
|
|
|
|
belongs_to :hub, class_name: 'Enterprise'
|
|
belongs_to :variant, class_name: 'Spree::Variant'
|
|
|
|
validates :hub, presence: true
|
|
validates :variant, presence: true
|
|
# Default stock can be nil, indicating stock should not be reset or zero, meaning reset to zero.
|
|
# Need to ensure this can be set by the user.
|
|
validates :default_stock, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
validates :price, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
validates :count_on_hand, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
|
|
|
|
default_scope { where(permission_revoked_at: nil) }
|
|
|
|
scope :for_hubs, lambda { |hubs|
|
|
where(hub_id: hubs)
|
|
}
|
|
|
|
scope :distinct_import_dates, lambda {
|
|
select('DISTINCT variant_overrides.import_date').
|
|
where.not(variant_overrides: { import_date: nil }).
|
|
order('import_date DESC')
|
|
}
|
|
|
|
localize_number :price
|
|
|
|
def self.indexed(hub)
|
|
for_hubs(hub).preload(:variant).index_by(&:variant)
|
|
end
|
|
|
|
def stock_overridden?
|
|
# If count_on_hand is present, it means on_demand is false
|
|
# See StockSettingsOverrideValidation for details
|
|
count_on_hand.present?
|
|
end
|
|
|
|
def use_producer_stock_settings?
|
|
on_demand.nil?
|
|
end
|
|
|
|
def move_stock!(quantity)
|
|
unless stock_overridden?
|
|
Bugsnag.notify RuntimeError.new "Attempting to move stock of a VariantOverride " \
|
|
"without a count_on_hand specified."
|
|
return
|
|
end
|
|
|
|
if quantity > 0
|
|
increment! :count_on_hand, quantity
|
|
elsif quantity < 0
|
|
decrement! :count_on_hand, -quantity
|
|
end
|
|
end
|
|
|
|
def default_stock?
|
|
default_stock.present?
|
|
end
|
|
|
|
def reset_stock!
|
|
if resettable
|
|
if default_stock?
|
|
self.attributes = { on_demand: false, count_on_hand: default_stock }
|
|
save
|
|
else
|
|
Bugsnag.notify RuntimeError.new "Attempting to reset stock level for a variant " \
|
|
"with no default stock level."
|
|
end
|
|
end
|
|
self
|
|
end
|
|
|
|
def deletable?
|
|
price.blank? &&
|
|
count_on_hand.blank? &&
|
|
default_stock.blank? &&
|
|
resettable.blank? &&
|
|
sku.nil? &&
|
|
on_demand.nil?
|
|
end
|
|
end
|