effective_orders 5.5.2 → 5.6.2

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: 496c6b24100359c7121e1903130d345ed5b13fabf41cf1a1e78be20be3d638c8
4
- data.tar.gz: a2451ac65694daa46c2386dd13754d6ed43ae2e9b8b34ff16903ec6c9591e888
3
+ metadata.gz: 4e419a31818cf5abba11e1330c5cf38e7637f144d9eacade387f919de7433973
4
+ data.tar.gz: 12a61662d772982f6ddff6f00bd990dfdab017a33ce011b55caf7f4507715010
5
5
  SHA512:
6
- metadata.gz: 24a8a97d2bc9c2b45680fc4e9f8c751245d5e83d69ff085a744f1e16709219cafb04c13c55fd88eda8a2b2707eaeea0dea48a2c9f66c682187720ef334aab1b7
7
- data.tar.gz: 14af91d8e9a56efe0e65d07348f4de7c2fc83a14df32d06b3e3cb40306b4469b575dfaf9c629a9f67369226da089b464d46c0be0cda1d3a5ca15a68b3693d6a4
6
+ metadata.gz: abc379d14277eb75eef1c315ad05d49bbd801211c8f4781951249421c6433f9e1fef5b5ff5e0348859ccab4a185bc4439ae0a06f0ba8e1bdc9b6bf9199f912ce
7
+ data.tar.gz: b189c07ee57a22ba4f3fb314da7078b7cf7d8f9d25ab85f3d37e6be74c8924cdc6ccac516053bf2ee0bbc182f8c80f1b4b82505cdd310a6d6bde02b0fff17dd2
@@ -14,38 +14,11 @@ module Admin
14
14
  submit :save, 'Duplicate', redirect: -> { effective_orders.new_admin_order_path(duplicate_id: resource.to_param) }
15
15
  submit :save, 'Checkout', redirect: -> { effective_orders.checkout_admin_order_path(resource) }
16
16
 
17
- def create
18
- @user = current_user.class.find_by_id(permitted_params[:user_id])
19
- @order = Effective::Order.new(user: @user)
20
-
21
- authorize_effective_order!
22
- error = nil
23
-
24
- Effective::Order.transaction do
25
- begin
26
- (permitted_params[:order_items_attributes] || {}).each do |_, item_attrs|
27
- purchasable = Effective::Product.new(item_attrs[:purchasable_attributes])
28
- @order.add(purchasable, quantity: item_attrs[:quantity])
29
- end
30
-
31
- @order.attributes = permitted_params.except(:order_items_attributes, :user_id)
32
- @order.pending!
33
-
34
- message = 'Successfully created order'
35
- message << ". A request for payment has been sent to #{@order.emails_send_to}" if @order.send_payment_request_to_buyer?
36
- flash[:success] = message
37
-
38
- redirect_to(admin_redirect_path) and return
39
- rescue => e
40
- error = e.message
41
- raise ActiveRecord::Rollback
42
- end
43
- end
44
-
45
- @page_title = 'New Order'
46
- flash.now[:danger] = flash_danger(@order) + error.to_s
47
- render :new
48
- end
17
+ submit :save, 'Save', success: -> {
18
+ message = flash_success(resource, params[:action])
19
+ message << ". A request for payment has been sent to #{resource.emails_send_to}" if resource.send_payment_request_to_buyer?
20
+ message
21
+ }
49
22
 
50
23
  # The show page posts to this action
51
24
  # See Effective::OrdersController checkout
@@ -58,21 +31,19 @@ module Admin
58
31
 
59
32
  if request.get?
60
33
  @order.assign_confirmed_if_valid!
61
- render :checkout and return
34
+ render(:checkout)
35
+ return
62
36
  end
63
37
 
64
- Effective::Order.transaction do
65
- begin
66
- @order.assign_attributes(checkout_params)
67
- @order.confirm!
68
- redirect_to(effective_orders.checkout_admin_order_path(@order)) and return
69
- rescue => e
70
- raise ActiveRecord::Rollback
71
- end
72
- end
38
+ # Otherwise a post
39
+ @order.assign_attributes(checkout_params)
73
40
 
74
- flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
75
- render :checkout
41
+ if (@order.confirm! rescue false)
42
+ redirect_to(effective_orders.checkout_admin_order_path(@order))
43
+ else
44
+ flash.now[:danger] = "Unable to proceed: #{flash_errors(@order)}. Please try again."
45
+ render :checkout
46
+ end
76
47
  end
77
48
 
78
49
  def destroy
@@ -124,15 +95,7 @@ module Admin
124
95
  private
125
96
 
126
97
  def permitted_params
127
- params.require(:effective_order).permit(:user_id, :user_type, :cc,
128
- :send_payment_request_to_buyer, :note_internal, :note_to_buyer,
129
- :payment_provider, :payment_card, :payment, :send_mark_as_paid_email_to_buyer,
130
- order_items_attributes: [
131
- :quantity, :_destroy, purchasable_attributes: [
132
- :name, :qb_item_name, :price, :tax_exempt
133
- ]
134
- ]
135
- )
98
+ params.require(:effective_order).permit!
136
99
  end
137
100
 
138
101
  def checkout_params
@@ -143,17 +106,5 @@ module Admin
143
106
  EffectiveResources.authorize!(self, action_name.to_sym, @order || Effective::Order)
144
107
  end
145
108
 
146
- def admin_redirect_path
147
- case params[:commit].to_s
148
- when 'Save' ; effective_orders.admin_order_path(@order)
149
- when 'Continue' ; effective_orders.admin_orders_path
150
- when 'Add New' ; effective_orders.new_admin_order_path(user_id: @order.user.try(:to_param))
151
- when 'Duplicate' ; effective_orders.new_admin_order_path(duplicate_id: @order.to_param)
152
- when 'Checkout' ; effective_orders.checkout_admin_order_path(@order.to_param)
153
- else
154
- effective_orders.admin_order_path(@order)
155
- end
156
- end
157
-
158
109
  end
159
110
  end
@@ -30,10 +30,10 @@ module Effective
30
30
  belongs_to :parent, polymorphic: true, optional: true
31
31
 
32
32
  belongs_to :user, polymorphic: true, validate: false # This is the buyer/user of the order. We validate it below.
33
- has_many :order_items, -> { order(:id) }, inverse_of: :order, dependent: :delete_all
33
+ accepts_nested_attributes_for :user, allow_destroy: false, update_only: true
34
34
 
35
+ has_many :order_items, -> { order(:id) }, inverse_of: :order, dependent: :delete_all
35
36
  accepts_nested_attributes_for :order_items, allow_destroy: false, reject_if: :all_blank
36
- accepts_nested_attributes_for :user, allow_destroy: false, update_only: true
37
37
 
38
38
  # Attributes
39
39
  effective_resource do
@@ -63,18 +63,30 @@ module Effective
63
63
 
64
64
  serialize :payment, Hash
65
65
 
66
- before_validation { assign_order_totals }
67
- before_validation { assign_billing_name }
68
- before_validation { assign_email }
69
- before_validation { assign_user_address }
70
- before_validation { assign_last_address }
66
+ scope :deep, -> { includes(:addresses, :user, order_items: :purchasable) }
67
+ scope :sorted, -> { order(:id) }
68
+
69
+ scope :purchased, -> { where(state: EffectiveOrders::PURCHASED) }
70
+ scope :purchased_by, lambda { |user| purchased.where(user: user) }
71
+ scope :not_purchased, -> { where.not(state: EffectiveOrders::PURCHASED) }
72
+
73
+ scope :pending, -> { where(state: EffectiveOrders::PENDING) }
74
+ scope :confirmed, -> { where(state: EffectiveOrders::CONFIRMED) }
75
+ scope :deferred, -> { where(state: EffectiveOrders::DEFERRED) }
76
+ scope :declined, -> { where(state: EffectiveOrders::DECLINED) }
77
+ scope :abandoned, -> { where(state: EffectiveOrders::ABANDONED) }
78
+ scope :refunds, -> { purchased.where('total < ?', 0) }
71
79
 
