mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +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
70 lines
2.1 KiB
Ruby
70 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class EnterpriseFee < ApplicationRecord
|
|
include CalculatedAdjustments
|
|
|
|
acts_as_paranoid
|
|
|
|
belongs_to :enterprise
|
|
belongs_to :tax_category, optional: true, class_name: 'Spree::TaxCategory'
|
|
|
|
has_many :coordinator_fees, dependent: :destroy
|
|
has_many :order_cycles, through: :coordinator_fees
|
|
|
|
has_many :exchange_fees, dependent: :destroy
|
|
has_many :exchanges, through: :exchange_fees
|
|
|
|
FEE_TYPES = %w(packing transport admin sales fundraising).freeze
|
|
PER_ORDER_CALCULATORS = ['Calculator::FlatRate',
|
|
'Calculator::FlexiRate',
|
|
'Calculator::PriceSack'].freeze
|
|
|
|
validates :fee_type, inclusion: { in: FEE_TYPES }
|
|
validates :name, presence: true
|
|
validates :enterprise_id, presence: true
|
|
|
|
before_save :ensure_valid_tax_category_settings
|
|
|
|
scope :for_enterprise, lambda { |enterprise| where(enterprise_id: enterprise) }
|
|
scope :for_enterprises, lambda { |enterprises| where(enterprise_id: enterprises) }
|
|
|
|
scope :managed_by, lambda { |user|
|
|
if user.has_spree_role?('admin')
|
|
where(nil)
|
|
else
|
|
where('enterprise_id IN (?)', user.enterprises.select(&:id))
|
|
end
|
|
}
|
|
|
|
scope :per_item, lambda {
|
|
joins(:calculator).where.not(spree_calculators: { type: PER_ORDER_CALCULATORS })
|
|
}
|
|
scope :per_order, lambda {
|
|
joins(:calculator).where('spree_calculators.type IN (?)', PER_ORDER_CALCULATORS)
|
|
}
|
|
|
|
def self.clear_all_adjustments(order)
|
|
order.all_adjustments.enterprise_fee.destroy_all
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_valid_tax_category_settings
|
|
# Setting an explicit tax_category removes any inheritance behaviour
|
|
# In the absence of any current changes to tax_category, setting
|
|
# inherits_tax_category to true will clear the tax_category
|
|
if tax_category_id_changed?
|
|
self.inherits_tax_category = false if tax_category.present?
|
|
elsif inherits_tax_category_changed?
|
|
self.tax_category_id = nil if inherits_tax_category?
|
|
end
|
|
|
|
if inherits_tax_category? && PER_ORDER_CALCULATORS.include?(calculator_type)
|
|
errors.add(:base, :inherit_tax_requires_per_item_calculator)
|
|
throw :abort
|
|
end
|
|
|
|
true
|
|
end
|
|
end
|