spree_core 2.1.6 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4c8f9444abee12730e46a75f58276b4a89a54ce
4
- data.tar.gz: 02d28150421a8deb02c47a16a514ceea6e6775ce
3
+ metadata.gz: ee66832489cf763d21c38a512e8b99392c104dba
4
+ data.tar.gz: 9e34bc2957303933d3b7ba62d043d27daac480c4
5
5
  SHA512:
6
- metadata.gz: 94c500d3cba6d3c9388d64f5304dd43391ecd9fc8aabf0c694cec4f3678f7e808039e7dd082aa932623ddfbf200c1e3ca525e34861fc82a2302650f09c0db57e
7
- data.tar.gz: 81aa93fc583a3eefaeea0804812ad174ecd359b4a1445f030a1ab40e54fb1290c8c9c570099b2e5ad5f8e12d46a0c91fda2a0682a07735a1883051a5c5da0276
6
+ metadata.gz: 9afb43b63ff91f6293536c6c3ab9bb451d8fefb01ab318e7efb401e1934b3e814a8796f53463271ad9a8f5d9588e53c748adce20ce89012dcbf1b4e8be0c2ec2
7
+ data.tar.gz: a845cd6990e60b712c0fa99e630ebe2b5c46d6abe7181e9e8f5508b4d8feb7f0f7c13736ff717fd258ecb749cfe8e5761bd963a3b3d5d1b3ef5881e9c740388a
@@ -26,12 +26,18 @@ module Spree
26
26
  }
27
27
 
28
28
  def expiry=(expiry)
29
- if expiry.present?
30
- self[:month], self[:year] = expiry.delete(' ').split('/')
31
- self[:year] = "20" + self[:year] if self[:year].length == 2
32
- self[:year] = self[:year].to_i
33
- self[:month] = self[:month].to_i
29
+ return unless expiry.present?
30
+
31
+ self[:month], self[:year] =
32
+ if expiry.match(/\d\s?\/\s?\d/) # will match mm/yy and mm / yyyy
33
+ expiry.delete(' ').split('/')
34
+ elsif match = expiry.match(/(\d{2})(\d{2,4})/) # will match mmyy and mmyyyy
35
+ [match[1], match[2]]
34
36
  end
37
+
38
+ self[:year] = "20" + self[:year] if self[:year].length == 2
39
+ self[:year] = self[:year].to_i
40
+ self[:month] = self[:month].to_i
35
41
  end
36
42
 
37
43
  def number=(num)
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class LineItem < ActiveRecord::Base
3
3
  before_validation :adjust_quantity
4
- belongs_to :order, class_name: "Spree::Order"
4
+ belongs_to :order, class_name: "Spree::Order", touch: true
5
5
  belongs_to :variant, class_name: "Spree::Variant"
6
6
  belongs_to :tax_category, class_name: "Spree::TaxCategory"
7
7
 
@@ -63,7 +63,7 @@ module Spree
63
63
  end
64
64
 
65
65
  def sufficient_stock?
66
- Stock::Quantifier.new(variant_id).can_supply? quantity
66
+ Stock::Quantifier.new(variant).can_supply? quantity
67
67
  end
68
68
 
69
69
  def insufficient_stock?
@@ -79,8 +79,12 @@ module Spree
79
79
  where(number: number)
80
80
  end
81
81
 
82
+ scope :created_between, ->(start_date, end_date) { where(created_at: start_date..end_date) }
83
+ scope :completed_between, ->(start_date, end_date) { where(completed_at: start_date..end_date) }
84
+
82
85
  def self.between(start_date, end_date)
83
- where(created_at: start_date..end_date)
86
+ ActiveSupport::Deprecation.warn("Order#between will be deprecated in Spree 2.3, please use either Order#created_between or Order#completed_between instead.")
87
+ self.created_between(start_date, end_date)
84
88
  end
85
89
 
86
90
  def self.by_customer(customer)
@@ -572,7 +576,7 @@ module Spree
572
576
 
573
577
  def after_cancel
574
578
  shipments.each { |shipment| shipment.cancel! }
575
- payments.completed.each { |payment| payment.credit! }
579
+ payments.completed.each { |payment| payment.cancel! }
576
580
 
577
581
  send_cancel_email
578
582
  self.update_column(:payment_state, 'credit_owed') unless shipped?
@@ -102,8 +102,8 @@ module Spree
102
102
 
103
103
  # see https://github.com/spree/spree/issues/981
104
104
  def build_source
105
- return if source_attributes.nil?
106
- if payment_method and payment_method.payment_source_class
105
+ return unless new_record?
106
+ if source_attributes.present? && source.blank? && payment_method.try(:payment_source_class)
107
107
  self.source = payment_method.payment_source_class.new(source_attributes)
108
108
  end
109
109
  end
@@ -108,6 +108,14 @@ module Spree
108
108
  end
109
109
  end
110
110
 
111
+ def cancel!
112
+ if payment_method.respond_to?(:cancel)
113
+ payment_method.cancel(response_code)
114
+ else
115
+ credit!
116
+ end
117
+ end
118
+
111
119
  def partial_credit(amount)
112
120
  return if amount > credit_allowed
113
121
  started_processing!
@@ -115,6 +123,7 @@ module Spree
115
123
  end
116
124
 
117
125
  def gateway_options
126
+ order.reload
118
127
  options = { :email => order.email,
119
128
  :customer => order.email,
120
129
  :customer_id => order.user_id,
@@ -10,7 +10,7 @@ module Spree
10
10
  quantity = line_item.quantity
11
11
  end
12
12
 
13
- quantifier = Stock::Quantifier.new(line_item.variant_id)
13
+ quantifier = Stock::Quantifier.new(line_item.variant)
14
14
 
15
15
  unless quantifier.can_supply? quantity
16
16
  variant = line_item.variant
@@ -4,7 +4,7 @@ module Spree
4
4
  attr_reader :stock_items
5
5
 
6
6
  def initialize(variant)
7
- @variant = resolve_variant_id(variant)
7
+ @variant = variant
8
8
  @stock_items = Spree::StockItem.joins(:stock_location).where(:variant_id => @variant, Spree::StockLocation.table_name =>{ :active => true})
9
9
  end
10
10
 
@@ -24,14 +24,6 @@ module Spree
24
24
  total_on_hand >= required || backorderable?
25
25
  end
26
26
 
27
- private
28
-
29
- # return variant when passed either variant object or variant id
30
- def resolve_variant_id(variant)
31
- variant = Spree::Variant.find_by_id(variant) unless variant.respond_to?(:should_track_inventory?)
32
- variant
33
- end
34
-
35
27
  end
36
28
  end
37
29
  end
@@ -44,6 +44,10 @@ module Spree
44
44
  self.in_stock? || self.backorderable?
45
45
  end
46
46
 
47
+ def variant
48
+ Spree::Variant.unscoped { super }
49
+ end
50
+
47
51
  private
48
52
  def count_on_hand=(value)
49
53
  write_attribute(:count_on_hand, value)
@@ -23,8 +23,9 @@ module Spree
23
23
 
24
24
  # Gets the array of TaxRates appropriate for the specified order
25
25
  def self.match(order)
26
- return [] unless order.tax_zone
27
- all.select do |rate|
26
+ order_zone = order.tax_zone
27
+ return [] unless order_zone
28
+ includes(zone: { zone_members: :zoneable }).load.select do |rate|
28
29
  (!rate.included_in_price && (rate.zone == order.tax_zone || rate.zone.contains?(order.tax_zone) || (order.tax_address.nil? && rate.zone.default_tax))) ||
29
30
  rate.included_in_price
30
31
  end
@@ -75,7 +75,7 @@ module Spree
75
75
  # allows extensions to override deleted? if they want to provide
76
76
  # their own definition.
77
77
  def deleted?
78
- deleted_at
78
+ !!deleted_at
79
79
  end
80
80
 
81
81
  # Product may be created with deleted_at already set,
@@ -149,9 +149,13 @@ module Spree
149
149
  "#{sku} #{options_text}".strip
150
150
  end
151
151
 
152
- def in_stock?(quantity=1)
153
- puts %q{[DEPRECATION] In Spree 2.2, Variant#in_stock? will no longer take a quantity. Use Variant#can_supply? instead.}
154
- can_stock?(quantity)
152
+ def in_stock?(quantity=:argument_here_is_deprecated)
153
+ if quantity == :argument_here_is_deprecated
154
+ can_stock?(1)
155
+ else
156
+ puts %q{[DEPRECATION] In Spree 2.2, Variant#in_stock? will no longer take a quantity. Use Variant#can_supply? instead.}
157
+ can_stock?(quantity)
158
+ end
155
159
  end
156
160
 
157
161
  def can_stock?(quantity=1)
@@ -3,7 +3,7 @@ class MigrateOldShippingCalculators < ActiveRecord::Migration
3
3
  Spree::ShippingMethod.all.each do |shipping_method|
4
4
  old_calculator = shipping_method.calculator
5
5
  next if old_calculator.class < Spree::ShippingCalculator # We don't want to mess with new shipping calculators
6
- new_calculator = eval("Spree::Calculator::Shipping::#{old_calculator.class.name.demodulize}").new
6
+ new_calculator = eval(old_calculator.class.name.sub("::Calculator::", "::Calculator::Shipping::")).new
7
7
  new_calculator.preferences.keys.each do |pref|
8
8
  # Preferences can't be read/set by name, you have to prefix preferred_
9
9
  pref_method = "preferred_#{pref}"
@@ -0,0 +1,5 @@
1
+ class AddUserIdCreatedByIdIndexToOrder < ActiveRecord::Migration
2
+ def change
3
+ add_index :spree_orders, [:user_id, :created_by_id]
4
+ end
5
+ end
data/lib/spree/core.rb CHANGED
@@ -5,6 +5,7 @@ require 'awesome_nested_set'
5
5
  require 'cancan'
6
6
  require 'kaminari'
7
7
  require 'mail'
8
+ require 'monetize'
8
9
  require 'paperclip'
9
10
  require 'paranoia'
10
11
  require 'ransack'
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.1.6"
3
+ "2.1.7"
4
4
  end
5
5
  end
data/lib/spree/money.rb CHANGED
@@ -30,7 +30,7 @@ module Spree
30
30
 
31
31
  # Check the first character for a currency symbol, alternatively get it
32
32
  # from the stated currency string
33
- c = if ::Money.assume_from_symbol && i =~ /^(\$|€|£)/
33
+ c = if ::Monetize.assume_from_symbol && i =~ /^(\$|€|£)/
34
34
  case i
35
35
  when /^\$/ then "USD"
36
36
  when /^€/ then "EUR"
@@ -52,6 +52,8 @@ FactoryGirl.define do
52
52
 
53
53
  factory :shipped_order do
54
54
  after(:create) do |order|
55
+ order.update_totals # To ensure we have the right total
56
+ create(:payment, amount: order.total, order: order, state: 'completed')
55
57
  order.shipments.each do |shipment|
56
58
  shipment.inventory_units.each { |u| u.update_column('state', 'shipped') }
57
59
  shipment.update_column('state', 'shipped')
@@ -2,14 +2,15 @@ FactoryGirl.define do
2
2
  factory :shipment, class: Spree::Shipment do
3
3
  tracking 'U10000'
4
4
  number '100'
5
- cost 100.00
6
5
  state 'pending'
7
6
  order
8
7
  address
9
8
  stock_location
10
9
 
11
10
  after(:create) do |shipment, evalulator|
12
- shipment.add_shipping_method(create(:shipping_method), true)
11
+ shipping_method = create(:shipping_method)
12
+ shipping_method.calculator.preferred_amount = 100
13
+ shipment.add_shipping_method(shipping_method, true)
13
14
 
14
15
  shipment.order.line_items.each do |line_item|
15
16
  line_item.quantity.times { shipment.inventory_units.create(variant_id: line_item.variant_id) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.6
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.15.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: monetize
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: paperclip
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -514,6 +528,7 @@ files:
514
528
  - db/migrate/20140129024326_add_deleted_at_to_spree_prices.rb
515
529
  - db/migrate/20140204192230_add_auto_capture_to_payment_methods.rb
516
530
  - db/migrate/20140205181631_default_variant_weight_to_zero.rb
531
+ - db/migrate/20140415041315_add_user_id_created_by_id_index_to_order.rb
517
532
  - db/seeds.rb
518
533
  - lib/generators/spree/custom_user/custom_user_generator.rb
519
534
  - lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
@@ -663,7 +678,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
663
678
  version: '0'
664
679
  requirements: []
665
680
  rubyforge_project:
666
- rubygems_version: 2.2.2
681
+ rubygems_version: 2.2.0
667
682
  signing_key:
668
683
  specification_version: 4
669
684
  summary: The bare bones necessary for Spree.