72
- before_validation(if: -> { confirmed_checkout }) do
73
- assign_attributes(state: EffectiveOrders::CONFIRMED) if pending?
80
+ before_validation do
81
+ self.state ||= EffectiveOrders::PENDING
82
+ self.state = EffectiveOrders::CONFIRMED if pending? && confirmed_checkout
74
83
  end
75
84
 
76
- before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
77
- raise EffectiveOrders::AlreadyPurchasedException.new('cannot unpurchase an order') unless purchased?
85
+ with_options(unless: -> { done? }) do
86
+ before_validation { assign_email }
87
+ before_validation { assign_user_address }
88
+ before_validation { assign_billing_name }
89
+ before_validation { assign_order_totals }
78
90
  end
79
91
 
80
92
  # Order validations
@@ -84,6 +96,8 @@ module Effective
84
96
 
85
97
  validates :order_items, presence: { message: 'No items are present. Please add additional items.' }
86
98
  validates :state, inclusion: { in: EffectiveOrders::STATES.keys }
99
+
100
+ # Price validations
87
101
  validates :subtotal, presence: true
88
102
 
89
103
  with_options(if: -> { EffectiveOrders.minimum_charge.to_i > 0 }) do
@@ -91,7 +105,7 @@ module Effective
91
105
 
92
106
  validate(unless: -> { (free? && EffectiveOrders.free?) || (refund? && EffectiveOrders.refund?) }) do
93
107
  if total.present? && total < EffectiveOrders.minimum_charge
94
- self.errors.add(:total, "must be $#{'%0.2f' % (EffectiveOrders.minimum_charge.to_i / 100.0)} or more. Please add additional items.")
108
+ errors.add(:total, "must be $#{'%0.2f' % (EffectiveOrders.minimum_charge.to_i / 100.0)} or more. Please add additional items.")
95
109
  end
96
110
  end
97
111
  end
@@ -118,11 +132,6 @@ module Effective
118
132
  validates :payment, presence: true
119
133
 
120
134
  validates :payment_provider, presence: true
121
-
122
- validate do
123
- self.errors.add(:payment_provider, "unknown payment provider") unless (EffectiveOrders.payment_providers + EffectiveOrders.admin_payment_providers).include?(payment_provider)
124
- end
125
-
126
135
  validates :payment_card, presence: true
127
136
  end
128
137
 
@@ -130,23 +139,17 @@ module Effective
130
139
  validates :payment_provider, presence: true
131
140
 
132
141
  validate do
133
- self.errors.add(:payment_provider, "unknown deferred payment provider") unless EffectiveOrders.deferred_providers.include?(payment_provider)
142
+ errors.add(:payment_provider, "unknown deferred payment provider") unless EffectiveOrders.deferred_providers.include?(payment_provider)
134
143
  end
135
144
  end
136
145
 
137
- scope :deep, -> { includes(:addresses, :user, order_items: :purchasable) }
138
- scope :sorted, -> { order(:id) }
139
-
140
- scope :purchased, -> { where(state: EffectiveOrders::PURCHASED) }
141
- scope :purchased_by, lambda { |user| purchased.where(user: user) }
142
- scope :not_purchased, -> { where.not(state: EffectiveOrders::PURCHASED) }
146
+ before_save(if: -> { state_was == EffectiveOrders::PURCHASED }) do
147
+ raise EffectiveOrders::AlreadyPurchasedException.new('cannot unpurchase an order') unless purchased?
148
+ end
143
149
 
144
- scope :pending, -> { where(state: EffectiveOrders::PENDING) }
145
- scope :confirmed, -> { where(state: EffectiveOrders::CONFIRMED) }
146
- scope :deferred, -> { where(state: EffectiveOrders::DEFERRED) }
147
- scope :declined, -> { where(state: EffectiveOrders::DECLINED) }
148
- scope :abandoned, -> { where(state: EffectiveOrders::ABANDONED) }
149
- scope :refunds, -> { purchased.where('total < ?', 0) }
150
+ before_save(if: -> { done? }) do
151
+ raise('cannot change total of a purchased order') if changes[:total].present?
152
+ end
150
153
 
