piggybak 0.4.15 → 0.4.16
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/piggybak/orders_controller.rb +5 -3
- data/app/controllers/piggybak/payments_controller.rb +1 -0
- data/app/models/piggybak/adjustment.rb +29 -0
- data/app/models/piggybak/order.rb +6 -4
- data/app/models/piggybak/order_note.rb +1 -0
- data/app/models/piggybak/payment.rb +1 -1
- data/app/views/rails_admin/main/_order_details.html.erb +4 -0
- data/db/migrate/20120718142841_modify_credits.rb +6 -0
- data/lib/formatted_changes.rb +3 -3
- data/lib/piggybak.rb +37 -1
- data/piggybak.gemspec +3 -2
- metadata +44 -43
- data/app/models/piggybak/credit.rb +0 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.16
|
@@ -89,6 +89,7 @@ module Piggybak
|
|
89
89
|
if can?(:email, order)
|
90
90
|
Piggybak::Notifier.order_notification(order).deliver
|
91
91
|
flash[:notice] = "Email notification sent."
|
92
|
+
OrderNote.create(:order_id => order.id, :note => "Email confirmation manually sent.", :user_id => current_user.id)
|
92
93
|
end
|
93
94
|
|
94
95
|
redirect_to rails_admin.edit_path('Piggybak::Order', order.id)
|
@@ -96,9 +97,11 @@ module Piggybak
|
|
96
97
|
|
97
98
|
def restore
|
98
99
|
order = Order.find(params[:id])
|
100
|
+
order.recorded_changer = current_user.id
|
99
101
|
|
100
102
|
if can?(:restore, order)
|
101
|
-
order.
|
103
|
+
order.status = "new"
|
104
|
+
order.save
|
102
105
|
end
|
103
106
|
|
104
107
|
redirect_to rails_admin.edit_path('Piggybak::Order', order.id)
|
@@ -106,11 +109,10 @@ module Piggybak
|
|
106
109
|
|
107
110
|
def cancel
|
108
111
|
order = Order.find(params[:id])
|
112
|
+
order.recorded_changer = current_user.id
|
109
113
|
|
110
114
|
if can?(:cancel, order)
|
111
|
-
cancelled_items = []
|
112
115
|
order.line_items.each do |line_item|
|
113
|
-
cancelled_items << "#{line_item.quantity}:#{line_item.variant.sku}"
|
114
116
|
line_item.destroy
|
115
117
|
end
|
116
118
|
order.payments.each do |payment|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Piggybak
|
2
|
+
class Adjustment < ActiveRecord::Base
|
3
|
+
belongs_to :order
|
4
|
+
belongs_to :source, :polymorphic => true
|
5
|
+
attr_accessor :user_id
|
6
|
+
acts_as_changer
|
7
|
+
|
8
|
+
validates_presence_of :order_id, :total
|
9
|
+
validates_numericality_of :total
|
10
|
+
validates_presence_of :source
|
11
|
+
|
12
|
+
before_validation :set_source
|
13
|
+
|
14
|
+
def set_source
|
15
|
+
if self.source.nil? && self.user_id.present?
|
16
|
+
self.source = User.find(self.user_id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def admin_label
|
21
|
+
if !self.new_record?
|
22
|
+
return "Adjustment ##{self.id} (#{self.created_at.strftime("%m-%d-%Y")}): " +
|
23
|
+
"$#{"%.2f" % self.total}"
|
24
|
+
else
|
25
|
+
return ""
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,7 +3,7 @@ module Piggybak
|
|
3
3
|
has_many :line_items, :inverse_of => :order
|
4
4
|
has_many :payments, :inverse_of => :order
|
5
5
|
has_many :shipments, :inverse_of => :order
|
6
|
-
has_many :
|
6
|
+
has_many :adjustments, :inverse_of => :order
|
7
7
|
has_many :order_notes, :inverse_of => :order
|
8
8
|
|
9
9
|
belongs_to :billing_address, :class_name => "Piggybak::Address"
|
@@ -15,6 +15,7 @@ module Piggybak
|
|
15
15
|
accepts_nested_attributes_for :shipments, :allow_destroy => true
|
16
16
|
accepts_nested_attributes_for :line_items, :allow_destroy => true
|
17
17
|
accepts_nested_attributes_for :payments
|
18
|
+
accepts_nested_attributes_for :adjustments, :allow_destroy => true
|
18
19
|
accepts_nested_attributes_for :order_notes
|
19
20
|
|
20
21
|
attr_accessor :recorded_changes
|
@@ -132,9 +133,10 @@ module Piggybak
|
|
132
133
|
self.total += shipment.total
|
133
134
|
end
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
adjustments.each do |adjustment|
|
137
|
+
if !adjustment._destroy
|
138
|
+
self.total += adjustment.total
|
139
|
+
end
|
138
140
|
end
|
139
141
|
|
140
142
|
self.total_due = self.total
|
@@ -84,7 +84,7 @@ module Piggybak
|
|
84
84
|
|
85
85
|
def admin_label
|
86
86
|
if !self.new_record?
|
87
|
-
return "Payment ##{self.id} (#{self.created_at.strftime("%m-%d-%Y")})
|
87
|
+
return "Payment ##{self.id} (#{self.created_at.strftime("%m-%d-%Y")}): " +
|
88
88
|
"$#{"%.2f" % self.total}"
|
89
89
|
else
|
90
90
|
return ""
|
@@ -14,6 +14,10 @@ N/A
|
|
14
14
|
<td>Tax</td>
|
15
15
|
<td>$<%= "%.2f" % form.object.tax_charge %></td>
|
16
16
|
</tr>
|
17
|
+
<tr>
|
18
|
+
<td>Adjustments</td>
|
19
|
+
<td>$<%= "%.2f" % form.object.adjustments.inject(0) { |total, adj| total + adj.total } %></td>
|
20
|
+
</tr>
|
17
21
|
<tr>
|
18
22
|
<td>Order Total</td>
|
19
23
|
<td>$<%= "%.2f" % form.object.total %></td>
|
data/lib/formatted_changes.rb
CHANGED
@@ -21,11 +21,11 @@ module Piggybak
|
|
21
21
|
def formatted_changes
|
22
22
|
text = "#{self.class.to_s.gsub(/Piggybak::/, '')} ##{self.id} changes:<br />"
|
23
23
|
self.changes.each do |k, v|
|
24
|
-
if
|
24
|
+
if !["updated_at", "id", "billing_address_id", "shipping_address_id", "created_at"].include?(k)
|
25
25
|
if v[0].is_a?(BigDecimal)
|
26
|
-
text += "#{k}
|
26
|
+
text += "#{k}: $#{format("%.2f", v[0])} to $#{format("%.2f", v[1])}<br />"
|
27
27
|
else
|
28
|
-
text += "#{k}
|
28
|
+
text += "#{k}: #{v[0]} to #{v[1]}<br />"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/piggybak.rb
CHANGED
@@ -143,6 +143,7 @@ module Piggybak
|
|
143
143
|
field :payments do
|
144
144
|
active true
|
145
145
|
end
|
146
|
+
field :adjustments
|
146
147
|
field :order_notes do
|
147
148
|
active true
|
148
149
|
end
|
@@ -237,7 +238,42 @@ module Piggybak
|
|
237
238
|
end
|
238
239
|
end
|
239
240
|
end
|
240
|
-
|
241
|
+
|
242
|
+
config.model Piggybak::Adjustment do
|
243
|
+
object_label_method :admin_label
|
244
|
+
visible false
|
245
|
+
edit do
|
246
|
+
field :user_id, :hidden do
|
247
|
+
default_value do
|
248
|
+
bindings[:view]._current_user.id
|
249
|
+
end
|
250
|
+
end
|
251
|
+
field :source do
|
252
|
+
help "Source of adjustment."
|
253
|
+
visible do
|
254
|
+
!bindings[:object].new_record?
|
255
|
+
end
|
256
|
+
read_only do
|
257
|
+
!bindings[:object].new_record?
|
258
|
+
end
|
259
|
+
end
|
260
|
+
field :total do
|
261
|
+
help "A negative value will add credit to an order. A positive value will add charges to the order."
|
262
|
+
read_only do
|
263
|
+
!bindings[:object].new_record?
|
264
|
+
end
|
265
|
+
formatted_value do
|
266
|
+
"$%.2f" % value
|
267
|
+
end
|
268
|
+
end
|
269
|
+
field :note do
|
270
|
+
read_only do
|
271
|
+
!bindings[:object].new_record?
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
241
277
|
config.model Piggybak::Payment do
|
242
278
|
object_label_method :admin_label
|
243
279
|
visible false
|
data/piggybak.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "piggybak"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.16"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steph Skardal", "Brian Buchalter"]
|
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"app/helpers/piggybak_helper.rb",
|
33
33
|
"app/mailers/piggybak/notifier.rb",
|
34
34
|
"app/models/piggybak/address.rb",
|
35
|
+
"app/models/piggybak/adjustment.rb",
|
35
36
|
"app/models/piggybak/cart.rb",
|
36
37
|
"app/models/piggybak/country.rb",
|
37
|
-
"app/models/piggybak/credit.rb",
|
38
38
|
"app/models/piggybak/line_item.rb",
|
39
39
|
"app/models/piggybak/order.rb",
|
40
40
|
"app/models/piggybak/order_note.rb",
|
@@ -95,6 +95,7 @@ Gem::Specification.new do |s|
|
|
95
95
|
"db/migrate/20120716191225_add_masked_credit_card_numbers.rb",
|
96
96
|
"db/migrate/20120716195806_order_debugging.rb",
|
97
97
|
"db/migrate/20120717022155_create_order_notes.rb",
|
98
|
+
"db/migrate/20120718142841_modify_credits.rb",
|
98
99
|
"lib/acts_as_changer.rb",
|
99
100
|
"lib/acts_as_orderer.rb",
|
100
101
|
"lib/acts_as_variant.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piggybak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-07-18 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: countries
|
17
|
-
requirement: &
|
17
|
+
requirement: &16546740 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *16546740
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &16545900 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *16545900
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &16544940 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.4
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *16544940
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &16560360 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *16560360
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rspec-rails
|
61
|
-
requirement: &
|
61
|
+
requirement: &16559280 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 2.7.0
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *16559280
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: factory_girl
|
72
|
-
requirement: &
|
72
|
+
requirement: &16557500 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *16557500
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: diff-lcs
|
83
|
-
requirement: &
|
83
|
+
requirement: &16555960 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *16555960
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: shoulda
|
94
|
-
requirement: &
|
94
|
+
requirement: &16554200 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,10 +99,10 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *16554200
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: simplecov
|
105
|
-
requirement: &
|
105
|
+
requirement: &16568640 !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
108
108
|
- - ! '>='
|
@@ -110,10 +110,10 @@ dependencies:
|
|
110
110
|
version: '0'
|
111
111
|
type: :development
|
112
112
|
prerelease: false
|
113
|
-
version_requirements: *
|
113
|
+
version_requirements: *16568640
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: tzinfo
|
116
|
-
requirement: &
|
116
|
+
requirement: &16567680 !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
119
|
- - ! '>='
|
@@ -121,10 +121,10 @@ dependencies:
|
|
121
121
|
version: '0'
|
122
122
|
type: :development
|
123
123
|
prerelease: false
|
124
|
-
version_requirements: *
|
124
|
+
version_requirements: *16567680
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: devise
|
127
|
-
requirement: &
|
127
|
+
requirement: &16566440 !ruby/object:Gem::Requirement
|
128
128
|
none: false
|
129
129
|
requirements:
|
130
130
|
- - ! '>='
|
@@ -132,10 +132,10 @@ dependencies:
|
|
132
132
|
version: '0'
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
|
-
version_requirements: *
|
135
|
+
version_requirements: *16566440
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
137
|
name: rails_admin
|
138
|
-
requirement: &
|
138
|
+
requirement: &16565060 !ruby/object:Gem::Requirement
|
139
139
|
none: false
|
140
140
|
requirements:
|
141
141
|
- - ! '>='
|
@@ -143,10 +143,10 @@ dependencies:
|
|
143
143
|
version: '0'
|
144
144
|
type: :runtime
|
145
145
|
prerelease: false
|
146
|
-
version_requirements: *
|
146
|
+
version_requirements: *16565060
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: devise
|
149
|
-
requirement: &
|
149
|
+
requirement: &16563860 !ruby/object:Gem::Requirement
|
150
150
|
none: false
|
151
151
|
requirements:
|
152
152
|
- - ! '>='
|
@@ -154,10 +154,10 @@ dependencies:
|
|
154
154
|
version: '0'
|
155
155
|
type: :runtime
|
156
156
|
prerelease: false
|
157
|
-
version_requirements: *
|
157
|
+
version_requirements: *16563860
|
158
158
|
- !ruby/object:Gem::Dependency
|
159
159
|
name: activemerchant
|
160
|
-
requirement: &
|
160
|
+
requirement: &16562720 !ruby/object:Gem::Requirement
|
161
161
|
none: false
|
162
162
|
requirements:
|
163
163
|
- - ! '>='
|
@@ -165,10 +165,10 @@ dependencies:
|
|
165
165
|
version: '0'
|
166
166
|
type: :runtime
|
167
167
|
prerelease: false
|
168
|
-
version_requirements: *
|
168
|
+
version_requirements: *16562720
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
name: countries
|
171
|
-
requirement: &
|
171
|
+
requirement: &16561060 !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|
174
174
|
- - ! '>='
|
@@ -176,10 +176,10 @@ dependencies:
|
|
176
176
|
version: '0'
|
177
177
|
type: :runtime
|
178
178
|
prerelease: false
|
179
|
-
version_requirements: *
|
179
|
+
version_requirements: *16561060
|
180
180
|
- !ruby/object:Gem::Dependency
|
181
181
|
name: rspec
|
182
|
-
requirement: &
|
182
|
+
requirement: &16576040 !ruby/object:Gem::Requirement
|
183
183
|
none: false
|
184
184
|
requirements:
|
185
185
|
- - ! '>='
|
@@ -187,10 +187,10 @@ dependencies:
|
|
187
187
|
version: '0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
|
-
version_requirements: *
|
190
|
+
version_requirements: *16576040
|
191
191
|
- !ruby/object:Gem::Dependency
|
192
192
|
name: rspec-rails
|
193
|
-
requirement: &
|
193
|
+
requirement: &16574740 !ruby/object:Gem::Requirement
|
194
194
|
none: false
|
195
195
|
requirements:
|
196
196
|
- - ! '>='
|
@@ -198,10 +198,10 @@ dependencies:
|
|
198
198
|
version: '0'
|
199
199
|
type: :development
|
200
200
|
prerelease: false
|
201
|
-
version_requirements: *
|
201
|
+
version_requirements: *16574740
|
202
202
|
- !ruby/object:Gem::Dependency
|
203
203
|
name: diff-lcs
|
204
|
-
requirement: &
|
204
|
+
requirement: &16572740 !ruby/object:Gem::Requirement
|
205
205
|
none: false
|
206
206
|
requirements:
|
207
207
|
- - ! '>='
|
@@ -209,10 +209,10 @@ dependencies:
|
|
209
209
|
version: '0'
|
210
210
|
type: :development
|
211
211
|
prerelease: false
|
212
|
-
version_requirements: *
|
212
|
+
version_requirements: *16572740
|
213
213
|
- !ruby/object:Gem::Dependency
|
214
214
|
name: factory_girl
|
215
|
-
requirement: &
|
215
|
+
requirement: &16570240 !ruby/object:Gem::Requirement
|
216
216
|
none: false
|
217
217
|
requirements:
|
218
218
|
- - ! '>='
|
@@ -220,10 +220,10 @@ dependencies:
|
|
220
220
|
version: '0'
|
221
221
|
type: :development
|
222
222
|
prerelease: false
|
223
|
-
version_requirements: *
|
223
|
+
version_requirements: *16570240
|
224
224
|
- !ruby/object:Gem::Dependency
|
225
225
|
name: shoulda
|
226
|
-
requirement: &
|
226
|
+
requirement: &16583140 !ruby/object:Gem::Requirement
|
227
227
|
none: false
|
228
228
|
requirements:
|
229
229
|
- - ! '>='
|
@@ -231,7 +231,7 @@ dependencies:
|
|
231
231
|
version: '0'
|
232
232
|
type: :development
|
233
233
|
prerelease: false
|
234
|
-
version_requirements: *
|
234
|
+
version_requirements: *16583140
|
235
235
|
description: Mountable ecommerce
|
236
236
|
email: steph@endpoint.com
|
237
237
|
executables: []
|
@@ -255,9 +255,9 @@ files:
|
|
255
255
|
- app/helpers/piggybak_helper.rb
|
256
256
|
- app/mailers/piggybak/notifier.rb
|
257
257
|
- app/models/piggybak/address.rb
|
258
|
+
- app/models/piggybak/adjustment.rb
|
258
259
|
- app/models/piggybak/cart.rb
|
259
260
|
- app/models/piggybak/country.rb
|
260
|
-
- app/models/piggybak/credit.rb
|
261
261
|
- app/models/piggybak/line_item.rb
|
262
262
|
- app/models/piggybak/order.rb
|
263
263
|
- app/models/piggybak/order_note.rb
|
@@ -318,6 +318,7 @@ files:
|
|
318
318
|
- db/migrate/20120716191225_add_masked_credit_card_numbers.rb
|
319
319
|
- db/migrate/20120716195806_order_debugging.rb
|
320
320
|
- db/migrate/20120717022155_create_order_notes.rb
|
321
|
+
- db/migrate/20120718142841_modify_credits.rb
|
321
322
|
- lib/acts_as_changer.rb
|
322
323
|
- lib/acts_as_orderer.rb
|
323
324
|
- lib/acts_as_variant.rb
|
@@ -398,7 +399,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
398
399
|
version: '0'
|
399
400
|
segments:
|
400
401
|
- 0
|
401
|
-
hash: -
|
402
|
+
hash: -1651129113805460590
|
402
403
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
403
404
|
none: false
|
404
405
|
requirements:
|