piggybak 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- piggybak (0.6.3)
4
+ piggybak (0.6.4)
5
5
  activemerchant
6
6
  countries
7
7
  devise
data/README.md CHANGED
@@ -69,7 +69,7 @@ TODO
69
69
 
70
70
  * Add/check validation to ensure sufficient inventory
71
71
 
72
- * Add copy from billing above shipping address section button
72
+ * Add copy from billing above shipping address section button in admin
73
73
 
74
74
  Copyright
75
75
  ========
@@ -7,6 +7,8 @@ module Piggybak
7
7
  validates_presence_of :price, :description, :quantity
8
8
  validates_numericality_of :quantity, :only_integer => true, :greater_than_or_equal_to => 0
9
9
 
10
+ default_scope :order => 'created_at ASC'
11
+
10
12
  after_create :decrease_inventory, :if => Proc.new { |line_item| line_item.line_item_type == 'sellable' && !line_item.sellable.unlimited_inventory }
11
13
  after_destroy :increase_inventory, :if => Proc.new { |line_item| line_item.line_item_type == 'sellable' && !line_item.sellable.unlimited_inventory }
12
14
  after_update :update_inventory, :if => Proc.new { |line_item| line_item.line_item_type == 'sellable' && !line_item.sellable.unlimited_inventory }
@@ -17,9 +19,13 @@ module Piggybak
17
19
  before_validation :preprocess
18
20
  before_destroy :destroy_associated_item
19
21
 
22
+ # TODO: Possibly replace all initializers below with database defaults
20
23
  def initialize_line_item
21
24
  self.quantity ||= 1
22
25
  self.price ||= 0
26
+
27
+ # TODO: Fix this, should default in database
28
+ self.created_at ||= Time.now
23
29
  end
24
30
 
25
31
  def preprocess
@@ -129,5 +135,9 @@ module Piggybak
129
135
  self.sellable.update_inventory(quantity_diff)
130
136
  end
131
137
  end
138
+
139
+ def self.sorted_line_item_types
140
+ Piggybak::Config.line_item_types.sort { |a, b| a[1][:sort] <=> b[1][:sort] }.collect { |a| a[0] }
141
+ end
132
142
  end
133
143
  end
@@ -193,17 +193,5 @@ module Piggybak
193
193
  def admin_label
194
194
  "Order ##{self.id}"
195
195
  end
196
-
197
- def subtotal
198
- v = 0
199
-
200
- self.line_items.select { |li| li.line_item_type == "sellable" }.each do |line_item|
201
- if !line_item._destroy
202
- v += line_item.price
203
- end
204
- end
205
-
206
- v
207
- end
208
196
  end
209
197
  end
@@ -2,30 +2,16 @@
2
2
  N/A
3
3
  <% else -%>
4
4
  <table cellpadding="5" cellspacing="0">
5
+ <% Piggybak::LineItem.sorted_line_item_types.each do |type| -%>
5
6
  <tr>
6
- <td width="150">Subtotal (Sellables)</td>
7
- <td><%= number_to_currency form.object.subtotal %></td>
8
- </tr>
9
- <tr>
10
- <td>Shipping</td>
11
- <td><%= number_to_currency form.object.shipment_charge %></td>
12
- </tr>
13
- <tr>
14
- <td>Tax</td>
15
- <td><%= number_to_currency form.object.tax_charge %></td>
16
- </tr>
17
- <tr>
18
- <td>Adjustments</td>
19
- <td><%= number_to_currency form.object.adjustment_charge %></td>
7
+ <td width="150"><%= type.to_s.pluralize.titleize %></td>
8
+ <td><%= number_to_currency form.object.send("#{type}_charge") %></td>
20
9
  </tr>
10
+ <% end -%>
21
11
  <tr>
22
12
  <td>Total</td>
23
13
  <td><%= number_to_currency form.object.total %></td>
24
14
  </tr>
25
- <tr>
26
- <td>Payments</td>
27
- <td><%= number_to_currency form.object.payment_charge %></td>
28
- </tr>
29
15
  <tr>
30
16
  <td>Balance Due</td>
31
17
  <td><%= number_to_currency form.object.total_due %></td>
@@ -0,0 +1,9 @@
1
+ class DropSortFromLineItems < ActiveRecord::Migration
2
+ def up
3
+ remove_column :line_items, :sort
4
+ end
5
+
6
+ def down
7
+ add_column :line_items, :sort, :integer, :null => false, :default => 0
8
+ end
9
+ end
@@ -40,7 +40,7 @@ module Piggybak
40
40
  plural_k = k.to_s.pluralize.to_sym
41
41
  if v[:nested_attrs]
42
42
  Piggybak::LineItem.class_eval do
43
- # TODO: dependent destroy destroys all line items. Figure out why
43
+ # TODO: dependent destroy destroys all line items. Fix and remove after_destroy on line items
44
44
  has_one k, :class_name => v[:class_name] #, :dependent => :destroy
45
45
  accepts_nested_attributes_for k
46
46
  attr_accessible "#{k}_attributes".to_sym
@@ -51,10 +51,21 @@ module Piggybak
51
51
  end
52
52
  Piggybak::Order.class_eval do
53
53
  define_method "#{k}_charge" do
54
- self.line_items.send(plural_k).inject(0) { |subtotal, li| subtotal + li.price }
54
+ # Scope doesn't work here for lookup of unsaved elements
55
+ # TODO: Figure out if we can fix, or specify behavior
56
+ charge = 0
57
+ self.line_items.each do |li|
58
+ next if li._destroy || li.line_item_type.to_sym != k
59
+ charge += li.price
60
+ end
61
+ charge
55
62
  end
56
63
  end
57
64
  end
65
+ # Define method subtotal on order, alias to sellable_charge
66
+ Piggybak::Order.class_eval do
67
+ alias :subtotal :sellable_charge
68
+ end
58
69
  end
59
70
 
60
71
  initializer "piggybak.rails_admin_config" do |app|
@@ -62,8 +73,8 @@ module Piggybak
62
73
  plural_k = k.to_s.pluralize.to_sym
63
74
  if v[:nested_attrs]
64
75
  Piggybak::LineItem.class_eval do
65
- # TODO: dependent destroy destroys all line items. Figure out why
66
- has_one k, :class_name => v[:class_name] #, :dependent => :destroy
76
+ # TODO: See above
77
+ has_one k, :class_name => v[:class_name]
67
78
  accepts_nested_attributes_for k
68
79
  attr_accessible "#{k}_attributes".to_sym
69
80
  end
@@ -26,22 +26,27 @@ module Piggybak
26
26
 
27
27
  @line_item_types = { :sellable => { :visible => true,
28
28
  :fields => ["sellable_id", "quantity"],
29
- :allow_destroy => true },
29
+ :allow_destroy => true,
30
+ :sort => 1 },
30
31
  :payment => { :visible => true,
31
32
  :nested_attrs => true,
32
33
  :fields => ["payment"],
33
34
  :allow_destroy => false,
34
- :class_name => "::Piggybak::Payment" },
35
+ :class_name => "::Piggybak::Payment",
36
+ :sort => 5 },
35
37
  :shipment => { :visible => true,
36
38
  :nested_attrs => true,
37
39
  :fields => ["shipment"],
38
40
  :allow_destroy => true,
39
- :class_name => "::Piggybak::Shipment" },
41
+ :class_name => "::Piggybak::Shipment",
42
+ :sort => 2 },
40
43
  :adjustment => { :visible => true,
41
44
  :fields => ["description", "price"],
42
- :allow_destroy => true },
45
+ :allow_destroy => true,
46
+ :sort => 4 },
43
47
  :tax => { :visible => false,
44
- :allow_destroy => false }
48
+ :allow_destroy => false,
49
+ :sort => 3 }
45
50
  }
46
51
 
47
52
  @default_country = "US"
@@ -1,3 +1,3 @@
1
1
  module Piggybak
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
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.6.3
4
+ version: 0.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-18 00:00:00.000000000 Z
14
+ date: 2012-10-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -164,6 +164,7 @@ files:
164
164
  - db/migrate/20120716191225_add_masked_credit_card_numbers.rb
165
165
  - db/migrate/20111227150106_create_orders.rb
166
166
  - db/migrate/20111228231806_create_payment_methods.rb
167
+ - db/migrate/20121018213421_drop_sort_from_line_items.rb
167
168
  - db/migrate/20111228231838_create_shipments.rb
168
169
  - db/migrate/20120104020930_populate_countries_and_states.rb
169
170
  - db/migrate/20111227213558_create_variants.rb
@@ -207,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
207
208
  version: '0'
208
209
  segments:
209
210
  - 0
210
- hash: 364248551342590092
211
+ hash: 32961448645574721
211
212
  required_rubygems_version: !ruby/object:Gem::Requirement
212
213
  none: false
213
214
  requirements:
@@ -216,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  version: '0'
217
218
  segments:
218
219
  - 0
219
- hash: 364248551342590092
220
+ hash: 32961448645574721
220
221
  requirements: []
221
222
  rubyforge_project:
222
223
  rubygems_version: 1.8.23