1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/models/order.rb

40 lines
1.0 KiB
Ruby
Raw Normal View History

2022-08-19 19:59:13 +02:00
# frozen_string_literal: true
# Order is a model for the user hold information of order
2022-08-26 15:56:20 +02:00
class Order < PaymentDocument
2022-08-19 19:59:13 +02:00
belongs_to :statistic_profile
belongs_to :operator_profile, class_name: 'InvoicingProfile'
2022-08-26 20:10:21 +02:00
belongs_to :coupon
2022-08-19 19:59:13 +02:00
has_many :order_items, dependent: :destroy
has_one :payment_gateway_object, as: :item
2022-08-19 19:59:13 +02:00
ALL_STATES = %w[cart in_progress ready canceled return].freeze
2022-08-19 19:59:13 +02:00
enum state: ALL_STATES.zip(ALL_STATES).to_h
PAYMENT_STATES = %w[paid failed refunded].freeze
2022-08-25 08:52:17 +02:00
enum payment_state: PAYMENT_STATES.zip(PAYMENT_STATES).to_h
2022-08-19 19:59:13 +02:00
validates :token, :state, presence: true
2022-08-26 11:19:09 +02:00
2022-08-26 15:56:20 +02:00
before_create :add_environment
after_create :update_reference
2022-08-26 15:56:20 +02:00
2022-08-26 20:10:21 +02:00
delegate :user, to: :statistic_profile
2022-09-09 10:43:44 +02:00
def generate_reference(_date = DateTime.current)
self.reference = PaymentDocumentService.generate_order_number(self)
end
2022-08-26 15:56:20 +02:00
def footprint_children
order_items
end
def paid_by_card?
!payment_gateway_object.nil? && payment_method == 'card'
end
def self.columns_out_of_footprint
%w[payment_method]
2022-08-26 11:19:09 +02:00
end
2022-08-19 19:59:13 +02:00
end