dear_inventory 0.7.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +15 -0
  4. data/README.md +71 -18
  5. data/dear_inventory.gemspec +1 -1
  6. data/docs/resources/advanced_purchase.md +25 -0
  7. data/docs/resources/customer.md +31 -0
  8. data/docs/resources/product.md +37 -0
  9. data/docs/resources/product_availability.md +33 -0
  10. data/docs/resources/purchase.md +89 -0
  11. data/docs/resources/sale.md +89 -0
  12. data/lib/dear_inventory.rb +26 -8
  13. data/lib/dear_inventory/config.rb +17 -6
  14. data/lib/dear_inventory/errors/api_limit.rb +6 -0
  15. data/lib/dear_inventory/errors/no_more_pages.rb +6 -0
  16. data/lib/dear_inventory/lib/endpoint_class.rb +1 -1
  17. data/lib/dear_inventory/lib/request.rb +45 -8
  18. data/lib/dear_inventory/lib/strings/urlize.rb +18 -0
  19. data/lib/dear_inventory/model.rb +33 -9
  20. data/lib/dear_inventory/models/advanced_purchase.rb +176 -0
  21. data/lib/dear_inventory/models/customer.rb +2 -2
  22. data/lib/dear_inventory/models/customers.rb +2 -2
  23. data/lib/dear_inventory/models/product_availability.rb +61 -0
  24. data/lib/dear_inventory/models/product_availability_results.rb +26 -0
  25. data/lib/dear_inventory/models/products.rb +1 -1
  26. data/lib/dear_inventory/models/{purchase_list.rb → purchases.rb} +12 -2
  27. data/lib/dear_inventory/models/purchases/additional_charge.rb +1 -1
  28. data/lib/dear_inventory/models/purchases/advanced/credit_note.rb +21 -0
  29. data/lib/dear_inventory/models/purchases/advanced/invoice.rb +68 -0
  30. data/lib/dear_inventory/models/purchases/advanced/manual_journal.rb +21 -0
  31. data/lib/dear_inventory/models/purchases/advanced/put_away.rb +34 -0
  32. data/lib/dear_inventory/models/purchases/advanced/put_away_line.rb +21 -0
  33. data/lib/dear_inventory/models/purchases/advanced/stock.rb +30 -0
  34. data/lib/dear_inventory/models/purchases/advanced/stock_line.rb +61 -0
  35. data/lib/dear_inventory/models/purchases/credit_note.rb +1 -1
  36. data/lib/dear_inventory/models/purchases/inventory_movement.rb +1 -1
  37. data/lib/dear_inventory/models/purchases/invoice.rb +1 -1
  38. data/lib/dear_inventory/models/purchases/invoice_additional_charge.rb +1 -1
  39. data/lib/dear_inventory/models/purchases/invoice_line.rb +1 -1
  40. data/lib/dear_inventory/models/purchases/line.rb +1 -1
  41. data/lib/dear_inventory/models/purchases/manual_journal.rb +1 -1
  42. data/lib/dear_inventory/models/purchases/manual_journal_line.rb +1 -1
  43. data/lib/dear_inventory/models/purchases/order.rb +1 -1
  44. data/lib/dear_inventory/models/purchases/payment_line.rb +51 -0
  45. data/lib/dear_inventory/models/purchases/stock.rb +1 -1
  46. data/lib/dear_inventory/models/purchases/stock_line.rb +1 -1
  47. data/lib/dear_inventory/models/purchases/unstock_line.rb +1 -1
  48. data/lib/dear_inventory/models/{purchase_lists.rb → purchases_results.rb} +4 -4
  49. data/lib/dear_inventory/models/{sale_list.rb → sales.rb} +7 -2
  50. data/lib/dear_inventory/models/sales/additional_charge.rb +1 -1
  51. data/lib/dear_inventory/models/sales/credit_note.rb +1 -1
  52. data/lib/dear_inventory/models/sales/fulfilment.rb +1 -1
  53. data/lib/dear_inventory/models/sales/fulfilments/pick_pack.rb +1 -1
  54. data/lib/dear_inventory/models/sales/fulfilments/pick_pack_line.rb +1 -1
  55. data/lib/dear_inventory/models/sales/fulfilments/ship.rb +1 -1
  56. data/lib/dear_inventory/models/sales/fulfilments/ship_line.rb +1 -1
  57. data/lib/dear_inventory/models/sales/invoice.rb +1 -1
  58. data/lib/dear_inventory/models/sales/invoice_additional_charge.rb +1 -1
  59. data/lib/dear_inventory/models/sales/invoice_line.rb +1 -1
  60. data/lib/dear_inventory/models/sales/line.rb +1 -1
  61. data/lib/dear_inventory/models/sales/manual_journal.rb +1 -1
  62. data/lib/dear_inventory/models/sales/manual_journal_line.rb +1 -1
  63. data/lib/dear_inventory/models/sales/order.rb +1 -1
  64. data/lib/dear_inventory/models/sales/payment_line.rb +1 -1
  65. data/lib/dear_inventory/models/sales/quote.rb +1 -1
  66. data/lib/dear_inventory/models/{sale_lists.rb → sales_results.rb} +4 -4
  67. data/lib/dear_inventory/models/test_request.rb +31 -0
  68. data/lib/dear_inventory/parameters/advanced_purchase/show.rb +25 -0
  69. data/lib/dear_inventory/parameters/product_availability/index.rb +55 -0
  70. data/lib/dear_inventory/parameters/purchase/index.rb +65 -6
  71. data/lib/dear_inventory/parameters/purchase/show.rb +25 -0
  72. data/lib/dear_inventory/parameters/sale/index.rb +95 -11
  73. data/lib/dear_inventory/parameters/sale/show.rb +35 -0
  74. data/lib/dear_inventory/resource.rb +8 -11
  75. data/lib/dear_inventory/resources/{purchase_list.rb → advanced_purchase.rb} +8 -5
  76. data/lib/dear_inventory/resources/customer.rb +2 -0
  77. data/lib/dear_inventory/resources/product.rb +2 -0
  78. data/lib/dear_inventory/resources/product_availability.rb +35 -0
  79. data/lib/dear_inventory/resources/purchase.rb +38 -2
  80. data/lib/dear_inventory/resources/sale.rb +38 -2
  81. data/lib/dear_inventory/response.rb +124 -17
  82. data/lib/dear_inventory/test_response.rb +44 -0
  83. data/lib/dear_inventory/validators/required.rb +11 -1
  84. data/lib/dear_inventory/version.rb +1 -1
  85. data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -4
  86. metadata +36 -12
  87. data/lib/dear_inventory/parameters/purchase_list/index.rb +0 -84
  88. data/lib/dear_inventory/parameters/sale_list/index.rb +0 -119
  89. data/lib/dear_inventory/resources/sale_list.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5895d4865f28593d657fa3f81db31ef6a5c603c17506bf1d9cf4d60d91a46e9a
4
- data.tar.gz: 432a24c5782d4a443cff9cfe64e5a6bc36173c04217a955fc1fc7e15c64ff8b1
3
+ metadata.gz: 5d2cff2061b63178640316ee94c2d2f755e00f6840c9c95254eff1da695dfdfe
4
+ data.tar.gz: da3f9d8d7bae5cb2626e69c17a26ed4eec5c3684246a84857ecbfbc8c0ee1d05
5
5
  SHA512:
6
- metadata.gz: b2be69cf126868c39d7b4c25d1bdcf51b6300aad35448e16202ff7f51ac92122cf8dd0f13ca88508e21d5e3a0664646d6f13a9e6d81978793277b4a42b40c124
7
- data.tar.gz: 19e17ae0e9c65277e13068a46b6440a8f67c53d37362605336d1f6c0041d721c1487ff69971aa4ee4e888056a5a6172619402bc513fee48d5906d4ffae482566
6
+ metadata.gz: 6b0c98e95c9674ed1f3179a6f95f955b9dfd27456fb708e703f01e421e6c6be18290a630e7be574a5d30befe92f7ac23af2090572b48aba6b7cd48b2e1bb11a8
7
+ data.tar.gz: b5602ee55a9dd359de1ddd8de3e5185ccf85283a53de760bfa78b60b3d6e5febbdd57a8dd4a8b048d76f3d8d10ca22de8620fe87066d8d6bda6403e5941a0d22
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  .rspec_status
14
14
  /spec/reports/
15
15
  /spec/examples.txt
16
+ /spec/vcr_cassettes
@@ -30,6 +30,12 @@ Lint/AmbiguousBlockAssociation:
30
30
  Exclude:
31
31
  - spec/**/*
32
32
 
33
+ Lint/RaiseException:
34
+ Enabled: true
35
+
36
+ Lint/StructNewOverride:
37
+ Enabled: true
38
+
33
39
  Metrics/BlockLength:
34
40
  Exclude:
35
41
  - dear_inventory.gemspec
@@ -64,6 +70,15 @@ Style/Documentation:
64
70
  Style/GuardClause:
65
71
  Enabled: false
66
72
 
73
+ Style/HashEachMethods:
74
+ Enabled: true
75
+
76
+ Style/HashTransformKeys:
77
+ Enabled: true
78
+
79
+ Style/HashTransformValues:
80
+ Enabled: true
81
+
67
82
  Style/LambdaCall:
68
83
  Enabled: false
69
84
 
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # DearInventory
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dear_inventory`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A Ruby API client for connecting to DEAR Inventory. At this point, I have only been implementing the GET requests based upon our business needs but, if you like the look of this gem but require a missing endpoint, it would be quite easy to bolt on POST/PUT/Delete endpoints.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Honestly, the DEAR API is a mess. Where possible, this gem attempts to hide the rampant inconsistencies and provide continuity but I'm afraid I'm no magician.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,10 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## N.B for Ruby 2.7
24
24
 
25
- At time of writing, the Sorbet team has not yet accepted my pull request to fix
26
- deprecation warnings due to the use of the single splat operator. It can be
27
- quite frustrating to have your console flooded with warnings and so it may be
28
- worth your while specifying my fork of sorbet-runtime in your project's Gemfile:
25
+ At time of writing, the Sorbet team has not yet accepted my pull request to fix deprecation warnings due to the use of the single splat operator. It can be quite frustrating to have your console flooded with warnings and so it may be worth your while specifying my fork of sorbet-runtime in your project's Gemfile:
29
26
  ```
30
27
  gem "sorbet-runtime",
31
28
  git: "https://github.com/HashNotAdam/sorbet.git",
@@ -33,10 +30,9 @@ gem "sorbet-runtime",
33
30
  glob: "gems/sorbet-runtime/sorbet-runtime.gemspec"
34
31
  ```
35
32
 
36
- ## Usage
33
+ ## Configuration
37
34
 
38
- Before you begin, you will need to setup API credentials in DEAR Inventory at
39
- https://inventory.dearsystems.com/ExternalApi
35
+ Before you begin, you will need to setup API credentials in DEAR Inventory at https://inventory.dearsystems.com/ExternalApi
40
36
 
41
37
  Next you need to supply your API credentials:
42
38
  ```ruby
@@ -48,18 +44,76 @@ DearInventory.configure do |config|
48
44
  end