151
154
  # Effective::Order.new()
152
155
  # Effective::Order.new(Product.first)
@@ -165,7 +168,7 @@ module Effective
165
168
  if atts.kind_of?(Hash)
166
169
  items = Array(atts[:item]) + Array(atts[:items])
167
170
 
168
- self.user = atts[:user] || (items.first.user if items.first.respond_to?(:user))
171
+ self.user = atts[:user] || items.first.try(:user)
169
172
 
170
173
  if (address = atts[:billing_address]).present?
171
174
  self.billing_address = address
@@ -280,7 +283,7 @@ module Effective
280
283
  if purchasable.blank? || purchasable.marked_for_destruction?
281
284
  item.mark_for_destruction
282
285
  else
283
- item.price = purchasable.price
286
+ item.assign_purchasable_attributes
284
287
  end
285
288
  end
286
289
 
@@ -386,6 +389,20 @@ module Effective
386
389
  state == EffectiveOrders::DEFERRED
387
390
  end
388
391
 
392
+ def in_progress?
393
+ pending? || confirmed? || deferred?
394
+ end
395
+
396
+ def done?
397
+ persisted? && (purchased? || declined?)
398
+ end
399
+
400
+ # A custom order is one that was created by an admin
401
+ # We allow custom orders to have their order items updated
402
+ def custom_order?
403
+ order_items.all? { |oi| oi.purchasable_type == 'Effective::Product' }
404
+ end
405
+
389
406
  def purchased?(provider = nil)
390
407
  return false if (state != EffectiveOrders::PURCHASED)
391
408
  return true if provider.nil? || payment_provider == provider.to_s
@@ -548,6 +565,10 @@ module Effective
548
565
  true
549
566
  end
550
567
 
568
+ def skip_quickbooks!
569
+ sync_quickbooks!(skip: true)
570
+ end
571
+
551
572
  def defer!(provider: 'none', email: true)
552
573
  return false if purchased?
553
574
 
@@ -624,10 +645,6 @@ module Effective
624
645
  EffectiveOrders.send_email(:refund_notification_to_admin, self) if purchased? && refund?
625
646
  end
626
647
 
627
- def skip_qb_sync!
628
- EffectiveOrders.use_effective_qb_sync ? EffectiveQbSync.skip_order!(self) : true
629
- end
630
-
631
648
  protected
632
649
 
633
650
  def get_tax_rate
@@ -651,56 +668,42 @@ module Effective
651
668
  order_items.reject { |oi| oi.marked_for_destruction? }
652
669
  end
653
670
 
654
- def assign_order_totals
655
- self.subtotal = present_order_items.map { |oi| oi.subtotal }.sum
656
- self.tax_rate = get_tax_rate()
657
- self.tax = get_tax()
658
- self.total = subtotal + (tax || 0)
659
- end
660
-
661
671
  def assign_billing_name
662
- self.billing_name = [(billing_address.full_name.presence if billing_address.present?), (user.to_s.presence)].compact.first
672
+ self.billing_name = billing_address.try(:full_name).presence || user.to_s.presence
663
673
  end
664
674
 
665
675
  def assign_email
666
- self.email = user&.email if user&.email.present?
667
- end
668
-
669
- def assign_last_address
670
- return unless user.present?
671
- return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
672
- return if EffectiveOrders.billing_address && billing_address.present?
673
- return if EffectiveOrders.shipping_address && shipping_address.present?
674
-
675
- last_order = Effective::Order.sorted.where(user: user).last
676
- return unless last_order.present?
677
-
678
- if EffectiveOrders.billing_address && last_order.billing_address.present?
679
- self.billing_address = last_order.billing_address
680
- end
681
-
682
- if EffectiveOrders.shipping_address && last_order.shipping_address.present?
683
- self.shipping_address = last_order.shipping_address
684
- end
676
+ self.email = user.email if user.try(:email).present?
685
677
  end
686
678
 
687
679
  def assign_user_address
688
680
  return unless user.present?
689
- return unless (EffectiveOrders.billing_address || EffectiveOrders.shipping_address)
690
- return if EffectiveOrders.billing_address && billing_address.present?
691
- return if EffectiveOrders.shipping_address && shipping_address.present?
692
681
 
693
- if billing_address.blank? && user.respond_to?(:billing_address) && user.billing_address.present?
682
+ if EffectiveOrders.billing_address && billing_address.blank? && user.try(:billing_address).present?
694
683
  self.billing_address = user.billing_address
695
684
  self.billing_address.full_name ||= user.to_s.presence
696
685
  end
697
686
 
698
- if shipping_address.blank? && user.respond_to?(:shipping_address) && user.shipping_address.present?
687
+ if EffectiveOrders.shipping_address && shipping_address.blank? && user.try(:shipping_address).present?
699
688
  self.shipping_address = user.shipping_address
700
689
  self.shipping_address.full_name ||= user.to_s.presence
701
690
  end
702
691
  end
703
692
 
693
+ # This overwrites the prices, taxes, etc on every save.
694
+ def assign_order_totals
695
+ # Copies prices from purchasable into order items
696
+ present_order_items.each { |oi| oi.assign_purchasable_attributes }
697
+
698
+ # Sum of order item subtotals
699
+ subtotal = present_order_items.map { |oi| oi.subtotal }.sum
700
+
701
+ self.subtotal = subtotal
702
+ self.tax_rate = get_tax_rate()
703
+ self.tax = get_tax()
704
+ self.total = subtotal + (tax || 0)
705
+ end
706
+
704
707
  def update_purchasables_purchased_order!
705
708
  order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
706
709
  end
@@ -3,7 +3,9 @@ module Effective
3
3
  self.table_name = EffectiveOrders.order_items_table_name.to_s
4
4
 
5
5
  belongs_to :order
6
+
6
7
  belongs_to :purchasable, polymorphic: true
8
+ accepts_nested_attributes_for :purchasable, allow_destroy: false
7
9
 
8
10
  if defined?(EffectiveQbSync)
9
11
  has_one :qb_order_item
@@ -18,21 +20,27 @@ module Effective
18
20
  timestamps
19
21
  end
20
22
 
21
- validates :purchasable, associated: true, presence: true
22
- accepts_nested_attributes_for :purchasable
23
+ scope :purchased, -> { where(order_id: Effective::Order.purchased) }
24
+ scope :purchased_by, lambda { |user| where(order_id: Effective::Order.purchased_by(user)) }
23
25
 
24
26
  validates :name, presence: true
25
27
  validates :quantity, presence: true, numericality: { greater_than: 0 }
26
28
  validates :price, presence: true
27
29
  validates :tax_exempt, inclusion: { in: [true, false] }
28
30
 
29
- scope :purchased, -> { where(order_id: Effective::Order.purchased) }
30
- scope :purchased_by, lambda { |user| where(order_id: Effective::Order.purchased_by(user)) }
31
-
32
31
  def to_s
33
32
  ((quantity || 0) > 1 ? "#{quantity}x #{name}" : name) || 'order item'
34
33
  end
35
34
 
35
+ # This method is called in a before_validation in order.assign_order_totals()
36
+ def assign_purchasable_attributes
37
+ assign_attributes(name: purchasable.purchasable_name, price: purchasable.price, tax_exempt: purchasable.tax_exempt) if purchasable
38
+ end
39
+
40
+ def build_purchasable(atts = {})
41
+ (self.purchasable ||= Effective::Product.new).tap { |purchasable| purchasable.assign_attributes(atts) }
42
+ end
43
+
36
44
  def purchased_download_url
37
45
  purchasable&.purchased_download_url
38
46
  end
@@ -58,16 +66,13 @@ module Effective
58
66
  end
59
67
 
60
68
  def price=(value)
