effective_orders 6.5.9 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42d67014fe256ed7ef96ee079c776855b73053d33bc116042ebd1a1c5e17bc5c
4
- data.tar.gz: cd0503035984b062eaed51f779c10fb1124e59b97598ae2ed2cc503d0c8ddb11
3
+ metadata.gz: 4e804f4ca70a3cb57e200abd2dc81f3148db743f3f76680dd3368f34a631d355
4
+ data.tar.gz: d88242d6315a34d6fe4aca05f44b8a0445e688cea8265439659d7be693010f59
5
5
  SHA512:
6
- metadata.gz: f5418c8644cf04e5bb73bd1266cbe81215db8b02d2065b48559b0dc12be511ba0b62f64910ffa7a867f84e6a54dd3d975a1236243eb6674c04aaf47ceb065ddf
7
- data.tar.gz: 3488074b6f0479e0f9c8d095a0799f551c8db36804d263c208069be52c3471d35b7fc769087ac8c08964dda51823988d6155022075e5e9642d4ea29f8d49f0d2
6
+ metadata.gz: fc681292de818d3248e8cf757a80ffe1efa097685036ded498c6f322a0181e175d069f85b551139cd1f52253dd866da3f3c3708aa3bcb6f436ccb634814bc853
7
+ data.tar.gz: fe83a4ee4de83547f88e18b75d30996c884d7edb3721161cf64b180ead5b7780da27857f6ba342d7657242cd73655461d824f6f1780e1157563f3ac94440e555
@@ -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
48
+
47
49
  if attributes[:user_id].blank?
48
50
  col :user, search: :string
49
51
  col :billing_name, visible: false
@@ -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
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.0'.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.0
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-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails