mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Merge pull request #12493 from cyrillefr/RedundantPresenceValidationOnBelongs_part_IV
Fix RedundantPresenceValidationOnBelongs on two files
This commit is contained in:
@@ -650,16 +650,14 @@ Rails/RedundantActiveRecordAllMethod:
|
||||
- 'app/models/spree/variant.rb'
|
||||
- 'spec/system/admin/product_import_spec.rb'
|
||||
|
||||
# Offense count: 9
|
||||
# Offense count: 7
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Rails/RedundantPresenceValidationOnBelongsTo:
|
||||
Exclude:
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/tax_rate.rb'
|
||||
- 'app/models/subscription_line_item.rb'
|
||||
- 'app/models/tag_rule.rb'
|
||||
- 'app/models/variant_override.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
|
||||
@@ -14,17 +14,14 @@ end
|
||||
|
||||
module Spree
|
||||
class TaxRate < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
include CalculatedAdjustments
|
||||
|
||||
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates
|
||||
belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates, optional: true
|
||||
belongs_to :tax_category, class_name: "Spree::TaxCategory", inverse_of: :tax_rates
|
||||
has_many :adjustments, as: :originator, dependent: nil
|
||||
|
||||
validates :amount, presence: true, numericality: true
|
||||
validates :tax_category, presence: true
|
||||
validates_with DefaultTaxZoneValidator
|
||||
|
||||
scope :by_zone, ->(zone) { where(zone_id: zone) }
|
||||
|
||||
@@ -6,15 +6,11 @@ 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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RequireTaxCategoryOnTaxRate < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :spree_tax_rates, :tax_category_id, false
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_05_10_041114) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_05_17_121235) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "plpgsql"
|
||||
@@ -869,7 +869,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_05_10_041114) do
|
||||
create_table "spree_tax_rates", id: :serial, force: :cascade do |t|
|
||||
t.decimal "amount", precision: 8, scale: 5
|
||||
t.integer "zone_id"
|
||||
t.integer "tax_category_id"
|
||||
t.integer "tax_category_id", null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.boolean "included_in_price", default: false
|
||||
|
||||
Reference in New Issue
Block a user