solidus-returnly 0.2.1 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8133650d26f4d86877bf02cf2d5306f64c4b8d7d
4
- data.tar.gz: 176a63204f4bc506e6247069c993d1755344e990
3
+ metadata.gz: b0f4def9162a15735d56d0e508c00f16b208d490
4
+ data.tar.gz: 4a4871b9e78dbbabaf7749a4e3367011567c46d9
5
5
  SHA512:
6
- metadata.gz: 3a35811dedbce70c640b8df0d153445cc4dd7eecfcc4eb95966322ddfb2845e0047ad6fef07e199ceceddd0f8ba5403f035aface8c588851e842641a74ce4d0e
7
- data.tar.gz: 34dbb6b1a962345cc37c930b159b5132ca85c8e5b2b552c7ccb8fece606c4e22f5bed7889211cd6100550d5b843932eea620128b16e99965a07fa156ced803fe
6
+ metadata.gz: 5c8a78e67e2dbcd2ec8c42f451f0105c81f2b83d71b2b44935f995722c81dfc450a7876d9aaac786f23b9fabdd26c38525c98341adde5c3b8c6c250d54505d46
7
+ data.tar.gz: 31e5fcbcb4fa977710be28e31dea281c1554248390a142f8b52e0a47354d8fb117b2eb7dcd43c183d8fb4b111caef1c2f75c837f57d10f4ff1b9118234ff29ab
data/LICENSE CHANGED
@@ -1,26 +1,21 @@
1
- Copyright (c) 2017 [name of plugin creator]
2
- All rights reserved.
1
+ The MIT License
3
2
 
4
- Redistribution and use in source and binary forms, with or without modification,
5
- are permitted provided that the following conditions are met:
3
+ Copyright (c) 2017 Returnly Technologies, Inc.
6
4
 
7
- * Redistributions of source code must retain the above copyright notice,
8
- this list of conditions and the following disclaimer.
9
- * Redistributions in binary form must reproduce the above copyright notice,
10
- this list of conditions and the following disclaimer in the documentation
11
- and/or other materials provided with the distribution.
12
- * Neither the name Spree nor the names of its contributors may be used to
13
- endorse or promote products derived from this software without specific
14
- prior written permission.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
15
11
 
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -3,19 +3,13 @@ Solidus Returnly
3
3
 
4
4
  This gem adds the required APIs to allow returnly obtain an estimate, process a return and apply a reimbursement
5
5
 
6
-
7
- KNOW ISSUES
8
- -----------
9
- * Currently the restock feature only supports the order shipping warehouse
10
- * The API user should have the right to create an order there is no an special permission yet for this api
11
-
12
6
  Installation
13
7
  ------------
14
8
 
15
9
  Add solidus_returnly to your Gemfile:
16
10
 
17
11
  ```ruby
18
- gem 'solidus_returnly'
12
+ gem 'solidus-returnly'
19
13
  ```
20
14
 
21
15
  Bundle your dependencies and run the installation generator:
@@ -155,4 +149,4 @@ Response:
155
149
  ```
156
150
 
157
151
 
158
- Copyright (c) 2017 Returnly Technologies, Inc, released under the New BSD License
152
+ Copyright (c) 2017 Returnly Technologies, Inc
data/Rakefile CHANGED
@@ -22,6 +22,6 @@ end
22
22
 
23
23
  desc 'Generates a dummy app for testing'
24
24
  task :test_app do
25
- ENV['LIB_NAME'] = 'solidus_returnly'
25
+ ENV['LIB_NAME'] = 'solidus-returnly'
26
26
  Rake::Task['extension:test_app'].invoke
27
27
  end
@@ -2,7 +2,6 @@ module Spree
2
2
  module Api
3
3
  module Returnly
4
4
  class RefundsController < ApiController
5
-
6
5
  def estimate
7
6
  authorize! :create, Order
8
7
  render json: Solidus::Returnly::Calculator.process(order, line_items_params)
@@ -39,4 +38,3 @@ module Spree
39
38
  end
40
39
  end
41
40
  end
42
-
@@ -1,13 +1,14 @@
1
1
  module Spree
2
2
  module Api
3
- class ReturnlyVersionController < ApiController
4
- def index
5
- render json: {
6
- extension_version: Solidus::Returly::VERSION,
7
- platform_version: Solidus::VERSION,
8
- }
3
+ module Returnly
4
+ class VersionController < ApiController
5
+ def index
6
+ render json: {
7
+ extension_version: Solidus::Returnly::VERSION,
8
+ platform_version: Spree.solidus_version
9
+ }
10
+ end
9
11
  end
10
-
11
12
  end
12
13
  end
13
14
  end
@@ -4,26 +4,15 @@ module SolidusReturnly
4
4
  class_option :auto_run_migrations, type: :boolean, default: false
5
5
 
6
6
  def add_javascripts
7
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_returnly\n"
8
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_returnly\n"
9
7
  end
10
8
 
11
9
  def add_stylesheets
12
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_returnly\n", before: /\*\//, verbose: true
13
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_returnly\n", before: /\*\//, verbose: true
14
10
  end
15
11
 
16
12
  def add_migrations
17
- run 'bundle exec rake railties:install:migrations FROM=solidus_returnly'
18
13
  end
19
14
 
20
15
  def run_migrations
21
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
22
- if run_migrations
23
- run 'bundle exec rake db:migrate'
24
- else
25
- puts 'Skipping rake db:migrate, don\'t forget to run it!'
26
- end
27
16
  end
28
17
  end
29
18
  end
@@ -2,4 +2,4 @@ require 'solidus_core'
2
2
 
3
3
  require 'solidus/returnly/engine'
4
4
  require 'solidus/returnly/refunds'
5
- require 'solidus/returnly/calculator'
5
+ require 'solidus/returnly/calculator'
@@ -13,16 +13,18 @@ module Solidus
13
13
  end
14
14
 
15
15
  def calculated_estimate
16
- total = line_items_return_items.values.sum {|iu| iu.sum(&:pre_tax_amount)}
16
+ total = 0.0
17
+ sub_total = 0.0
17
18
 
18
- tax_amount = returnable_inventory_units.sum do |inventory_unit|
19
- calculate_tax inventory_unit
19
+ line_items_return_items.values.flatten.each do |return_item|
20
+ total += return_item.total
21
+ sub_total += return_item.pre_tax_amount
20
22
  end
21
23
 
22
24
  {
23
25
  total_amount: total,
24
- subtotal_amount: total - tax_amount,
25
- tax_amount: tax_amount,
26
+ subtotal_amount: sub_total,
27
+ tax_amount: total - sub_total,
26
28
  discount_amount: order.promo_total,
27
29
  shipping_amount: order.shipment_total,
28
30
  line_items: present_line_items
@@ -30,44 +32,58 @@ module Solidus
30
32
  end
31
33
 
32
34
  def present_line_items
33
- line_items_return_items.map do |line_item_id, inventory_units|
34
- line_item = line_item(line_item_id)
35
+ line_items_return_items.values.map do |return_items|
36
+ line_item = return_items.first.inventory_unit.line_item
37
+
38
+ total_amount = 0.0
39
+ sub_total = 0.0
40
+
41
+ return_items.each do |return_item|
42
+ total_amount += return_item.total
43
+ sub_total += return_item.pre_tax_amount
44
+ end
35
45
 
36
46
  {
37
47
  order_line_item_id: line_item.id,
38
- quantity: inventory_units.size,
39
- total_amount: inventory_units.sum(&:amount),
40
- tax_amount: line_item.included_tax_total,
41
- discount_amount: line_item.adjustment_total,
48
+ quantity: return_items.size,
49
+ total_amount: total_amount,
50
+ tax_amount: total_amount - sub_total
42
51
  }
43
52
  end
44
53
  end
45
54
 
55
+ def set_tax(return_item)
56
+ percent_of_tax = (return_item.amount <= 0) ? 0 : return_item.amount /
57
+ Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)
46
58
 
47
- def calculate_tax(inventory_unit)
48
- return_item = Spree::ReturnItem.from_inventory_unit(inventory_unit)
49
- (return_item.amount <= 0) ? 0 : return_item.amount /
50
- Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)
51
- end
59
+ additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
60
+ included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
61
+
62
+ return_item.additional_tax_total = additional_tax_total
63
+ return_item.included_tax_total = included_tax_total
52
64
 
65
+ return_item
66
+ end
53
67
 
54
68
  def line_items_return_items
55
69
  found_return_items = {}
56
70
 
57
- self.line_items.each do |line_item|
71
+ line_items.each do |line_item|
58
72
  quantity = line_item[:quantity].to_i
59
73
 
60
- if quantity > 0
61
- available_inventory_units = line_item_inventory_unit(line_item).slice(0, quantity)
62
-
63
- available_inventory_units.each do |inventory_unit|
64
- found_return_items[line_item[:order_line_item_id]] ||= []
65
- found_return_items[line_item[:order_line_item_id]] << Spree::ReturnItem.new({amount: inventory_unit.line_item.price,
66
- acceptance_status: 'accepted',
67
- inventory_unit_id: inventory_unit.id,
68
- reception_status_event: 'receive'
69
- })
70
- end
74
+ next unless quantity > 0
75
+ available_inventory_units = line_item_inventory_unit(line_item).slice(0, quantity)
76
+
77
+ available_inventory_units.each do |inventory_unit|
78
+ found_return_items[line_item[:order_line_item_id]] ||= []
79
+
80
+ return_item = Spree::ReturnItem.new({ amount: inventory_unit.line_item.price,
81
+ acceptance_status: 'accepted',
82
+ inventory_unit_id: inventory_unit.id,
83
+ reception_status_event: 'receive'
84
+ })
85
+
86
+ found_return_items[line_item[:order_line_item_id]] << set_tax(return_item)
71
87
  end
72
88
  end
73
89
 
@@ -75,11 +91,11 @@ module Solidus
75
91
  end
76
92
 
77
93
  def line_item_inventory_unit(line_item)
78
- returnable_inventory_units.select {|iu| iu.line_item_id == line_item[:order_line_item_id].to_i}
94
+ returnable_inventory_units.select { |iu| iu.line_item_id == line_item[:order_line_item_id].to_i }
79
95
  end
80
96
 
81
97
  def line_item(id)
82
- returnable_line_items.select {|i| i.id == id.to_i}.first
98
+ returnable_line_items.find { |i| i.id == id.to_i }
83
99
  end
84
100
 
85
101
  def returnable_inventory_units
@@ -93,10 +109,8 @@ module Solidus
93
109
  end
94
110
 
95
111
  def requested_line_items
96
- line_items.map {|item| item[:order_line_item_id]}
112
+ line_items.map { |item| item[:order_line_item_id] }
97
113
  end
98
114
  end
99
115
  end
100
116
  end
101
-
102
-
@@ -52,5 +52,4 @@ module Solidus
52
52
  end
53
53
  end
54
54
  end
55
-
56
- end
55
+ end
@@ -1,7 +1,7 @@
1
1
  module Solidus
2
2
  module Returnly
3
3
  class Refunds
4
- attr_accessor :calculator, :order, :line_items, :restock, :transactions
4
+ attr_accessor :calculator, :order, :line_items, :restock, :transactions, :customer_return
5
5
 
6
6
  def initialize(order:, line_items:, restock: true, transactions:)
7
7
  self.order = order
@@ -9,25 +9,19 @@ module Solidus
9
9
  self.calculator = Calculator.new order, line_items
10
10
  self.restock = restock
11
11
  self.transactions = transactions
12
- end
13
-
14
- def restock_return(customer_return)
15
- customer_return.return_items.each do |item|
16
- customer_return.stock_location.restock(item.inventory_unit.variant, 1, customer_return)
17
- end
12
+ self.customer_return = Spree::CustomerReturn.new customer_return_params
18
13
  end
19
14
 
20
15
  def proceed!
21
- customer_return = Spree::CustomerReturn.new customer_return_params
22
16
  customer_return.return_items = calculator.line_items_return_items.values.flatten
23
17
 
24
18
  customer_return.return_items.each do |return_item|
25
- return_item.amount = refund_amount_per_item
26
- return_item.resellable = self.restock
19
+ return_item.amount = refund_amount_per_item - Money.from_amount(return_item.total - return_item.pre_tax_amount)
20
+ return_item.resellable = restock
27
21
  end
28
22
 
29
23
  if customer_return.save!
30
- reimbursement = perform_reimbursement(customer_return)
24
+ perform_reimbursement
31
25
  processed_customer_return(customer_return, reimbursement)
32
26
  end
33
27
  end
@@ -37,32 +31,35 @@ module Solidus
37
31
  refund_id: customer_return.number,
38
32
  created_at: customer_return.created_at,
39
33
  updated_at: customer_return.updated_at,
40
- line_items: customer_return.return_items.map {|ri|
34
+ line_items: customer_return.return_items.group_by{ |ri| ri.inventory_unit.line_item.id }.map {|_, return_items|
41
35
  {
42
- refund_line_item_id: ri.id,
43
- order_line_item_id: ri.inventory_unit.line_item.id,
44
- quantity: 1
36
+ refund_line_item_id: return_items.first.id,
37
+ order_line_item_id: return_items.first.inventory_unit.line_item.id,
38
+ refunded_amount_per_item: return_items.first.amount.to_f,
39
+ total_refunded_per_line_item: return_items.sum(&:amount).to_f,
40
+ quantity: return_items.size
45
41
  }
46
42
  },
47
43
  transactions: [
48
44
  id: reimbursement.id,
49
45
  amount: reimbursement.total
50
46
  ],
51
- note: "comment text",
52
- restock: true
47
+ restock: restock
53
48
  }
54
49
  end
55
50
 
56
- def perform_reimbursement(customer_return)
57
- reimbursement = Spree::Reimbursement.build_from_customer_return(customer_return)
51
+ def perform_reimbursement
58
52
  reimbursement.save!
59
53
  reimbursement.perform!
60
- reimbursement
54
+ end
55
+
56
+ def reimbursement
57
+ @_reimbursement ||= Spree::Reimbursement.build_from_customer_return(customer_return)
61
58
  end
62
59
 
63
60
  def customer_return_params
64
61
  {
65
- stock_location_id: stock_location_id,
62
+ stock_location_id: stock_location_id
66
63
  }
67
64
  end
68
65
 
@@ -71,7 +68,7 @@ module Solidus
71
68
  end
72
69
 
73
70
  def refund_available_amount
74
- @available_amount ||= self.transactions.sum {|t| Money.from_amount(t[:amount].to_f)}
71
+ @available_amount ||= transactions.sum { |t| Money.from_amount(t[:amount].to_f) }
75
72
  end
76
73
 
77
74
  def refund_amount_per_item
@@ -79,5 +76,4 @@ module Solidus
79
76
  end
80
77
  end
81
78
  end
82
-
83
- end
79
+ end
@@ -1,5 +1,5 @@
1
1
  module Solidus
2
2
  module Returnly
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
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.2.1
4
+ version: 0.3.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: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: byebug
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  description: Solidus API extensions for returnly
238
252
  email: support@returnly.com
239
253
  executables: []