mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
order extends to payment document
This commit is contained in:
parent
453954e2b9
commit
3a669109b5
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Order is a model for the user hold information of order
|
||||
class Order < ApplicationRecord
|
||||
class Order < PaymentDocument
|
||||
belongs_to :statistic_profile
|
||||
belongs_to :operator_profile, class_name: 'InvoicingProfile'
|
||||
has_many :order_items, dependent: :destroy
|
||||
@ -15,8 +15,17 @@ class Order < ApplicationRecord
|
||||
|
||||
validates :token, :state, presence: true
|
||||
|
||||
def set_wallet_transaction(amount, transaction_id)
|
||||
self.wallet_amount = amount
|
||||
self.wallet_transaction_id = transaction_id
|
||||
before_create :add_environment
|
||||
|
||||
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]
|
||||
end
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ class PaymentSchedule < PaymentDocument
|
||||
belongs_to :coupon
|
||||
belongs_to :invoicing_profile
|
||||
belongs_to :statistic_profile
|
||||
belongs_to :operator_profile, foreign_key: :operator_profile_id, class_name: 'InvoicingProfile'
|
||||
belongs_to :operator_profile, class_name: 'InvoicingProfile'
|
||||
|
||||
has_many :payment_schedule_items
|
||||
has_many :payment_gateway_objects, as: :item
|
||||
@ -61,9 +61,7 @@ class PaymentSchedule < PaymentDocument
|
||||
payment_schedule_objects.find_by(main: true)
|
||||
end
|
||||
|
||||
def user
|
||||
invoicing_profile.user
|
||||
end
|
||||
delegate :user, to: :invoicing_profile
|
||||
|
||||
# for debug & used by rake task "fablab:maintenance:regenerate_schedules"
|
||||
def regenerate_pdf
|
||||
|
@ -32,6 +32,18 @@ class PaymentDocumentService
|
||||
reference.gsub!(/X\[([^\]]+)\]/, ''.to_s)
|
||||
end
|
||||
|
||||
# remove information about refunds (R[text])
|
||||
reference.gsub!(/R\[([^\]]+)\]/, ''.to_s)
|
||||
# remove information about payment schedule (S[text])
|
||||
reference.gsub!(/S\[([^\]]+)\]/, ''.to_s)
|
||||
elsif document.is_a? Order
|
||||
# information about online selling (X[text])
|
||||
if document.paid_by_card?
|
||||
reference.gsub!(/X\[([^\]]+)\]/, '\1')
|
||||
else
|
||||
reference.gsub!(/X\[([^\]]+)\]/, ''.to_s)
|
||||
end
|
||||
|
||||
# remove information about refunds (R[text])
|
||||
reference.gsub!(/R\[([^\]]+)\]/, ''.to_s)
|
||||
# remove information about payment schedule (S[text])
|
||||
|
@ -32,6 +32,7 @@ module Payments::PaymentConcern
|
||||
order.order_items.each do |item|
|
||||
ProductService.update_stock(item.orderable, 'external', 'sold', -item.quantity, item.id)
|
||||
end
|
||||
order.reference = order.generate_reference
|
||||
order.save
|
||||
order.reload
|
||||
end
|
||||
|
@ -0,0 +1,6 @@
|
||||
class AddFootprintAndEnvironmentToOrder < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :orders, :footprint, :string
|
||||
add_column :orders, :environment, :string
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_093503) do
|
||||
ActiveRecord::Schema.define(version: 2022_08_26_133518) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "fuzzystrmatch"
|
||||
@ -471,6 +471,8 @@ ActiveRecord::Schema.define(version: 2022_08_26_093503) do
|
||||
t.integer "wallet_amount"
|
||||
t.integer "wallet_transaction_id"
|
||||
t.string "payment_method"
|
||||
t.string "footprint"
|
||||
t.string "environment"
|
||||
t.index ["operator_profile_id"], name: "index_orders_on_operator_profile_id"
|
||||
t.index ["statistic_profile_id"], name: "index_orders_on_statistic_profile_id"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user