49
45
  ```
50
46
 
47
+ There is a default logger set to write to STDOUT which is also configurable
48
+
49
+ ```ruby
50
+ DearInventory.configure do |config|
51
+ ...
52
+ config.logger = CustomLogger.new
53
+ end
54
+ ```
55
+
56
+ ## Endpoints
57
+
58
+ - [Customer](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/customer.md)
59
+ - [Product](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/product.md)
60
+ - [Product Availability](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/product_availability.md)
61
+ - [Purchase](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/purchase.md)
62
+ - [Advanced Purchase](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/advanced_purchase.md)
63
+ - [Sale](https://github.com/HashNotAdam/dear_inventory-ruby/blob/master/docs/resources/sale.md)
64
+
65
+ ## Managing pagination
66
+
67
+ The response object for any endpoint that returns a paginated result set will include helper methods for retrieving the results.
68
+
69
+ ### each
70
+
71
+ `each` iterates over all the records as if they were not paginated, automatically retrieving subsequent pages.
72
+
73
+ ```ruby
74
+ DearInventory::Customer.().each do |record|
75
+ do_some_things(record)
76
+ end
77
+ ```
78
+
79
+ ### next_page
80
+
81
+ If you would like control over the pagination process, the paginated responses include a `next_page` method
82
+
83
+ ```ruby
84
+ response = DearInventory::Customer.()
85
+
86
+ loop do
87
+ do_some_things(response)
88
+ break unless response.next_page?
89
+ response = response.next_page
90
+ end
91
+ ```
92
+
93
+ ## Exceptions
94
+
95
+ Exceptions that occur while making a request to DEAR Inventory should be a subclass of DearInventory::RequestError. These errors include the DearInventory::Response instance which provides some flexibility in your error reporting.
96
+
97
+ ```ruby
98
+ def find_a_sale
99
+ DearInventory::Sale.(id: "incorrect")
100
+ rescue DearInventory::RequestError => e
101
+ message = [
102
+ e.message,
103
+ "URI: #{e.response.request.uri}",
104
+ "Params: #{e.response.request.params.to_h}"
105
+ ]
106
+ ErrorMonitoring.error(message.join("\n"))
107
+ end
108
+ ```
109
+
51
110
  ## Development
52
111
 
53
112
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
113
 
55
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push
56
- git commits and tags, and push the `.gem` file to
57
- [rubygems.org](https://rubygems.org).
114
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
115
 
59
- Since it is necessary to authenticate with DEAR Inventory to test API resources,
60
- credentials are required. The dotenv gem is loaded when tests are run and will
61
- look for a .env file in the root directory. A .env.example file has been
62
- supplied so you copy it to .env and replace the example values:
116
+ Since it is necessary to authenticate with DEAR Inventory to test API resources, credentials are required. The dotenv gem is loaded when tests are run and will look for a .env file in the root directory. A .env.example file has been supplied so you copy it to .env and replace the example values:
63
117
 
64
118
  ```sh
65
119
  cp .env.example .env
@@ -67,8 +121,7 @@ cp .env.example .env
67
121
 
68
122
  ## Contributing
69
123
 
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/HashNotAdam/dear_inventory. This project is intended to be a safe, welcoming
71
- space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/HashNotAdam/dear_inventory. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
125
 
73
126
  ## License
74
127
 
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "sorbet-runtime"
33
33
 
34
34
  spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "byebug"
35
36
  spec.add_development_dependency "dotenv"
36
- spec.add_development_dependency "pry-byebug"
37
37
  spec.add_development_dependency "rake", ">= 12.3.3"
38
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
39
  spec.add_development_dependency "rubocop", "~> 0.71"
@@ -0,0 +1,25 @@
1
+ # AdvancedPurchase resource
2
+
3
+ ## Show GET
4
+
5
+ ```ruby
6
+ DearInventory::AdvancedPurchase.show
7
+ ```
8
+
9
+ ### Parameters
10
+
11
+ | Name | Type | Required |
12
+ | --- | --- | --- |
13
+ | id | String | true |
14
+ | combine_additional_charges | Boolean | false |
15
+
16
+ ### Response
17
+
18
+ To see what data is available in the response, you can call the `field` method:
19
+
20
+ ```ruby
21
+ response = DearInventory::AdvancedPurchase.show(id: "abcdef01-2345-6789-abcd-ef0123456789")
22
+ response.fields # [:id, :supplier_id, :supplier, :contact, :phone, :inventory_account, :blind_receipt, :approach, :billing_address, :shipping_address, :base_currency, :supplier_currency, :tax_rule, :tax_calculation, :terms, :required_by, :location, :note, :order_number, :order_date, :combined_receiving_status, :combined_invoice_status, :combined_payment_status, :type, :is_service_only, :status, :related_drop_ship_sale_task, :currency_rate, :last_updated_date, :order, :stock_received, :put_away, :invoice, :credit_note, :manual_journals, :additional_attributes, :attachments, :inventory_movements]
23
+ id = response.id # abcdef01-2345-6789-abcd-ef0123456789
24
+ ```
25
+
@@ -0,0 +1,31 @@
1
+ # Customer resource
2
+
3
+ ## GET
4
+
5
+ ```ruby
6
+ DearInventory::Customer.index
7
+ DearInventory::Customer.()
8
+ ```
9
+
10
+ ### Parameters
11
+ | Name | Type | Required |
12
+ | --- | --- | --- |
13
+ | id | String | false |
14
+ | page | Integer | false |
15
+ | limit | Integer | false |
16
+ | name | String | false |
17
+ | modified_since | DateTime | false |
18
+ | include_deprecated | Boolean | false |
19
+
20
+ ### Response
21
+
22
+ The index endpoint returns a paginated set of records.
23
+
24
+ To see what data is available in the response, you can call the `field` method:
25
+
26
+ ```ruby
27
+ response = DearInventory::Customer.()
28
+ response.fields # [:records, :total, :page, :sale_list]
29
+ records = response.records
30
+ ```
31
+
@@ -0,0 +1,37 @@
1
+ # Product resource
2
+
3
+ ## GET
4
+
5
+ ```ruby
6
+ DearInventory::Product.index
7
+ DearInventory::Product.()
8
+ ```
9
+
10
+ ### Parameters
11
+ | Name | Type | Required |
12
+ | --- | --- | --- |
13
+ | id | String | false |
14
+ | page | Integer | false |
15
+ | limit | Integer | false |
16
+ | name | String | false |
17
+ | sku | String | false |
18
+ | modified_since | DateTime | false |
19
+ | include_attachments | Boolean | false |
20
+ | include_bom | Boolean | false |
21
+ | include_deprecated | Boolean | false |
22
+ | include_movements | Boolean | false |
23
+ | include_reorder_levels | Boolean | false |
24
+ | include_suppliers | Boolean | false |
25
+
26
+ ### Response
27
+
28
+ The index endpoint returns a paginated set of records.
29
+
30
+ To see what data is available in the response, you can call the `field` method:
31
+
32
+ ```ruby
33
+ response = DearInventory::Product.()
34
+ response.fields # [:records, :total, :page, :products]
35
+ records = response.records
36
+ ```
37
+
@@ -0,0 +1,33 @@
1
+ # Product resource
2
+
3
+ ## GET
4
+
5
+ ```ruby
6
+ DearInventory::ProductAvailability.index
7
+ DearInventory::ProductAvailability.()
8
+ ```
9
+
10
+ ### Parameters
11
+ | Name | Type | Required |
12
+ | --- | --- | --- |
13
+ | id | String | false |
14
+ | page | Integer | false |
15
+ | limit | Integer | false |
16
+ | name | String | false |
17
+ | sku | String | false |
18
+ | location | String | false |
19
+ | batch | String | false |
20
+ | category | String | false |
21
+
22
+ ### Response
23
+
24
+ The index endpoint returns a paginated set of records.
25
+
26
+ To see what data is available in the response, you can call the `field` method:
27
+
28
+ ```ruby
29
+ response = DearInventory::ProductAvailability.()
30
+ response.fields # [:records, :total, :page, :product_availabilities]
31
+ records = response.records
32
+ ```
33
+
@@ -0,0 +1,89 @@
1
+ # Purchase resource
2
+
3
+ ## Index GET
4
+
5
+ ```ruby
6
+ DearInventory::Purchase.index
7
+ DearInventory::Purchase.()
8
+ ```
9
+
10
+ ### Parameters
11
+
12
+ | Name | Type | Required |
13
+ | ----------------------- | -------- | -------- |
14
+ | page | Integer | false |
15
+ | limit | Integer | false |
16
+ | search | String | false |
17
+ | required_by | DateTime | false |
18
+ | updated_since | DateTime | false |
19
+ | order_status | String | false |
20
+ | restock_received_status | String | false |
21
+ | invoice_status | String | false |
22
+ | credit_note_status | String | false |
23
+ | unstock_status | String | false |
24
+ | status | String | false |
25
+ | drop_ship_task_id | String | false |
26
+
27
+ ### Response
28
+
29
+ The index endpoint returns a paginated set of purchase summary records. If you would like to load the full purchase, you can either use the helper method, `full_record`, or call the appropriate resource directly, keeping in mind that Simple and Advanced/Service purchases have different resources... because DEAR :shrug:
30
+
31
+ ```ruby
32
+ DearInventory::Purchase.().records.each do |purchase_summary|
33
+ purchase = purchase_summary.full_record
34
+ end
35
+ ```
36
+
37
+ ```ruby
38
+ DearInventory::Purchase.().records.each do |purchase_summary|
39
+ purchase =
40
+ case purchase_summary.type
41
+ when "Advanced Purchase", "Service Purchase"
42
+ DearInventory::AdvancedPurchase.show(id: purchase_summary.id)
43
+ else
44
+ DearInventory::Purchase.show(id: purchase_summary.id)
45
+ end
46
+ end
47
+ ```
48
+
49
+ If you use the `each` helper method, it will automatically return the full record each time. Given it makes n+1 API requests, the time per iteration will be a lot slower than iterating over `records` directly, however, it's much nicer if you intend to load every record anway.
50
+
51
+ ```ruby
52
+ DearInventory::Purchase.().each do |purchase|
53
+ so_stuff_with_the_full_purchase_record(purchase)
54
+ end
55
+ ```
56
+
57
+ To see what data is available in the response, you can call the `field` method:
58
+
59
+ ```ruby
60
+ response = DearInventory::Purchase.()
61
+ response.fields # [:records, :total, :page, :purchases]
62
+ records = response.records
63
+ ```
64
+
65
+
66
+
67
+ ## Show GET
68
+
69
+ ```ruby
70
+ DearInventory::Purchase.show
71
+ ```
72
+
73
+ ### Parameters
74
+
75
+ | Name | Type | Required |
76
+ | --- | --- | --- |
77
+ | id | String | true |
78
+ | combine_additional_charges | Boolean | false |
79
+
80
+ ### Response
81
+
82
+ To see what data is available in the response, you can call the `field` method:
83
+
84
+ ```ruby
85
+ response = DearInventory::Purchase.show(id: "abcdef01-2345-6789-abcd-ef0123456789")
86
+ response.fields # [:id, :supplier_id, :supplier, :contact, :phone, :inventory_account, :blind_receipt, :approach, :billing_address, :shipping_address, :base_currency, :supplier_currency, :tax_rule, :tax_calculation, :terms, :required_by, :location, :note, :order_number, :order_date, :status, :related_drop_ship_sale_task, :currency_rate, :last_updated_date, :order, :stock_received, :invoice, :credit_note, :manual_journals, :additional_attributes, :attachments, :inventory_movements]
87
+ id = response.id # abcdef01-2345-6789-abcd-ef0123456789
88
+ ```
89
+
@@ -0,0 +1,89 @@
1
+ # Sale resource
2
+
3
+ ## Index GET
4
+
5
+ ```ruby
6
+ DearInventory::Sale.index
7
+ DearInventory::Sale.()
8
+ ```
9
+
10
+ ### Parameters
11
+
12
+ | Name | Type | Required |
13
+ | ----------------------- | -------- | -------- |
14
+ | page | Integer | false |
15
+ | limit | Integer | false |
16
+ | search | String | false |
17
+ | created_since | DateTime | false |
18
+ | updated_since | DateTime | false |
19
+ | ship_by | DateTime | false |
20
+ | quote_status | String | false |
21
+ | order_status | String | false |
22
+ | combined_invoice_status | String | false |
23
+ | combined_pick_status | String | false |
24
+ | combined_pack_status | String | false |
25
+ | combined_shipp_status | String | false |
26
+ | credit_note_status | String | false |
27
+ | external_id | String | false |
28
+ | status | String | false |
29
+ | ready_for_shipping | Boolean | false |
30
+
31
+ ### Response
32
+
33
+ The index endpoint returns a paginated set of sale summary records. If you would like to load the full purchase, you can either use the helper method, `full_record`, or call `DearInventory::Sale.show` resource.
34
+
35
+ ```ruby
36
+ DearInventory::Sale.().records.each do |sale_summary|
37
+ sale = sale_summary.full_record
38
+ end
39
+ ```
40
+
41
+ ```ruby
42
+ DearInventory::Sale.().records.each do |sale_summary|
43
+ sale = DearInventory::Sale.show(id: sale_summary.id)
44
+ end
45
+ ```
46
+
47
+ If you use the `each` helper method, it will automatically return the full record each time. Given it makes n+1 API requests, the time per iteration will be a lot slower than iterating over `records` directly, however, it's much nicer if you intend to load every record anway.
48
+
49
+ ```ruby
50
+ DearInventory::Sale.().each do |sale|
51
+ so_stuff_with_the_full_sale_record(sale)
52
+ end
53
+ ```
54
+
55
+ To see what data is available in the response, you can call the `field` method:
56
+
57
+ ```ruby
58
+ response = DearInventory::Sale.()
59
+ response.fields # [:records, :total, :page, :sales]
60
+ records = response.records
61
+ ```
62
+
63
+
64
+
65
+ ## Show GET
66
+
67
+ ```ruby
68
+ DearInventory::Sale.show
69
+ ```
70
+
71
+ ### Parameters
72
+
73
+ | Name | Type | Required |
74
+ | --- | --- | --- |
75
+ | id | String | true |
76
+ | combine_additional_charges | Boolean | false |
77
+ | hide_inventory_movements | Boolean | false |
78
+ | include_transactions | Boolean | false |
79
+
80
+ ### Response
81
+
82
+ To see what data is available in the response, you can call the `field` method:
83
+
84
+ ```ruby
85
+ response = DearInventory::Sale.show(id: "abcdef01-2345-6789-abcd-ef0123456789")
86
+ response.fields # [:id, :customer, :customer_id, :contact, :phone, :email, :default_account, :skip_quote, :billing_address, :shipping_address, :base_currency, :customer_currency, :tax_rule, :tax_calculation, :terms, :price_tier, :ship_by, :location, :sale_order_date, :last_modified_on, :note, :customer_reference, :cogs_amount, :status, :combined_picking_status, :combined_packing_status, :combined_shipping_status, :fulfilment_status, :combined_invoice_status, :combined_payment_status, :combined_tracking_numbers, :carrier, :currency_rate, :sales_representative, :type, :source_channel, :external_id, :service_only, :quote, :order, :fulfilments, :invoices, :credit_notes, :manual_journals, :additional_attributes, :attachments, :inventory_movements, :transactions]
87
+ id = response.id # abcdef01-2345-6789-abcd-ef0123456789
88
+ ```
89
+