effective_orders 6.5.9 → 6.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42d67014fe256ed7ef96ee079c776855b73053d33bc116042ebd1a1c5e17bc5c
4
- data.tar.gz: cd0503035984b062eaed51f779c10fb1124e59b97598ae2ed2cc503d0c8ddb11
3
+ metadata.gz: 1e85399d8a94ed81ae67ced9f120983d83a626cbd7bd0fe410610803f7b65e32
4
+ data.tar.gz: f903881c98703d5ac9e3d6a7f356b45b5b02280b0ad4dc6125de970d887d3e2a
5
5
  SHA512:
6
- metadata.gz: f5418c8644cf04e5bb73bd1266cbe81215db8b02d2065b48559b0dc12be511ba0b62f64910ffa7a867f84e6a54dd3d975a1236243eb6674c04aaf47ceb065ddf
7
- data.tar.gz: 3488074b6f0479e0f9c8d095a0799f551c8db36804d263c208069be52c3471d35b7fc769087ac8c08964dda51823988d6155022075e5e9642d4ea29f8d49f0d2
6
+ metadata.gz: 8163a7d6cf97d35c85e1464fee0932d4e4159513c01d76e5d281598a52f67e2259455af9e35aeb46ee61fa97bd4908e7e440684e22165120906072f43f70bb40
7
+ data.tar.gz: 88f47fabff177758de90fb826424626af5496b14fc4a56e28e9a949a5477d68b8edba970c3413387aee4b50b09ccf84ec79b34cc1996482f3c8524ba44553299
@@ -44,6 +44,8 @@ module Admin
44
44
  order.purchased_at&.strftime('%F %H:%M') || ('pending refund' if order.pending_refund?) || ("pending #{order.payment_provider}" if order.deferred?) || 'not purchased'
45
45
  end
46
46
 
47
+ col :purchased_by, search: :string, visible: EffectiveOrders.organization_enabled?
48
+
47
49
  if attributes[:user_id].blank?
48
50
  col :user, search: :string
49
51
  col :billing_name, visible: false
@@ -17,6 +17,12 @@ module Admin
17
17
  end
18
18
 
19
19
  col :purchased_at
20
+ col :purchased_by, search: :string, visible: EffectiveOrders.organization_enabled?
21
+
22
+ if EffectiveOrders.organization_enabled?
23
+ col :organization
24
+ end
25
+
20
26
  col :user
21
27
  col :order_items
22
28
  col :payment_provider, search: EffectiveOrders.payment_providers
@@ -49,10 +55,9 @@ module Admin
49
55
  end
50
56
 
51
57
  collection do
52
- Effective::Order.purchased
58
+ Effective::Order.purchased.deep
53
59
  .where(purchased_at: date_range)
54
60
  .where('total != 0')
55
- .includes(:user, [order_items: :purchasable])
56
61
  end
57
62
  end
58
63
  end
@@ -28,6 +28,8 @@ class EffectiveOrdersDatatable < Effective::Datatable
28
28
  col :purchased_at do |order|
29
29
  order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
30
30
  end
31
+
32
+ col :purchased_by, search: :string, visible: EffectiveOrders.organization_enabled?
31
33
  end
32
34
 
33
35
  if EffectiveOrders.billing_address
@@ -21,8 +21,8 @@ module Effective
21
21
  subject = subject_for(__method__, "Order Receipt: ##{@order.to_param}", resource, opts)
22
22
  headers = headers_for(resource, opts)
23
23
 
24
- # Just @order.email here. Not everyone.
25
- mail(to: @order.email, cc: @order.cc.presence, subject: subject, **headers)
24
+ # Just to the purchaser. Not everyone.
25
+ mail(to: @order.emails.first, cc: @order.cc.presence, subject: subject, **headers)
26
26
  end
27
27
 
28
28
  # This is sent when an admin creates a new order or /admin/orders/new
@@ -31,13 +31,17 @@ module Effective
31
31
  # If we want to use orders in a has_many way
32
32
  belongs_to :parent, polymorphic: true, optional: true
33
33
 
34
- belongs_to :user, polymorphic: true, optional: true, validate: false # This is the buyer of the order. We validate it below.
34
+ # This is user the order is for
35
+ belongs_to :user, polymorphic: true, optional: true, validate: false
35
36
  accepts_nested_attributes_for :user, allow_destroy: false, update_only: true
36
37
 
37
38
  # When an organization is present, any user with role :billing in that organization can purchase this order
38
39
  belongs_to :organization, polymorphic: true, optional: true, validate: false
39
40
  accepts_nested_attributes_for :organization, allow_destroy: false, update_only: true
40
41
 
42
+ # When purchased, this is the user that purchased it.
43
+ belongs_to :purchased_by, polymorphic: true, optional: true, validate: false
44
+
41
45
  has_many :order_items, -> { order(:id) }, inverse_of: :order, dependent: :delete_all
42
46
  accepts_nested_attributes_for :order_items, allow_destroy: true, reject_if: :all_blank
43
47
 
@@ -75,7 +79,7 @@ module Effective
75
79
 
76
80
  serialize :payment, Hash
77
81
 
78
- scope :deep, -> { includes(:addresses, :user, :organization, order_items: :purchasable) }
82
+ scope :deep, -> { includes(:addresses, :user, :purchased_by, :organization, order_items: :purchasable) }
79
83
  scope :sorted, -> { order(:id) }
80
84
 
81
85
  scope :purchased, -> { where(state: EffectiveOrders::PURCHASED) }
@@ -605,9 +609,10 @@ module Effective
605
609
  state: EffectiveOrders::PURCHASED,
606
610
  skip_buyer_validations: skip_buyer_validations,
607
611
 
608
- payment: payment_to_h(payment.presence || 'none'),
609
612
  purchased_at: (purchased_at.presence || Time.zone.now),
613
+ purchased_by: (purchased_by.presence || current_user),
610
614
 
615
+ payment: payment_to_h(payment.presence || 'none'),
611
616
  payment_provider: (provider.presence || 'none'),
612
617
  payment_card: (card.presence || 'none')
613
618
  )
@@ -707,7 +712,7 @@ module Effective
707
712
 
708
713
  # These are all the emails we send all notifications to
709
714
  def emails
710
- ([email] + [user.try(:email)] + Array(organization.try(:billing_emails))).map(&:presence).compact.uniq
715
+ ([purchased_by.try(:email)] + [email] + [user.try(:email)] + Array(organization.try(:billing_emails))).map(&:presence).compact.uniq
711
716
  end
712
717
 
713
718
  # Doesn't control anything. Purely for the flash messaging
@@ -13,6 +13,9 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
13
13
  t.string :state
14
14
  t.datetime :purchased_at
15
15
 
16
+ t.integer :purchased_by_id
17
+ t.string :purchased_by_type
18
+
16
19
  t.text :note
17
20
  t.text :note_to_buyer
18
21
  t.text :note_internal
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.5.9'.freeze
2
+ VERSION = '6.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.5.9
4
+ version: 6.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-27 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails