effective_orders 6.5.8 → 6.6.0

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: 8c9eabbfa8db6fb53919cf3dae73c783f774c3af7fd242f6ca937f434d39e54e
4
- data.tar.gz: ee95193ee1ef29b1c3854d4fa82c73f6d305b16edfcc73c2507b0f3922201ec8
3
+ metadata.gz: 4e804f4ca70a3cb57e200abd2dc81f3148db743f3f76680dd3368f34a631d355
4
+ data.tar.gz: d88242d6315a34d6fe4aca05f44b8a0445e688cea8265439659d7be693010f59
5
5
  SHA512:
6
- metadata.gz: fc985176f4855ead79fe1394f49cb55551c24ab23c2913177874d78f38d24b51cef62bd0acb6a2543ba8e4f7ca63d3df40358494a897085c8d7deb2848c73440
7
- data.tar.gz: 93afb3bd5f5588140dcf1efe0af860f87e7e30e9d8e9833bdca00ef9b03abcb3b50312cd0e3fd277b30448ae3f2e484760ba7c52187a3c37ef38c83c59879395
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
@@ -3,6 +3,7 @@
3
3
  %thead
4
4
  %tr
5
5
  %th Order
6
+ %th Buyer
6
7
  %th Date
7
8
  %th Description
8
9
  %th
@@ -10,10 +11,13 @@
10
11
  - orders.each do |order|
11
12
  %tr
12
13
  %td ##{order.to_param}
14
+ %td
15
+ = [order.organization, order.user].compact.join('<br>').html_safe
13
16
  %td
14
17
  = (order.purchased? ? 'Purchased' : 'Created')
15
18
  = (order.purchased_at || order.created_at).strftime("%F %H:%M")
16
- %td= order_summary(order)
19
+ %td
20
+ = order_summary(order)
17
21
  %td
18
22
  - if order.pending? || order.confirmed?
19
23
  = link_to_checkout(order: order)
@@ -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.8'.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.8
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-21 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