accountability 0.2.2 → 0.2.3

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: 25f8546f25aae663976cd6cd712b38b444a385a9b5b609bf9f0fa0f1f62e0bb0
4
- data.tar.gz: 278fb73d9c9d2f9d3a5c7ed609514b82cceb9db892508cb5bda6464b8e959607
3
+ metadata.gz: ea198d3d5114628829df3f4b29e3d33ee1dff1899113b42846704842bd7bfdd8
4
+ data.tar.gz: 9f9496c534dd51ec485b94f4e6557d3be874e96168f3e7d5b00283ed1397cec6
5
5
  SHA512:
6
- metadata.gz: 4bfd0bf5a59e3a8804a96739d416f9dbbb6ade1a56d6bdc821a207eafc58fe783086511001f40262b9c7175e30f8a17078a23af4e1ea1f79d18a1558650b1ab3
7
- data.tar.gz: 869170f02d04650f64beefa7cc616189420575ceb497ba7ae97b3970f635ce29c1c555bc66bc1157831cfc02f9dc6c4bf97c99b3097c8a1ae2da5b883f2363e6
6
+ metadata.gz: 3daace9c9b8bced32115713766b9d5d171210b32ba5ad0969a73c3e3ee77d18be31b3a0d15daa3061870b1954a751462f7d9bf1f048de427e86fad9c13c9dc21
7
+ data.tar.gz: 595718d2f8de2b35468b016742c96d32cb037aa0498bba29b45d8994cb09c22aad9686255728bd7a4745363f60e911b5c71d59265d48484407bd177510a0c3c1
@@ -55,6 +55,16 @@ module Accountability
55
55
  end
56
56
  end
57
57
 
58
+ def checkout
59
+ @order_group.assign_account!(helpers.current_account) if @order_group.unassigned?
60
+
61
+ if @order_group.checkout!
62
+ redirect_to after_checkout_path(@order_group), notice: 'Checkout complete'
63
+ else
64
+ redirect_back fallback_location: accountability_order_group_path(@order_group), alert: 'Failed to check out'
65
+ end
66
+ end
67
+
58
68
  private
59
69
 
60
70
  def set_order_group
@@ -64,5 +74,9 @@ module Accountability
64
74
  def order_group_params
65
75
  params.require(:order_group).permit
66
76
  end
77
+
78
+ def after_checkout_path(_order_group)
79
+ accountability_order_groups_path
80
+ end
67
81
  end
68
82
  end
@@ -13,6 +13,7 @@ module Accountability
13
13
  has_many :credits, dependent: :destroy
14
14
  has_many :debits, dependent: :destroy
15
15
  has_many :billing_configurations, dependent: :destroy
16
+ has_one :primary_billing_configuration, -> { order(primary: :desc) }, class_name: 'BillingConfiguration', inverse_of: :account
16
17
 
17
18
  enum statement_schedule: %i[end_of_month bi_weekly]
18
19
 
@@ -12,6 +12,10 @@ class Accountability::ApplicationRecord < ActiveRecord::Base
12
12
 
13
13
  def validate_validatable_attributes
14
14
  validatable_attribute_names.each do |attribute_name|
15
+ # This is a fragile, temporary patch for an issue caused by the misuse of class attributes.
16
+ # TODO: Rework validatable_attributes with isolated variable scope
17
+ next unless self.respond_to? attribute_name
18
+
15
19
  attribute = public_send attribute_name
16
20
 
17
21
  next if attribute.blank?
@@ -29,6 +29,10 @@ module Accountability
29
29
  order_items.each(&:accrue_credit!)
30
30
  end
31
31
 
32
+ def raw_total
33
+ order_items.sum(&:default_price)
34
+ end
35
+
32
36
  # The `product` parameter accepts Product, String, and Integer objects
33
37
  def add_item!(product, source_scope: nil)
34
38
  product = Product.find(product) unless product.is_a? Product
@@ -51,7 +51,9 @@ class Accountability::OrderItem < ApplicationRecord
51
51
  end
52
52
 
53
53
  def default_price
54
- price_override&.price || product.price
54
+ return price_override.price if price_override.present?
55
+
56
+ product.price
55
57
  end
56
58
 
57
59
  def price_override
@@ -37,7 +37,10 @@ module ActionDispatch::Routing
37
37
  resources :products, controller: options.dig(:controllers, :products), path: options.dig(:routes, :products)
38
38
 
39
39
  resources :order_groups, controller: options.dig(:controllers, :order_groups), path: options.dig(:routes, :order_groups) do
40
- member { post :add_item }
40
+ member do
41
+ post :add_item
42
+ put :checkout
43
+ end
41
44
  end
42
45
  end
43
46
 
@@ -1,3 +1,3 @@
1
1
  module Accountability
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accountability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Stowers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-31 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_accountability_merchant