Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add some scopes to payments and store credits (#12077)
Łukasz Adamczykcf3da93eb4ad
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rbindex d1a24a8035..57ca0e1944 100644--- a/core/app/models/spree/payment.rb+++ b/core/app/models/spree/payment.rb@@ -65,6 +65,8 @@ module Spreescope :processing, -> { with_state('processing') }scope :failed, -> { with_state('failed') }+ scope :incomplete, -> { where.not(state: 'completed') }+scope :risky, -> { where("avs_response IN (?) OR (cvv_response_code IS NOT NULL and cvv_response_code != 'M') OR state = 'failed'", RISKY_AVS_CODES) }scope :valid, -> { where.not(state: INVALID_STATES) }diff --git a/core/app/models/spree/store_credit.rb b/core/app/models/spree/store_credit.rbindex 7cbec93ce3..a1f272ba06 100644--- a/core/app/models/spree/store_credit.rb+++ b/core/app/models/spree/store_credit.rb@@ -23,7 +23,10 @@ module Spreebelongs_to :created_by, class_name: "::#{Spree.admin_user_class}", foreign_key: 'created_by_id', optional: truebelongs_to :credit_type, class_name: 'Spree::StoreCreditType', foreign_key: 'type_id', optional: truebelongs_to :store, class_name: 'Spree::Store'+has_many :store_credit_events, class_name: 'Spree::StoreCreditEvent'+ has_many :payments, as: :source, class_name: 'Spree::Payment'+ has_many :orders, through: :payments, class_name: 'Spree::Order'validates :currency, :store, presence: truevalidates :amount, numericality: { greater_than: 0 }@@ -36,6 +39,10 @@ module Spreescope :order_by_priority, -> { includes(:credit_type).order('spree_store_credit_types.priority ASC') }+ scope :not_authorized, -> { where(amount_authorized: 0) }+ scope :not_used, -> { where(amount_authorized: 0) }+ scope :available, -> { not_authorized.not_used }+after_save :store_eventbefore_destroy :validate_no_amount_used