effective_products 0.0.6 → 0.0.9

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: fe191a8c318148da7f4d5c91a4e8248ad1e46ed79a226fd8549873fbeeac7e58
4
- data.tar.gz: e0481a234925beb15a4bde2656f931cfc98466224d4fdaa7cdf0be3e4a85879e
3
+ metadata.gz: 33912b031a749bc69286e6d5d04a85a67c930237b426389f0fbe890a05707e18
4
+ data.tar.gz: f2ab6eaf54d5c407ab891370ceaec1d1d25d659730e12c5dd2ad9b5fb3ac7ae8
5
5
  SHA512:
6
- metadata.gz: 39a16cb225c1dd2f0c575af9eec56d5b8865f928d2acc2cb0990aec35dfd36b1d9af8acb474a3ac53dee78772224520fd3e35949447bbf1d5079c38a904511bb
7
- data.tar.gz: a9f3006715674b41ce72da94d2936a87d456a45f08920cc4765ecc5596d69ffa6502a42aeed557c3ca1dd2061e76214d897bb3e91308e8bb5e2ede6790ec5781
6
+ metadata.gz: 8a258133393608311a4044c421905b90e511af529ba465ba59173482722e01c63d06958434b7ee2d038a955c26205825fbb2b994e23460503ac61545a2e330c2
7
+ data.tar.gz: 1a6ba5a8f9de60dab801d4c5eb7ad871d3a00e0fe9cc58b25fa751d25c6b2a154ca2eb2880c8dc566556aabe183a15737fccd64905e34a1087bb0b066414d9d2
@@ -5,5 +5,7 @@ module Admin
5
5
 
6
6
  include Effective::CrudController
7
7
 
8
+ submit :mark_paid, 'Save and Mark Paid'
9
+
8
10
  end
9
11
  end
@@ -16,8 +16,9 @@ module Admin
16
16
  col :created_at, as: :date
17
17
  col :owner, search: :string
18
18
 
19
- col(:first_name) { |stamp| stamp.owner.first_name }
20
- col(:last_name) { |stamp| stamp.owner.last_name }
19
+ col :applicant, visible: false
20
+ col :stamp_wizard, visible: false
21
+
21
22
  col(:email) { |stamp| stamp.owner.email }
22
23
  col(:phone) { |stamp| stamp.owner.phone }
23
24
 
@@ -25,12 +26,20 @@ module Admin
25
26
  stamp.owner.try(:membership).try(:number)
26
27
  end
27
28
 
28
- col :category
29
29
  col :name
30
- col :name_confirmation
30
+ col :name_confirmation, visible: false
31
+
32
+ col :category, visible: false
31
33
 
32
34
  col :shipping_address, label: 'Address'
33
35
 
36
+ col :purchased_order, visible: false
37
+ col :price, visible: false
38
+ col :tax_exempt, visible: false
39
+ col :qb_item_name, visible: false
40
+
41
+ col :status, visible: false
42
+
34
43
  col :issued_at
35
44
 
36
45
  actions_col
@@ -110,9 +110,8 @@ module EffectiveProductsRingWizard
110
110
 
111
111
  def build_ring
112
112
  ring = rings.build(owner: owner)
113
- address = owner.try(:shipping_address) || owner.try(:billing_address)
114
113
 
115
- if address.present?
114
+ if (address = owner.try(:shipping_address) || owner.try(:billing_address)).present?
116
115
  ring.shipping_address = address
117
116
  end
118
117
 
@@ -86,7 +86,7 @@ module EffectiveProductsStampWizard
86
86
  end
87
87
 
88
88
  def after_submit_purchased!
89
- # Nothing to do yet
89
+ stamps.each { |stamp| stamp.submit! }
90
90
  end
91
91
 
92
92
  end
@@ -109,8 +109,13 @@ module EffectiveProductsStampWizard
109
109
  end
110
110
 
111
111
  def build_stamp
112
- address = owner.try(:shipping_address) || owner.try(:billing_address)
113
- stamps.build(owner: owner, shipping_address: address)
112
+ stamp = stamps.build(owner: owner)
113
+
114
+ if (address = owner.try(:shipping_address) || owner.try(:billing_address)).present?
115
+ stamp.shipping_address = address
116
+ end
117
+
118
+ stamp
114
119
  end
115
120
 
116
121
  def assign_pricing
@@ -5,15 +5,24 @@ module Effective
5
5
  acts_as_purchasable
6
6
  acts_as_addressable :shipping
7
7
 
8
+ acts_as_statused(
9
+ :draft, # Built in an application
10
+ :submitted, # Submitted by an applicant or stamp wizard
11
+ :issued # Issued by an admin
12
+ )
13
+
8
14
  #CATEGORIES = ['Physical', 'Digital-only']
9
15
  CATEGORIES = ['Physical']
10
16
 
11
17
  log_changes if respond_to?(:log_changes)
12
18
 
13
- # This ring is charged to an owner
19
+ # This stamp is charged to an owner
14
20
  belongs_to :owner, polymorphic: true
15
21
 
16
- # Through the stamp_wizard
22
+ # Sometimes a stamp is built through an applicant
23
+ belongs_to :applicant, polymorphic: true, optional: true
24
+
25
+ # Other times through the stamp_wizard
17
26
  belongs_to :stamp_wizard, polymorphic: true, optional: true
18
27
 
19
28
  effective_resource do
@@ -25,6 +34,10 @@ module Effective
25
34
  # Admin issues stamps
26
35
  issued_at :datetime # Present when issued by an admin
27
36
 
37
+ # Acts as Statused
38
+ status :string
39
+ status_steps :text
40
+
28
41
  # Acts as Purchasable
29
42
  price :integer
30
43
  qb_item_name :string
@@ -34,8 +47,13 @@ module Effective
34
47
  end
35
48
 
36
49
  scope :deep, -> { includes(:owner) }
37
- scope :ready_to_issue, -> { purchased.where(issued_at: nil) }
38
- scope :issued, -> { where.not(issued_at: nil) }
50
+
51
+ scope :with_approved_applicants, -> { where(applicant_id: EffectiveMemberships.Applicant.approved) }
52
+ scope :with_stamp_wizards, -> { where(applicant_id: nil).where.not(stamp_wizard_id: nil) }
53
+
54
+ scope :ready_to_issue, -> {
55
+ with_approved_applicants.or(with_stamp_wizards).purchased.where.not(status: :issued)
56
+ }
39
57
 
40
58
  validates :category, presence: true, inclusion: { in: CATEGORIES }
41
59
  validates :name, presence: true
@@ -54,16 +72,39 @@ module Effective
54
72
  end
55
73
 
56
74
  def mark_as_issued!
57
- update!(issued_at: Time.zone.now)
58
- end
59
-
60
- def issued?
61
- issued_at.present?
75
+ issued!
62
76
  end
63
77
 
64
78
  def physical?
65
79
  category == 'Physical'
66
80
  end
67
81
 
82
+ def created_by_admin?
83
+ stamp_wizard_id.blank? && applicant_id.blank?
84
+ end
85
+
86
+ # Called by an application when submitted
87
+ # Called by a stamp wizard when submitted
88
+ def submit!
89
+ raise('expected a purchased order') unless purchased?
90
+ submitted!
91
+ end
92
+
93
+ # This is the Admin Save and Mark Paid action
94
+ def mark_paid!
95
+ raise('expected an user with a membership category') unless owner && owner.try(:membership).present?
96
+
97
+ category = owner.membership.categories.first
98
+
99
+ assign_attributes(
100
+ price: category.stamp_fee,
101
+ tax_exempt: category.stamp_fee_tax_exempt,
102
+ qb_item_name: category.stamp_fee_qb_item_name
103
+ )
104
+
105
+ save!
106
+ Effective::Order.new(items: self, user: owner).mark_as_purchased!
107
+ end
108
+
68
109
  end
69
110
  end
@@ -0,0 +1,12 @@
1
+ = effective_form_with(model: [:admin, stamp], engine: true) do |f|
2
+ - if f.object.new_record?
3
+ = f.select :owner, { 'Users' => current_user.class.members.sorted }, polymorphic: true
4
+ - else
5
+ = f.static_field :owner
6
+
7
+ = render 'effective/stamps/fields', f: f, stamp: f.object
8
+
9
+ - if f.object.new_record?
10
+ = f.submit 'Save and Mark Paid'
11
+ - else
12
+ = f.submit 'Save'
@@ -0,0 +1,11 @@
1
+ = f.text_field :name
2
+ = f.text_field :name_confirmation, hint: 'must match name'
3
+
4
+ %h2 Stamp Information
5
+
6
+ %p Please select a stamp and enter a shipping address.
7
+
8
+ = f.select :category, Effective::Stamp::CATEGORIES
9
+
10
+ = f.show_if :category, 'Physical' do
11
+ = effective_address_fields(f, :shipping)
data/config/routes.rb CHANGED
@@ -23,7 +23,7 @@ EffectiveProducts::Engine.routes.draw do
23
23
  post :mark_as_issued, on: :member
24
24
  end
25
25
 
26
- resources :stamps, only: [:index, :show] do
26
+ resources :stamps do
27
27
  post :mark_as_issued, on: :member
28
28
  end
29
29
  end
@@ -55,6 +55,12 @@ class CreateEffectiveProducts < ActiveRecord::Migration[6.1]
55
55
  t.integer :stamp_wizard_id
56
56
  t.string :stamp_wizard_type
57
57
 
58
+ t.integer :applicant_id
59
+ t.string :applicant_type
60
+
61
+ t.string :status
62
+ t.text :status_steps
63
+
58
64
  t.string :category
59
65
  t.string :name
60
66
  t.string :name_confirmation
@@ -1,3 +1,3 @@
1
1
  module EffectiveProducts
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_products
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.9
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-01-31 00:00:00.000000000 Z
11
+ date: 2022-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -237,6 +237,7 @@ files:
237
237
  - app/models/effective/stamp.rb
238
238
  - app/models/effective/stamp_wizard.rb
239
239
  - app/views/admin/rings/_ring.html.haml
240
+ - app/views/admin/stamps/_form.html.haml
240
241
  - app/views/admin/stamps/_stamp.html.haml
241
242
  - app/views/effective/ring_wizards/_content.html.haml
242
243
  - app/views/effective/ring_wizards/_dashboard.html.haml
@@ -266,6 +267,7 @@ files:
266
267
  - app/views/effective/stamp_wizards/start.html.haml
267
268
  - app/views/effective/stamp_wizards/submitted.html.haml
268
269
  - app/views/effective/stamp_wizards/summary.html.haml
270
+ - app/views/effective/stamps/_fields.html.haml
269
271
  - config/effective_products.rb
270
272
  - config/routes.rb
271
273
  - db/migrate/01_create_effective_products.rb.erb