effective_products 0.0.6 → 0.0.7

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: 36f1b24a9da60c9e39f6d27fd085283bd0f5b061f80c14a53f7a4a59edb1d31a
4
+ data.tar.gz: 713caaaaa536356ede62d6d207166a8861190bb3d8ea41c16296637f49033c84
5
5
  SHA512:
6
- metadata.gz: 39a16cb225c1dd2f0c575af9eec56d5b8865f928d2acc2cb0990aec35dfd36b1d9af8acb474a3ac53dee78772224520fd3e35949447bbf1d5079c38a904511bb
7
- data.tar.gz: a9f3006715674b41ce72da94d2936a87d456a45f08920cc4765ecc5596d69ffa6502a42aeed557c3ca1dd2061e76214d897bb3e91308e8bb5e2ede6790ec5781
6
+ metadata.gz: 8bc5e5606f1fe01fde2bc06429ba9f4813a0f6115cfafaa7fa657aaee71c4440f61a00bf523446a4b82af4e2513bf5593c19801030f50e1d7f82aafd87bddead
7
+ data.tar.gz: aa6f08d926456c04c97f34b7ad4d53b26e021339a98c3e54781ce3475056771b22ec46063d6daf0a47af990362c7e1d84213bc5392c07725673e71f3cf44db7c
@@ -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
@@ -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
@@ -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(issued_at: nil)
56
+ }
39
57
 
40
58
  validates :category, presence: true, inclusion: { in: CATEGORIES }
41
59
  validates :name, presence: true
@@ -53,17 +71,44 @@ module Effective
53
71
  ['Professional Stamp', *name.presence].join(' ')
54
72
  end
55
73
 
56
- def mark_as_issued!
57
- update!(issued_at: Time.zone.now)
58
- end
59
-
60
74
  def issued?
61
75
  issued_at.present?
62
76
  end
63
77
 
78
+ def mark_as_issued!
79
+ issued!
80
+ end
81
+
64
82
  def physical?
65
83
  category == 'Physical'
66
84
  end
67
85
 
86
+ def created_by_admin?
87
+ stamp_wizard_id.blank? && applicant_id.blank?
88
+ end
89
+
90
+ # Called by an application when submitted
91
+ # Called by a stamp wizard when submitted
92
+ def submit!
93
+ raise('expected a purchased order') unless purchased?
94
+ submitted!
95
+ end
96
+
97
+ # This is the Admin Save and Mark Paid action
98
+ def mark_paid!
99
+ raise('expected an user with a membership category') unless owner && owner.try(:membership).present?
100
+
101
+ category = owner.membership.categories.first
102
+
103
+ assign_attributes(
104
+ price: category.stamp_fee,
105
+ tax_exempt: category.stamp_fee_tax_exempt,
106
+ qb_item_name: category.stamp_fee_qb_item_name
107
+ )
108
+
109
+ save!
110
+ Effective::Order.new(items: self, user: owner).mark_as_purchased!
111
+ end
112
+
68
113
  end
69
114
  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.7'.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.7
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-02-04 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