61
- if value.kind_of?(Integer)
62
- super
63
- else
64
- raise 'expected price to be an Integer representing the number of cents.'
65
- end
69
+ raise 'expected price to be an Integer representing the number of cents.' unless value.kind_of?(Integer)
70
+ super
66
71
  end
67
72
 
68
73
  # first or build
69
74
  def qb_item_name
70
- raise('expected EffectiveQbSync gem') unless defined?(EffectiveQbSync)
75
+ raise('expected Effective Quickbooks gem') unless defined?(EffectiveQbSync) || defined?(EffectiveQbOnline)
71
76
  (qb_order_item || build_qb_order_item(name: purchasable&.qb_item_name)).name
72
77
  end
73
78
 
@@ -4,7 +4,7 @@ module Effective
4
4
 
5
5
  acts_as_purchasable
6
6
 
7
- # belongs_to :purchased_order_id
7
+ has_many :order_items, as: :purchasable
8
8
 
9
9
  effective_resource do
10
10
  name :string
@@ -1,22 +1,24 @@
1
- = effective_form_with(model: [:admin, order], url: (order.persisted? ? effective_orders.admin_order_path(order) : effective_orders.admin_orders_path)) do |f|
2
- - if f.object.new_record?
3
- - user_collection = current_user.class.respond_to?(:sorted) ? current_user.class.sorted : current_user.class.all
4
-
5
- = f.select :user_id, (@users || user_collection),
6
- label: 'Buyer', required: true, hint: 'The user that should purchase this order.'
1
+ = effective_form_with(model: [:admin, order], engine: true) do |f|
2
+ = f.hidden_field :user_type, value: (f.object.user || current_user).class.name
7
3
 
8
- = f.email_cc_field :cc, hint: "Cc the above on any emailed receipts or payment requests."
4
+ - collection = (@users || current_user.class.try(:sorted) || current_user.class.all)
5
+ = f.select :user_id, collection, label: 'Buyer', required: true, hint: 'The user that should purchase this order.'
9
6
 
10
- %h2 Order Items
11
- = f.has_many :order_items, remove: f.object.new_record? do |fc|
12
- = render 'order_item_fields', f: fc
13
-
14
- %hr
7
+ = f.email_cc_field :cc, hint: "Cc the above on any emailed receipts or payment requests."
15
8
 
9
+ - if f.object.new_record?
16
10
  = f.check_box :send_payment_request_to_buyer,
17
11
  label: 'Yes, send a payment request email to the buyer and any cc.',
18
12
  value: (f.object.send_payment_request_to_buyer.nil? ? EffectiveOrders.send_payment_request_to_buyer : f.object.send_payment_request_to_buyer?)
19
13
 
14
+ %hr
15
+
16
+ %h2 Order Items
17
+ = f.has_many :order_items, remove: true do |fc|
18
+ = render 'order_item_fields', f: fc
19
+
20
+ %hr
21
+
20
22
  .row
21
23
  .col-md-6.effective-order-note-to-buyer
22
24
  %h2 Note to Buyer
@@ -1,10 +1,19 @@
1
1
  .row.align-items-center
2
- = f.fields_for :purchasable, (f.object.purchasable || Effective::Product.new) do |pf|
3
- .col= f.number_field :quantity, input_html: { value: f.object.quantity || 1, min: 1 }
4
- .col= pf.text_field :name
2
+ = f.fields_for :purchasable, (f.object.purchasable || f.object.build_purchasable) do |pf|
3
+ -# Order item fields
4
+ .col
5
+ = f.hidden_field :purchasable_id
6
+ = f.hidden_field :purchasable_type
7
+ = f.number_field :quantity, input_html: { value: f.object.quantity || 1, min: 1 }
8
+
9
+ -# Purchasable fields
10
+ .col
11
+ = pf.hidden_field :id
12
+ = pf.text_field :name
13
+
5
14
  .col= pf.price_field :price
6
15
 
7
- - if EffectiveOrders.use_effective_qb_sync
16
+ - if EffectiveOrders.qb_sync? || EffectiveOrders.qb_online?
8
17
  .col= pf.text_field :qb_item_name, label: 'Quickbooks Item'
