mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-15 04:14:24 +00:00
Merge pull request #11297 from mkllnk/require-belongs-to--part2
Require belongs_to associations by default
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AdjustmentMetadata < ApplicationRecord
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :adjustment, class_name: 'Spree::Adjustment'
|
||||
belongs_to :enterprise
|
||||
end
|
||||
|
||||
@@ -5,8 +5,6 @@ require 'open_food_network/column_preference_defaults'
|
||||
class ColumnPreference < ApplicationRecord
|
||||
extend OpenFoodNetwork::ColumnPreferenceDefaults
|
||||
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
# Non-persisted attributes that only have one
|
||||
# setting (ie. the default) for a given column
|
||||
attr_accessor :name
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CoordinatorFee < ApplicationRecord
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :order_cycle
|
||||
belongs_to :enterprise_fee
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class CustomTab < ApplicationRecord
|
||||
belongs_to :enterprise, optional: false
|
||||
belongs_to :enterprise
|
||||
|
||||
validates :title, presence: true, length: { maximum: 20 }
|
||||
end
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
class Customer < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
searchable_attributes :first_name, :last_name, :email, :code
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
class DistributorPaymentMethod < ApplicationRecord
|
||||
self.table_name = "distributors_payment_methods"
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :payment_method, class_name: "Spree::PaymentMethod", touch: true
|
||||
belongs_to :distributor, class_name: "Enterprise", touch: true
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
class DistributorShippingMethod < ApplicationRecord
|
||||
self.table_name = "distributors_shipping_methods"
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :shipping_method, class_name: "Spree::ShippingMethod", touch: true
|
||||
belongs_to :distributor, class_name: "Enterprise", touch: true
|
||||
|
||||
@@ -44,7 +44,7 @@ class Enterprise < ApplicationRecord
|
||||
dependent: :destroy
|
||||
has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id'
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
belongs_to :business_address, class_name: 'Spree::Address', dependent: :destroy
|
||||
belongs_to :business_address, optional: true, class_name: 'Spree::Address', dependent: :destroy
|
||||
has_many :enterprise_fees
|
||||
has_many :enterprise_roles, dependent: :destroy
|
||||
has_many :users, through: :enterprise_roles
|
||||
@@ -108,8 +108,7 @@ class Enterprise < ApplicationRecord
|
||||
validates :name, presence: true
|
||||
validate :name_is_unique
|
||||
validates :sells, presence: true, inclusion: { in: SELLS }
|
||||
validates :address, presence: true, associated: true
|
||||
validates :owner, presence: true
|
||||
validates :address, associated: true
|
||||
validates :permalink, uniqueness: true, presence: true
|
||||
validate :shopfront_taxons
|
||||
validate :shopfront_producers
|
||||
|
||||
@@ -6,7 +6,7 @@ class EnterpriseFee < ApplicationRecord
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :enterprise
|
||||
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
|
||||
belongs_to :tax_category, optional: true, class_name: 'Spree::TaxCategory'
|
||||
|
||||
has_many :coordinator_fees, dependent: :destroy
|
||||
has_many :order_cycles, through: :coordinator_fees
|
||||
|
||||
@@ -8,10 +8,10 @@ class EnterpriseGroup < ApplicationRecord
|
||||
acts_as_list
|
||||
|
||||
has_and_belongs_to_many :enterprises, join_table: 'enterprise_groups_enterprises'
|
||||
belongs_to :owner, class_name: 'Spree::User', inverse_of: :owned_groups
|
||||
belongs_to :owner, class_name: 'Spree::User', inverse_of: :owned_groups, optional: true
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
accepts_nested_attributes_for :address
|
||||
validates :address, presence: true, associated: true
|
||||
validates :address, associated: true
|
||||
before_validation :set_undefined_address_fields
|
||||
before_validation :set_unused_address_fields
|
||||
before_validation :sanitize_permalink
|
||||
@@ -46,10 +46,14 @@ class EnterpriseGroup < ApplicationRecord
|
||||
}
|
||||
|
||||
def set_unused_address_fields
|
||||
return if address.blank?
|
||||
|
||||
address.firstname = address.lastname = address.company = I18n.t(:unused)
|
||||
end
|
||||
|
||||
def set_undefined_address_fields
|
||||
return if address.blank?
|
||||
|
||||
address.phone.present? || address.phone = I18n.t(:undefined)
|
||||
address.address1.present? || address.address1 = I18n.t(:undefined)
|
||||
address.city.present? || address.city = I18n.t(:undefined)
|
||||
|
||||
@@ -5,7 +5,6 @@ class EnterpriseRelationship < ApplicationRecord
|
||||
belongs_to :child, class_name: 'Enterprise', touch: true
|
||||
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
|
||||
|
||||
validates :parent, :child, presence: true
|
||||
validates :child_id, uniqueness: {
|
||||
scope: :parent_id,
|
||||
message: I18n.t('validation_msg_relationship_already_established')
|
||||
|
||||
@@ -4,7 +4,6 @@ class EnterpriseRole < ApplicationRecord
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
belongs_to :enterprise
|
||||
|
||||
validates :user, :enterprise, presence: true
|
||||
validates :enterprise_id,
|
||||
uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
# shopfront (outgoing products). But the set of shown products can be smaller
|
||||
# than all incoming products.
|
||||
class Exchange < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :order_cycle
|
||||
@@ -88,7 +90,6 @@ class Exchange < ApplicationRecord
|
||||
exchange = dup
|
||||
exchange.order_cycle = new_order_cycle
|
||||
exchange.enterprise_fee_ids = enterprise_fee_ids
|
||||
exchange.tag_ids = tag_ids
|
||||
exchange.save!
|
||||
clone_all_exchange_variants(exchange.id)
|
||||
exchange
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ExchangeFee < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :exchange
|
||||
belongs_to :enterprise_fee
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ExchangeVariant < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :exchange
|
||||
belongs_to :variant, class_name: 'Spree::Variant'
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class InventoryItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
belongs_to :variant, class_name: "Spree::Variant"
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Invoice < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
serialize :data, Hash
|
||||
before_validation :serialize_order
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
require 'open_food_network/scope_variant_to_hub'
|
||||
|
||||
class OrderCycle < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :orders_open_at, :orders_close_at, :coordinator_id
|
||||
searchable_scopes :active, :inactive, :active_or_complete, :upcoming, :closed, :not_closed,
|
||||
:dated, :undated, :soonest_opening, :soonest_closing, :most_recently_closed
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class OrderCycleSchedule < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :schedule
|
||||
belongs_to :order_cycle
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProducerProperty < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :producer, class_name: 'Enterprise', touch: true
|
||||
belongs_to :property, class_name: 'Spree::Property'
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# This reduces the need to keep Orders in sync with their parent Subscriptions
|
||||
|
||||
class ProxyOrder < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
belongs_to :subscription
|
||||
belongs_to :order_cycle
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ReportRenderingOptions < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
serialize :options, Hash
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ module Spree
|
||||
class Address < ApplicationRecord
|
||||
include AddressDisplay
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :firstname, :lastname, :phone, :full_name
|
||||
searchable_associations :country, :state
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ module Spree
|
||||
class Adjustment < ApplicationRecord
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
# Deletion of metadata is handled in the database.
|
||||
# So we don't need the option `dependent: :destroy` as long as
|
||||
# AdjustmentMetadata has no destroy logic itself.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Asset < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :viewable, polymorphic: true, touch: true
|
||||
acts_as_list scope: :viewable
|
||||
end
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Calculator < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :calculable, polymorphic: true
|
||||
|
||||
# This method must be overriden in concrete calculator.
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class CreditCard < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :payment_method
|
||||
belongs_to :user
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class InventoryUnit < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant"
|
||||
belongs_to :order, class_name: "Spree::Order"
|
||||
belongs_to :shipment, class_name: "Spree::Shipment"
|
||||
|
||||
@@ -8,6 +8,8 @@ module Spree
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include LineItemStockChanges
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :price, :quantity, :order_id, :variant_id, :tax_category_id
|
||||
searchable_associations :order, :order_cycle, :variant, :product, :supplier, :tax_category
|
||||
searchable_scopes :with_tax, :without_tax
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class LogEntry < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :source, polymorphic: true
|
||||
|
||||
# Fix for Spree #1767
|
||||
|
||||
@@ -13,6 +13,8 @@ module Spree
|
||||
include Balance
|
||||
include SetUnusedAddressFields
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id,
|
||||
:order_cycle_id, :email, :total, :customer_id
|
||||
searchable_associations :shipping_method, :bill_address, :distributor
|
||||
|
||||
@@ -7,6 +7,8 @@ module Spree
|
||||
include Spree::Payment::Processing
|
||||
extend Spree::LocalizedNumber
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
localize_number :amount
|
||||
|
||||
IDENTIFIER_CHARS = (('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze
|
||||
|
||||
@@ -7,6 +7,8 @@ module Spree
|
||||
include CalculatedAdjustments
|
||||
include PaymentMethodDistributors
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
acts_as_paranoid
|
||||
|
||||
@@ -26,14 +28,12 @@ module Spree
|
||||
scope :production, -> { where(environment: 'production') }
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
where(nil)
|
||||
else
|
||||
joins(:distributors).
|
||||
where('distributors_payment_methods.distributor_id IN (?)',
|
||||
user.enterprises.select(&:id)).
|
||||
select('DISTINCT spree_payment_methods.*')
|
||||
end
|
||||
return where(nil) if user.admin?
|
||||
|
||||
joins(:distributors).
|
||||
where('distributors_payment_methods.distributor_id IN (?)',
|
||||
user.enterprises.select(&:id)).
|
||||
select('DISTINCT spree_payment_methods.*')
|
||||
}
|
||||
|
||||
scope :for_distributors, ->(distributors) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Price < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid without_default_scope: true
|
||||
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
|
||||
@@ -25,6 +25,8 @@ module Spree
|
||||
class Product < ApplicationRecord
|
||||
include ProductStock
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
|
||||
@@ -32,8 +34,8 @@ module Spree
|
||||
searchable_scopes :active, :with_properties
|
||||
|
||||
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
|
||||
belongs_to :supplier, class_name: 'Enterprise', touch: true
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
|
||||
belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon', optional: false, touch: true
|
||||
|
||||
has_one :image, class_name: "Spree::Image", as: :viewable, dependent: :destroy
|
||||
|
||||
@@ -52,9 +54,6 @@ module Spree
|
||||
validates :name, presence: true
|
||||
validates :shipping_category, presence: true
|
||||
|
||||
validates :supplier, presence: true
|
||||
validates :primary_taxon, presence: true
|
||||
|
||||
validates :variant_unit, presence: true
|
||||
validates :unit_value, presence:
|
||||
{ if: ->(p) { %w(weight volume).include?(p.variant_unit) && new_record? } }
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ProductProperty < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :product, class_name: "Spree::Product", touch: true
|
||||
belongs_to :property, class_name: 'Spree::Property'
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ReturnAuthorization < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations
|
||||
|
||||
@@ -4,6 +4,8 @@ require 'ostruct'
|
||||
|
||||
module Spree
|
||||
class Shipment < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation'
|
||||
|
||||
@@ -8,8 +8,6 @@ module Spree
|
||||
back_end: "back_end"
|
||||
}.freeze
|
||||
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
acts_as_paranoid
|
||||
acts_as_taggable
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ShippingMethodCategory < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
|
||||
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory',
|
||||
inverse_of: :shipping_method_categories
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ShippingRate < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :shipment, class_name: 'Spree::Shipment'
|
||||
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class State < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :country, class_name: 'Spree::Country'
|
||||
|
||||
validates :country, :name, presence: true
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StateChange < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :stateful, polymorphic: true
|
||||
before_create :assign_user
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockLocation < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location
|
||||
has_many :stock_movements, through: :stock_items
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class StockMovement < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :stock_item, class_name: 'Spree::StockItem'
|
||||
belongs_to :originator, polymorphic: true
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ end
|
||||
|
||||
module Spree
|
||||
class TaxRate < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
include CalculatedAdjustments
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class Taxon < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_nested_set dependent: :destroy
|
||||
|
||||
belongs_to :taxonomy, class_name: 'Spree::Taxonomy', touch: true
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class TokenizedPermission < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :permissable, polymorphic: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,8 @@ module Spree
|
||||
class User < ApplicationRecord
|
||||
include SetUnusedAddressFields
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :email
|
||||
|
||||
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
|
||||
|
||||
@@ -11,6 +11,8 @@ module Spree
|
||||
include VariantUnits::VariantAndLineItemNaming
|
||||
include VariantStock
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
searchable_attributes :sku, :display_as, :display_name
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module Spree
|
||||
class ZoneMember < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members
|
||||
belongs_to :zoneable, polymorphic: true
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StripeAccount < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
validates :stripe_user_id, :stripe_publishable_key, presence: true
|
||||
validates :enterprise_id, uniqueness: true
|
||||
|
||||
@@ -6,6 +6,8 @@ class Subscription < ApplicationRecord
|
||||
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check",
|
||||
"Spree::Gateway::StripeSCA"].freeze
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :shop_id, :canceled_at, :paused_at
|
||||
searchable_associations :shop
|
||||
searchable_scopes :active, :not_ended, :not_paused, :not_canceled
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubscriptionLineItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :subscription, inverse_of: :subscription_line_items
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagRule < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
|
||||
preference :customer_tags, :string, default: ""
|
||||
|
||||
@@ -6,6 +6,8 @@ class VariantOverride < ApplicationRecord
|
||||
extend Spree::LocalizedNumber
|
||||
include StockSettingsOverrideValidation
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :hub, class_name: 'Enterprise'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
class Voucher < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
belongs_to :enterprise, optional: false
|
||||
|
||||
@@ -227,7 +227,6 @@ module Openfoodnetwork
|
||||
# https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults
|
||||
config.load_defaults 6.1
|
||||
config.action_view.form_with_generates_remote_forms = false
|
||||
config.active_record.belongs_to_required_by_default = false
|
||||
config.active_record.cache_versioning = false
|
||||
config.active_record.has_many_inversing = false
|
||||
config.active_record.yaml_column_permitted_classes = [BigDecimal, Symbol]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RequireEnterpriseOnEnterpriseFee < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_fees, :enterprise_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class RequireParentAndChildOnEnterpriseRelationship < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_relationships, :parent_id, false
|
||||
change_column_null :enterprise_relationships, :child_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RequireEnterpriseRelationshipOnEnterpriseRelationshipPermission < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_relationship_permissions, :enterprise_relationship_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class RequireUserAndEnterpriseOnEnterpriseRole < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_roles, :user_id, false
|
||||
change_column_null :enterprise_roles, :enterprise_id, false
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
db/schema.rb
@@ -121,7 +121,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do
|
||||
end
|
||||
|
||||
create_table "enterprise_fees", id: :serial, force: :cascade do |t|
|
||||
t.integer "enterprise_id"
|
||||
t.integer "enterprise_id", null: false
|
||||
t.string "fee_type", limit: 255
|
||||
t.string "name", limit: 255
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
@@ -161,22 +161,22 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do
|
||||
end
|
||||
|
||||
create_table "enterprise_relationship_permissions", id: :serial, force: :cascade do |t|
|
||||
t.integer "enterprise_relationship_id"
|
||||
t.integer "enterprise_relationship_id", null: false
|
||||
t.string "name", limit: 255, null: false
|
||||
t.index ["enterprise_relationship_id"], name: "index_erp_on_erid"
|
||||
end
|
||||
|
||||
create_table "enterprise_relationships", id: :serial, force: :cascade do |t|
|
||||
t.integer "parent_id"
|
||||
t.integer "child_id"
|
||||
t.integer "parent_id", null: false
|
||||
t.integer "child_id", null: false
|
||||
t.index ["child_id"], name: "index_enterprise_relationships_on_child_id"
|
||||
t.index ["parent_id", "child_id"], name: "index_enterprise_relationships_on_parent_id_and_child_id", unique: true
|
||||
t.index ["parent_id"], name: "index_enterprise_relationships_on_parent_id"
|
||||
end
|
||||
|
||||
create_table "enterprise_roles", id: :serial, force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "enterprise_id"
|
||||
t.integer "user_id", null: false
|
||||
t.integer "enterprise_id", null: false
|
||||
t.boolean "receives_notifications", default: false
|
||||
t.index ["enterprise_id", "user_id"], name: "index_enterprise_roles_on_enterprise_id_and_user_id", unique: true
|
||||
t.index ["enterprise_id"], name: "index_enterprise_roles_on_enterprise_id"
|
||||
|
||||
@@ -95,6 +95,10 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do
|
||||
# This second line item will have a default a bigint value.
|
||||
order.line_items << create(:line_item)
|
||||
|
||||
# Create deterministic / aphabetical order of items:
|
||||
order.line_items[0].variant.product.update!(name: "Apple")
|
||||
order.line_items[1].variant.product.update!(name: "Banana")
|
||||
|
||||
# Generating the report used to raise:
|
||||
# > TypeError: no implicit conversion of BigDecimal into String
|
||||
expect(table_headers[4]).to eq "Total Units"
|
||||
|
||||
@@ -4,7 +4,8 @@ require 'spec_helper'
|
||||
|
||||
describe EnterpriseFee do
|
||||
describe "associations" do
|
||||
it { is_expected.to belong_to(:enterprise) }
|
||||
it { is_expected.to belong_to(:enterprise).required }
|
||||
it { is_expected.to belong_to(:tax_category).optional }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe EnterpriseGroup do
|
||||
describe "associations" do
|
||||
subject { build(:enterprise_group) }
|
||||
|
||||
it { is_expected.to belong_to(:owner).optional }
|
||||
it { is_expected.to belong_to(:address).required }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it "pass with name, description and address" do
|
||||
e = EnterpriseGroup.new
|
||||
|
||||
@@ -19,11 +19,11 @@ describe Enterprise do
|
||||
end
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to belong_to(:owner) }
|
||||
it { is_expected.to belong_to(:owner).required }
|
||||
it { is_expected.to have_many(:supplied_products) }
|
||||
it { is_expected.to have_many(:distributed_orders) }
|
||||
it { is_expected.to belong_to(:address) }
|
||||
it { is_expected.to belong_to(:business_address) }
|
||||
it { is_expected.to belong_to(:address).required }
|
||||
it { is_expected.to belong_to(:business_address).optional }
|
||||
it { is_expected.to have_many(:vouchers) }
|
||||
|
||||
it "destroys enterprise roles upon its own demise" do
|
||||
@@ -125,12 +125,6 @@ describe Enterprise do
|
||||
is_expected.to validate_uniqueness_of(:permalink)
|
||||
end
|
||||
|
||||
it "requires an owner" do
|
||||
enterprise = build_stubbed(:enterprise, owner: nil)
|
||||
expect(enterprise).not_to be_valid
|
||||
expect(enterprise.errors[:owner].first).to eq "can't be blank"
|
||||
end
|
||||
|
||||
describe "name uniqueness" do
|
||||
let(:owner) { create(:user, email: 'owner@example.com') }
|
||||
let!(:enterprise) { create(:enterprise, name: 'Enterprise', owner: owner) }
|
||||
@@ -823,7 +817,7 @@ describe Enterprise do
|
||||
it "should return only parent producers" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(Enterprise.parents_of_one_union_others(supplier, nil)).to include(distributor)
|
||||
@@ -833,7 +827,7 @@ describe Enterprise do
|
||||
another_enterprise = create(:enterprise)
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(
|
||||
@@ -844,7 +838,7 @@ describe Enterprise do
|
||||
it "does not find child in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
expect(Enterprise.parents_of_one_union_others(distributor, nil)).not_to include(supplier)
|
||||
@@ -868,7 +862,7 @@ describe Enterprise do
|
||||
it "finds parent in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
product = create(:product)
|
||||
order_cycle = create(
|
||||
:simple_order_cycle,
|
||||
@@ -884,7 +878,7 @@ describe Enterprise do
|
||||
it "does not find child in the relationship" do
|
||||
supplier = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor,
|
||||
child: supplier, permissions: [permission])
|
||||
product = create(:product)
|
||||
@@ -902,7 +896,7 @@ describe Enterprise do
|
||||
supplier = create(:supplier_enterprise)
|
||||
sender = create(:supplier_enterprise)
|
||||
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
||||
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
||||
permission = EnterpriseRelationshipPermission.new(name: "add_to_order_cycle")
|
||||
create(:enterprise_relationship, parent: distributor, child: supplier,
|
||||
permissions: [permission])
|
||||
product = create(:product)
|
||||
|
||||
@@ -11,10 +11,10 @@ module Spree
|
||||
it { is_expected.to have_one(:metadata) }
|
||||
it { is_expected.to have_many(:adjustments) }
|
||||
|
||||
it { is_expected.to belong_to(:adjustable) }
|
||||
it { is_expected.to belong_to(:originator) }
|
||||
it { is_expected.to belong_to(:order) }
|
||||
it { is_expected.to belong_to(:tax_category) }
|
||||
it { is_expected.to belong_to(:adjustable).optional }
|
||||
it { is_expected.to belong_to(:originator).optional }
|
||||
it { is_expected.to belong_to(:order).optional }
|
||||
it { is_expected.to belong_to(:tax_category).optional }
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
|
||||
@@ -6,6 +6,25 @@ class Spree::Gateway::Test < Spree::Gateway
|
||||
end
|
||||
|
||||
describe Spree::PaymentMethod do
|
||||
describe ".managed_by scope" do
|
||||
subject! { create(:payment_method) }
|
||||
let(:owner) { subject.distributors.first.owner }
|
||||
let(:other_user) { create(:user) }
|
||||
let(:admin) { create(:admin_user) }
|
||||
|
||||
it "returns everything for admins" do
|
||||
expect(Spree::PaymentMethod.managed_by(admin)).to eq [subject]
|
||||
end
|
||||
|
||||
it "returns payment methods of managed enterprises" do
|
||||
expect(Spree::PaymentMethod.managed_by(owner)).to eq [subject]
|
||||
end
|
||||
|
||||
it "returns nothing for other users" do
|
||||
expect(Spree::PaymentMethod.managed_by(other_user)).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
describe "#available" do
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
|
||||
|
||||
@@ -154,8 +154,8 @@ module Spree
|
||||
end
|
||||
|
||||
describe "associations" do
|
||||
it { is_expected.to belong_to(:supplier) }
|
||||
it { is_expected.to belong_to(:primary_taxon) }
|
||||
it { is_expected.to belong_to(:supplier).required }
|
||||
it { is_expected.to belong_to(:primary_taxon).required }
|
||||
end
|
||||
|
||||
describe "validations and defaults" do
|
||||
|
||||
@@ -4,13 +4,13 @@ require 'spec_helper'
|
||||
|
||||
describe Subscription, type: :model do
|
||||
describe "associations" do
|
||||
it { expect(subject).to belong_to(:shop) }
|
||||
it { expect(subject).to belong_to(:customer) }
|
||||
it { expect(subject).to belong_to(:schedule) }
|
||||
it { expect(subject).to belong_to(:shipping_method) }
|
||||
it { expect(subject).to belong_to(:payment_method) }
|
||||
it { expect(subject).to belong_to(:ship_address) }
|
||||
it { expect(subject).to belong_to(:bill_address) }
|
||||
it { expect(subject).to belong_to(:shop).optional }
|
||||
it { expect(subject).to belong_to(:customer).optional }
|
||||
it { expect(subject).to belong_to(:schedule).optional }
|
||||
it { expect(subject).to belong_to(:shipping_method).optional }
|
||||
it { expect(subject).to belong_to(:payment_method).optional }
|
||||
it { expect(subject).to belong_to(:ship_address).optional }
|
||||
it { expect(subject).to belong_to(:bill_address).optional }
|
||||
it { expect(subject).to have_many(:subscription_line_items) }
|
||||
it { expect(subject).to have_many(:order_cycles) }
|
||||
it { expect(subject).to have_many(:proxy_orders) }
|
||||
|
||||
@@ -5,16 +5,16 @@ require 'spec_helper'
|
||||
describe Sets::ModelSet do
|
||||
describe "updating" do
|
||||
it "creates new models" do
|
||||
attrs = { collection_attributes: { '1' => { name: 's1' },
|
||||
'2' => { name: 's2' } } }
|
||||
attrs = { collection_attributes: { '1' => { name: "Fantasia", iso_name: "FAN" },
|
||||
'2' => { name: "Utopia", iso_name: "UTO" } } }
|
||||
|
||||
ms = Sets::ModelSet.new(EnterpriseRelationshipPermission,
|
||||
EnterpriseRelationshipPermission.all,
|
||||
ms = Sets::ModelSet.new(Spree::Country,
|
||||
Spree::Country.all,
|
||||
attrs)
|
||||
|
||||
expect { ms.save }.to change(EnterpriseRelationshipPermission, :count).by(2)
|
||||
expect { ms.save }.to change(Spree::Country, :count).by(2)
|
||||
|
||||
expect(EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count).to eq(2)
|
||||
expect(Spree::Country.where(name: ["Fantasia", "Utopia"]).count).to eq(2)
|
||||
end
|
||||
|
||||
it "updates existing models" do
|
||||
|
||||
@@ -212,7 +212,9 @@ describe '
|
||||
end
|
||||
|
||||
it "displays $0.00 when a line item has no tax" do
|
||||
expect(page).to have_content "#{Spree::Product.first.name} (1g) 1 $0.00 $12.54"
|
||||
expect(page).to have_content Spree::Product.first.name
|
||||
expect(page).to have_content "(1g)"
|
||||
expect(page).to have_content "1 $0.00 $12.54"
|
||||
end
|
||||
|
||||
it "displays the taxes correctly" do
|
||||
@@ -343,7 +345,9 @@ describe '
|
||||
convert_pdf_to_page
|
||||
end
|
||||
it "displays $0.0 when a line item has no tax" do
|
||||
expect(page).to have_content "#{Spree::Product.first.name} (1g) 1 $0.00 $12.54"
|
||||
expect(page).to have_content Spree::Product.first.name
|
||||
expect(page).to have_content "(1g)"
|
||||
expect(page).to have_content "1 $0.00 $12.54"
|
||||
end
|
||||
|
||||
it "displays the added tax on the GST colum" do
|
||||
|
||||
Reference in New Issue
Block a user