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

39 lines
1.0 KiB
Ruby
Raw Normal View History

2022-08-19 19:59:13 +02:00
# frozen_string_literal: true
2022-12-28 17:51:27 +01:00
# Order is a model used to hold orders data
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-09-09 16:35:49 +02:00
belongs_to :invoice
2022-08-19 19:59:13 +02:00
has_many :order_items, dependent: :destroy
has_one :payment_gateway_object, as: :item, dependent: :destroy
2022-09-15 20:19:19 +02:00
has_many :order_activities, dependent: :destroy
2022-08-19 19:59:13 +02:00
2022-09-16 17:54:41 +02:00
ALL_STATES = %w[cart paid payment_failed refunded in_progress ready canceled delivered].freeze
2022-08-19 19:59:13 +02:00
enum state: ALL_STATES.zip(ALL_STATES).to_h
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
def generate_reference(_date = Time.current)
2022-09-09 10:43:44 +02:00
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