spree_core 2.4.0 → 2.4.1
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 +4 -4
- data/app/models/spree/promotion/rules/product.rb +8 -1
- data/app/models/spree/reimbursement.rb +19 -1
- data/app/models/spree/reimbursement/reimbursement_type_validator.rb +4 -1
- data/app/models/spree/reimbursement_type/credit.rb +1 -1
- data/app/models/spree/reimbursement_type/original_payment.rb +1 -1
- data/app/models/spree/store.rb +7 -2
- data/config/locales/en.yml +5 -0
- data/lib/spree/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c3f728999034d676a7bade2faa38354f43b90e7
|
4
|
+
data.tar.gz: f4112e883677f3f9561afac00de040a5191141d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abc9b0511722dada69919986af38a1c160ea1b4eae247936d57bc0e9bf9316e699e2dfb15469dcfec67ccd59a54fc1689cabb7a19960f00bedf2fbab38edb231
|
7
|
+
data.tar.gz: 6e515054c8250211a602f28d42dcc519502ca09f2928a755546ae44860fea1bc8499562fbf30a70300c75311095f7f69093d26805158d0d4c769eade5dd4247f
|
@@ -40,7 +40,14 @@ module Spree
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def actionable?(line_item)
|
43
|
-
|
43
|
+
case preferred_match_policy
|
44
|
+
when 'any', 'all'
|
45
|
+
product_ids.include? line_item.variant.product_id
|
46
|
+
when 'none'
|
47
|
+
product_ids.exclude? line_item.variant.product_id
|
48
|
+
else
|
49
|
+
raise "unexpected match policy: #{preferred_match_policy.inspect}"
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
def product_ids_string
|
@@ -105,7 +105,7 @@ module Spree
|
|
105
105
|
|
106
106
|
reimbursement_performer.perform(self)
|
107
107
|
|
108
|
-
if
|
108
|
+
if unpaid_amount_within_tolerance?
|
109
109
|
reimbursed!
|
110
110
|
reimbursement_success_hooks.each { |h| h.call self }
|
111
111
|
send_reimbursement_email
|
@@ -146,5 +146,23 @@ module Spree
|
|
146
146
|
def send_reimbursement_email
|
147
147
|
Spree::ReimbursementMailer.reimbursement_email(self.id).deliver
|
148
148
|
end
|
149
|
+
|
150
|
+
# If there are multiple different reimbursement types for a single
|
151
|
+
# reimbursement we open ourselves to a one-cent rounding error for every
|
152
|
+
# type over the first one. This is due to how we round #unpaid_amount and
|
153
|
+
# how each reimbursement type will round as well. Since at this point the
|
154
|
+
# payments and credits have already been processed, we should allow the
|
155
|
+
# reimbursement to show as 'reimbursed' and not 'errored'.
|
156
|
+
def unpaid_amount_within_tolerance?
|
157
|
+
reimbursement_count = reimbursement_models.count do |model|
|
158
|
+
model.total_amount_reimbursed_for(self) > 0
|
159
|
+
end
|
160
|
+
leniency = if reimbursement_count > 0
|
161
|
+
(reimbursement_count - 1) * 0.01.to_d
|
162
|
+
else
|
163
|
+
0
|
164
|
+
end
|
165
|
+
unpaid_amount.abs.between?(0, leniency)
|
166
|
+
end
|
149
167
|
end
|
150
168
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module Spree
|
2
2
|
module Reimbursement::ReimbursementTypeValidator
|
3
3
|
def valid_preferred_reimbursement_type?(return_item)
|
4
|
-
|
4
|
+
preferred_type = return_item.preferred_reimbursement_type.class
|
5
|
+
|
6
|
+
!past_reimbursable_time_period?(return_item) ||
|
7
|
+
preferred_type == expired_reimbursement_type
|
5
8
|
end
|
6
9
|
|
7
10
|
def past_reimbursable_time_period?(return_item)
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def reimburse(reimbursement, return_items, simulate)
|
7
|
-
unpaid_amount = return_items.sum(&:total).round(2)
|
7
|
+
unpaid_amount = return_items.sum(&:total).round(2, :down)
|
8
8
|
reimbursement_list, unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate)
|
9
9
|
reimbursement_list
|
10
10
|
end
|
@@ -3,7 +3,7 @@ class Spree::ReimbursementType::OriginalPayment < Spree::ReimbursementType
|
|
3
3
|
|
4
4
|
class << self
|
5
5
|
def reimburse(reimbursement, return_items, simulate)
|
6
|
-
unpaid_amount = return_items.sum(&:total).round(2)
|
6
|
+
unpaid_amount = return_items.sum(&:total).round(2, :down)
|
7
7
|
payments = reimbursement.order.payments.completed
|
8
8
|
|
9
9
|
refund_list, unpaid_amount = create_refunds(reimbursement, payments, unpaid_amount, simulate)
|
data/app/models/spree/store.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Spree
|
2
2
|
class Store < Spree::Base
|
3
|
-
|
4
3
|
validates :code, presence: true, uniqueness: { allow_blank: true }
|
5
4
|
validates :name, presence: true
|
6
5
|
validates :url, presence: true
|
7
6
|
validates :mail_from_address, presence: true
|
8
7
|
|
9
8
|
before_create :ensure_default_exists_and_is_unique
|
9
|
+
before_destroy :validate_not_default
|
10
10
|
|
11
11
|
scope :by_url, lambda { |url| where("url like ?", "%#{url}%") }
|
12
12
|
|
@@ -24,10 +24,15 @@ module Spree
|
|
24
24
|
def ensure_default_exists_and_is_unique
|
25
25
|
if default
|
26
26
|
Store.update_all(default: false)
|
27
|
-
|
27
|
+
elsif Store.where(default: true).count == 0
|
28
28
|
self.default = true
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def validate_not_default
|
33
|
+
if default
|
34
|
+
errors.add(:base, :cannot_destroy_default_store)
|
35
|
+
end
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
data/config/locales/en.yml
CHANGED
@@ -298,6 +298,11 @@ en:
|
|
298
298
|
cannot_be_associated_unless_accepted: cannot be associated to a return item that is not accepted.
|
299
299
|
inventory_unit:
|
300
300
|
other_completed_return_item_exists: "%{inventory_unit_id} has already been taken by return item %{return_item_id}"
|
301
|
+
spree/store:
|
302
|
+
attributes:
|
303
|
+
base:
|
304
|
+
cannot_destroy_default_store: Cannot destroy the default Store.
|
305
|
+
|
301
306
|
|
302
307
|
devise:
|
303
308
|
confirmations:
|
data/lib/spree/core/version.rb
CHANGED
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.4.
|
4
|
+
version: 2.4.1
|
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-11-
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|