9
18
 
10
19
  .col= pf.check_box :tax_exempt, label: "Tax&nbsp;Exempt", title: 'When checked, tax will not be applied to this item'
@@ -1,6 +1,15 @@
1
1
  %h1.effective-admin-heading= @page_title
2
2
 
3
- = render partial: 'effective/orders/order', locals: { order: @order }
3
+ - if @order.custom_order? && @order.in_progress?
4
+ = render 'effective/orders/order_actions', order: @order
4
5
 
5
- .effective-order
6
- = render partial: 'form', locals: { order: @order }
6
+ .mb-4
7
+ = collapse('show order') do
8
+ = render 'effective/orders/order', order: @order, no_order_actions: true
9
+
10
+ = render 'admin/orders/form', order: @order
11
+
12
+ - else
13
+ - # Same as the show action
14
+ = render 'effective/orders/order', order: @order
15
+ = render 'admin/orders/form_note_internal', order: @order
@@ -1,4 +1,3 @@
1
1
  %h1.effective-admin-heading= @page_title
2
2
 
3
- .effective-order
4
- = render partial: 'form', locals: { order: @order }
3
+ = render 'admin/orders/form', order: @order
@@ -1,4 +1,4 @@
1
1
  %h1.effective-admin-heading= @page_title
2
2
 
3
- = render partial: 'effective/orders/order', locals: { order: @order }
4
- = render partial: 'admin/orders/form_note_internal', locals: { order: @order }
3
+ = render 'effective/orders/order', order: @order
4
+ = render 'admin/orders/form_note_internal', order: @order
@@ -7,8 +7,14 @@
7
7
  class: 'btn btn-secondary',
8
8
  data: { method: :post, confirm: "Send receipt to #{order.emails_send_to}?" }
9
9
 
10
- - if order.persisted? && EffectiveResources.authorized?(controller, :admin, :effective_orders)
11
- - if order.pending? || order.confirmed? || order.deferred?
10
+ - if controller_path.include?('admin/') && (EffectiveResources.authorized?(controller, :admin, :effective_orders) rescue false)
11
+ - if order.persisted? && order.in_progress?
12
+ - if params[:action] == 'show'
13
+ = link_to('Edit', effective_orders.edit_admin_order_path(order), class: 'btn btn-primary')
14
+
15
+ - if params[:action] == 'edit'
16
+ = link_to('Show', effective_orders.admin_order_path(order), class: 'btn btn-primary')
17
+
12
18
  = link_to 'Email request for payment to buyer', effective_orders.send_payment_request_admin_order_path(order),
13
19
  class: 'btn btn-secondary',
14
20
  data: { method: :post, confirm: "Send request for payment to #{order.emails_send_to}?" }
@@ -13,15 +13,15 @@
13
13
  label: 'Payment card type, cheque or transaction number',
14
14
  hint: 'Do not enter credit card numbers here, or anywhere.'
15
15
 
16
+ = f.check_box :send_mark_as_paid_email_to_buyer,
17
+ label: 'Yes, send a receipt email to the buyer.',
18
+ input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.send_order_receipts_when_mark_as_paid : f.object.send_mark_as_paid_email_to_buyer?) }
19
+
20
+
16
21
  .row
17
22
  .col
18
23
  = f.text_area :note_to_buyer, hint: 'This message will be displayed to the buyer on the receipt.'
19
24
  .col
20
25
  = f.text_area :note_internal, hint: 'For or internal admin use only. This note will never be displayed to the buyer.'
21
26
 
22
- = f.check_box :send_mark_as_paid_email_to_buyer,
23
- label: 'Yes, send a receipt email to the buyer.',
24
- input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.send_order_receipts_when_mark_as_paid : f.object.send_mark_as_paid_email_to_buyer?) }
25
-
26
-
27
27
  = f.submit order_checkout_label(order.refund? ? :refund : :mark_as_paid)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.5.2'.freeze
2
+ VERSION = '5.6.2'.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: 5.5.2
4
+ version: 5.6.2
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: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails