solidus-returnly 0.11.0 → 0.12.0

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
  SHA256:
3
- metadata.gz: bbba58335cd0c6733fd3ac7ac1cd1138f9fe60c3c9fd054d333d6cd214880af4
4
- data.tar.gz: 92908dfff3ed9d1725e8439404ea3da94bbe7849d6b004ea95eb81dca871e7ac
3
+ metadata.gz: c65b26145ed509d151c337ef349bb1573cba5703e80b646dfa874ac6566c66a2
4
+ data.tar.gz: ea4067aaaf9ebd7b97927c2e9c586f4398654e4388009f2c5f226ceaa9b70979
5
5
  SHA512:
6
- metadata.gz: acb300cf3987ae5db4687721141f20336abb11cd333e27f44edd60a45a8b0b63d362a5c1cd31da59654c7788a2f07a8099b554facacf5bd8f9273c339d222f48
7
- data.tar.gz: bc19abf556483df2f5c5931f1e607607fc2f414cb51e93423c0c1287091c4eee51ecef94e47de732a8c1f7645151ee8c7807e5d4fb403a4cb47191144784245c
6
+ metadata.gz: 8be45554263a53fd0e88c8a9255d437861815e01cc174bc3f0d0b8476d71e4cca99068a493257b7e6297c60cd9319bc3488b1457d2d41d24cf2f57ec12940de8
7
+ data.tar.gz: b9322a7879716d05367cce5609737af8f628a43bb34412d0b9691ca3487ce2862a8aa95531b345d1db470616f6d262d627d6f5cd11a9323f6d68891f47bf34a5
@@ -8,30 +8,19 @@ module Returnly
8
8
  end
9
9
 
10
10
  def build_by_requested_line_items(requested_line_items)
11
- is_returned_item = false
12
- items = requested_line_items.each_with_object([]) do |request_line_item, return_items|
11
+ requested_line_items.each_with_object([]) do |request_line_item, return_items|
13
12
  quantity = request_line_item[:units].to_i
14
13
  next return_items unless quantity > 0
15
14
 
16
- inventory_units = inventory_units_by(request_line_item[:order_line_item_id])
17
- if inventory_units.empty?
18
- inventory_units = returned_inventory_units_by(request_line_item[:order_line_item_id])
19
- request_line_item[:find_return?] = true
20
- is_returned_item = true
21
- end
22
- inventory_units.take(quantity).each do |inventory_unit|
15
+ inventory_units_by(request_line_item[:order_line_item_id]).take(quantity).each do |inventory_unit|
23
16
  return_items << build_by_inventory_unit(inventory_unit, request_line_item)
24
17
  end
25
18
 
26
19
  return_items
27
20
  end
28
- {
29
- items: items,
30
- is_returned_items: is_returned_item
31
- }
32
21
  end
33
22
 
34
- def exact_build_by_inventory_unit(inventory_unit, options = {})
23
+ def build_by_inventory_unit(inventory_unit, options = {})
35
24
  Spree::ReturnItem.new(
36
25
  amount: inventory_unit.line_item.price,
37
26
  acceptance_status: 'accepted',
@@ -41,14 +30,6 @@ module Returnly
41
30
  )
42
31
  end
43
32
 
44
- def build_by_inventory_unit(inventory_unit, options = {})
45
- return exact_build_by_inventory_unit(inventory_unit, options) unless options[:find_return?]
46
- Spree::ReturnItem.find_by(
47
- amount: inventory_unit.line_item.price,
48
- inventory_unit_id: inventory_unit.id
49
- )
50
- end
51
-
52
33
  private
53
34
 
54
35
  def inventory_units_by(line_item_ids)
@@ -56,12 +37,6 @@ module Returnly
56
37
  .where(line_item_id: line_item_ids)
57
38
  .where.not(state: 'returned')
58
39
  end
59
-
60
- def returned_inventory_units_by(line_item_ids)
61
- order.inventory_units.includes(:line_item, :return_items)
62
- .where(line_item_id: line_item_ids, state: 'returned')
63
- .where(spree_return_items: { reimbursement_id: nil })
64
- end
65
40
  end
66
41
  end
67
42
  end
@@ -21,17 +21,12 @@ module Returnly
21
21
  end
22
22
 
23
23
  def line_items_return_items
24
- available_to_return = available_return_items
25
- items = available_to_return[:items].each_with_object({}) do |return_item, return_items|
24
+ available_return_items.each_with_object({}) do |return_item, return_items|
26
25
  line_item_id = return_item.inventory_unit.line_item_id
27
26
  return_items[line_item_id] ||= []
28
27
  return_items[line_item_id] << set_tax(return_item)
29
28
  return_items
30
29
  end
31
- {
32
- items: items,
33
- is_returned_items: available_to_return[:is_returned_items]
34
- }
35
30
  end
36
31
 
37
32
  def shipping_tax
@@ -5,16 +5,12 @@ module Returnly
5
5
  sub_total = Money.new 0
6
6
  tax = Money.new 0
7
7
 
8
- return_items = calculator.line_items_return_items
9
- return_items[:items].values.flatten.each do |return_item|
10
- sub_total += Money.from_amount return_item.total_excluding_vat
8
+ calculator.line_items_return_items.values.flatten.each do |return_item|
9
+ sub_total += Money.from_amount return_item.inventory_unit.line_item.price
11
10
  tax += Money.from_amount calculator.line_item_tax(return_item.inventory_unit.line_item)
12
11
  end
13
12
 
14
13
  discount = Money.from_amount(calculator.discount)
15
- if return_items[:is_returned_items]
16
- sub_total += discount
17
- end
18
14
  total_refund_amount = sub_total + tax - (discount * -1) # discount is negative, so we multiply it by -1 to make it positive for subtraction
19
15
  shipping_tax = calculator.shipping_tax
20
16
  {
@@ -95,7 +95,7 @@ module Returnly
95
95
  end
96
96
 
97
97
  def each_return_item
98
- return_items = refund_calculator.line_items_return_items[:items].values.flatten
98
+ return_items = refund_calculator.line_items_return_items.values.flatten
99
99
  self.customer_return = Returnly::Builders::CustomerReturn.build_by_return_items(return_items)
100
100
 
101
101
  return_items.each do |return_item|
@@ -1,5 +1,5 @@
1
1
  module Returnly
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0'
3
3
 
4
4
  def platform_version
5
5
  defined?(Solidus)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus-returnly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Returnly Technologies, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus