active_fulfillment 1.0.2 → 1.0.3

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.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  = ActiveFulfillment CHANGELOG
2
2
 
3
+ == Version 1.0.3 (Jan 21, 2010)
4
+
5
+ * Include "pending" counts in stock levels for Shipwire [wisq]
6
+ * Add option to include pending stock in Shipwire inventory calculations [jessehk]
7
+
3
8
  == Version 1.0.2 (Jan 12, 2010)
4
9
 
5
10
  * Include "pending" counts in stock levels for Shipwire [wisq]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_fulfillment}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cody Fauser", "James MacAulay"]
@@ -3,6 +3,7 @@ require 'cgi'
3
3
  module ActiveMerchant
4
4
  module Fulfillment
5
5
  class ShipwireService < Service
6
+
6
7
  SERVICE_URLS = { :fulfillment => 'https://api.shipwire.com/exec/FulfillmentServices.php',
7
8
  :inventory => 'https://api.shipwire.com/exec/InventoryServices.php',
8
9
  :tracking => 'https://api.shipwire.com/exec/TrackingServices.php'
@@ -67,6 +68,10 @@ module ActiveMerchant
67
68
  true
68
69
  end
69
70
 
71
+ def include_pending_stock?
72
+ @options[:include_pending_stock]
73
+ end
74
+
70
75
  private
71
76
  def build_fulfillment_request(order_id, shipping_address, line_items, options)
72
77
  xml = Builder::XmlMarkup.new :indent => 2
@@ -196,7 +201,10 @@ module ActiveMerchant
196
201
  document = REXML::Document.new(xml)
197
202
  document.root.elements.each do |node|
198
203
  if node.name == 'Product'
199
- amount = ['quantity', 'pending'].map { |a| node.attributes[a].to_i }.sum
204
+ to_check = ['quantity']
205
+ to_check << 'pending' if include_pending_stock?
206
+
207
+ amount = to_check.sum { |a| node.attributes[a].to_i }
200
208
  response[:stock_levels][node.attributes['code']] = amount
201
209
  else
202
210
  response[node.name.underscore.to_sym] = node.text
@@ -60,12 +60,28 @@ class ShipwireTest < Test::Unit::TestCase
60
60
  assert_equal 'US', country_node.text
61
61
  end
62
62
 
63
- def test_stock_levels
63
+ def test_stock_levels_dont_include_pending_by_default
64
64
  @shipwire.expects(:ssl_post).returns(xml_fixture('shipwire/inventory_get_response'))
65
65
 
66
66
  response = @shipwire.fetch_stock_levels
67
67
  assert response.success?
68
68
  assert_equal 926, response.stock_levels['BlackDog']
69
+ assert_equal -1, response.stock_levels['MoustacheCat']
70
+ assert_equal 677, response.stock_levels['KingMonkey']
71
+ end
72
+
73
+ def test_stock_levels_include_pending_when_set
74
+ @shipwire = ShipwireService.new(
75
+ :login => 'cody@example.com',
76
+ :password => 'test',
77
+ :include_pending_stock => true
78
+ )
79
+ @shipwire.expects(:ssl_post).returns(xml_fixture('shipwire/inventory_get_response'))
80
+
81
+ response = @shipwire.fetch_stock_levels
82
+ assert response.success?
83
+ assert @shipwire.include_pending_stock?
84
+ assert_equal 926, response.stock_levels['BlackDog']
69
85
  assert_equal 805, response.stock_levels['MoustacheCat']
70
86
  assert_equal 921, response.stock_levels['KingMonkey']
71
87
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fulfillment
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cody Fauser