fortnox-api 0.1.0 → 0.2.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.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +3 -2
  3. data/.env.test +3 -0
  4. data/.rubocop.yml +32 -23
  5. data/.travis.yml +3 -2
  6. data/Guardfile +2 -2
  7. data/LICENSE.txt +165 -22
  8. data/README.md +56 -37
  9. data/fortnox-api.gemspec +9 -6
  10. data/lib/fortnox/api.rb +18 -2
  11. data/lib/fortnox/api/base.rb +5 -3
  12. data/lib/fortnox/api/environment_validation.rb +51 -6
  13. data/lib/fortnox/api/mappers.rb +49 -0
  14. data/lib/fortnox/api/mappers/base.rb +47 -0
  15. data/lib/fortnox/api/mappers/base/from_json.rb +78 -0
  16. data/lib/fortnox/api/mappers/base/to_json.rb +65 -0
  17. data/lib/fortnox/api/mappers/customer.rb +27 -0
  18. data/lib/fortnox/api/mappers/default_delivery_types.rb +13 -0
  19. data/lib/fortnox/api/mappers/default_templates.rb +15 -0
  20. data/lib/fortnox/api/mappers/edi_information.rb +22 -0
  21. data/lib/fortnox/api/mappers/email_information.rb +18 -0
  22. data/lib/fortnox/api/mappers/invoice.rb +27 -0
  23. data/lib/fortnox/api/mappers/invoice_row.rb +20 -0
  24. data/lib/fortnox/api/mappers/order.rb +23 -0
  25. data/lib/fortnox/api/mappers/order_row.rb +16 -0
  26. data/lib/fortnox/api/models.rb +2 -0
  27. data/lib/fortnox/api/models/base.rb +56 -13
  28. data/lib/fortnox/api/models/customer.rb +112 -101
  29. data/lib/fortnox/api/models/document_base.rb +189 -0
  30. data/lib/fortnox/api/models/invoice.rb +29 -195
  31. data/lib/fortnox/api/models/label.rb +17 -0
  32. data/lib/fortnox/api/models/order.rb +27 -0
  33. data/lib/fortnox/api/repositories.rb +2 -0
  34. data/lib/fortnox/api/repositories/base.rb +4 -5
  35. data/lib/fortnox/api/repositories/base/loaders.rb +22 -14
  36. data/lib/fortnox/api/repositories/base/savers.rb +30 -16
  37. data/lib/fortnox/api/repositories/customer.rb +3 -25
  38. data/lib/fortnox/api/repositories/invoice.rb +3 -22
  39. data/lib/fortnox/api/repositories/order.rb +16 -0
  40. data/lib/fortnox/api/request_handling.rb +3 -3
  41. data/lib/fortnox/api/types.rb +44 -0
  42. data/lib/fortnox/api/types/default_delivery_types.rb +20 -0
  43. data/lib/fortnox/api/types/default_templates.rb +23 -0
  44. data/lib/fortnox/api/types/defaulted.rb +11 -0
  45. data/lib/fortnox/api/types/document_row.rb +65 -0
  46. data/lib/fortnox/api/types/edi_information.rb +29 -0
  47. data/lib/fortnox/api/types/email_information.rb +26 -0
  48. data/lib/fortnox/api/types/enums.rb +75 -0
  49. data/lib/fortnox/api/types/invoice_row.rb +19 -0
  50. data/lib/fortnox/api/types/model.rb +40 -0
  51. data/lib/fortnox/api/types/nullable.rb +21 -0
  52. data/lib/fortnox/api/types/order_row.rb +16 -0
  53. data/lib/fortnox/api/types/required.rb +13 -0
  54. data/lib/fortnox/api/types/sized.rb +25 -0
  55. data/lib/fortnox/api/version.rb +1 -1
  56. data/spec/fortnox/api/base_spec.rb +85 -14
  57. data/spec/fortnox/api/mappers/base/from_json_spec.rb +70 -0
  58. data/spec/fortnox/api/mappers/base/to_json_spec.rb +76 -0
  59. data/spec/fortnox/api/mappers/base_spec.rb +156 -0
  60. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +56 -0
  61. data/spec/fortnox/api/mappers/customer_spec.rb +25 -0
  62. data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +12 -0
  63. data/spec/fortnox/api/mappers/edi_information_spec.rb +21 -0
  64. data/spec/fortnox/api/mappers/email_information_spec.rb +17 -0
  65. data/spec/fortnox/api/mappers/examples/mapper.rb +26 -0
  66. data/spec/fortnox/api/mappers/invoice_row_spec.rb +19 -0
  67. data/spec/fortnox/api/mappers/invoice_spec.rb +24 -0
  68. data/spec/fortnox/api/mappers/order_row_spec.rb +14 -0
  69. data/spec/fortnox/api/mappers/order_spec.rb +20 -0
  70. data/spec/fortnox/api/models/base_spec.rb +44 -22
  71. data/spec/fortnox/api/models/customer_spec.rb +9 -0
  72. data/spec/fortnox/api/models/examples/document_base.rb +13 -0
  73. data/spec/fortnox/api/models/examples/model.rb +13 -0
  74. data/spec/fortnox/api/models/invoice_spec.rb +7 -31
  75. data/spec/fortnox/api/models/order_spec.rb +13 -0
  76. data/spec/fortnox/api/repositories/customer_spec.rb +20 -76
  77. data/spec/fortnox/api/repositories/examples/all.rb +17 -0
  78. data/spec/fortnox/api/repositories/examples/find.rb +25 -0
  79. data/spec/fortnox/api/repositories/examples/only.rb +42 -0
  80. data/spec/fortnox/api/repositories/examples/save.rb +69 -0
  81. data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +32 -0
  82. data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +27 -0
  83. data/spec/fortnox/api/repositories/examples/search.rb +31 -0
  84. data/spec/fortnox/api/repositories/invoice_spec.rb +36 -5
  85. data/spec/fortnox/api/repositories/order_spec.rb +35 -0
  86. data/spec/fortnox/api/types/account_number_spec.rb +28 -0
  87. data/spec/fortnox/api/types/default_delivery_types_spec.rb +10 -0
  88. data/spec/fortnox/api/types/edi_information_spec.rb +13 -0
  89. data/spec/fortnox/api/types/email_information_spec.rb +13 -0
  90. data/spec/fortnox/api/types/email_spec.rb +29 -0
  91. data/spec/fortnox/api/types/enums_spec.rb +13 -0
  92. data/spec/fortnox/api/types/examples/document_row.rb +15 -0
  93. data/spec/fortnox/api/types/examples/enum.rb +48 -0
  94. data/spec/fortnox/api/types/examples/types.rb +9 -0
  95. data/spec/fortnox/api/types/house_work_types_spec.rb +60 -0
  96. data/spec/fortnox/api/types/invoice_row_spec.rb +9 -0
  97. data/spec/fortnox/api/types/model_spec.rb +56 -0
  98. data/spec/fortnox/api/types/nullable_spec.rb +57 -0
  99. data/spec/fortnox/api/types/order_row_spec.rb +13 -0
  100. data/spec/fortnox/api/types/required_spec.rb +42 -0
  101. data/spec/fortnox/api/types/sized_spec.rb +74 -0
  102. data/spec/fortnox/api_spec.rb +16 -15
  103. data/spec/spec_helper.rb +19 -9
  104. data/spec/support/helpers/dummy_class_helper.rb +19 -0
  105. data/spec/support/helpers/environment_helper.rb +7 -0
  106. data/spec/support/helpers/repository_helper.rb +8 -0
  107. data/spec/support/helpers/when_performing_helper.rb +5 -0
  108. data/spec/support/matchers.rb +1 -1
  109. data/spec/support/matchers/type.rb +17 -0
  110. data/spec/support/matchers/type/attribute_matcher.rb +39 -0
  111. data/spec/support/matchers/type/enum_matcher.rb +21 -0
  112. data/spec/support/matchers/type/have_account_number_matcher.rb +21 -0
  113. data/spec/support/matchers/type/have_country_code_matcher.rb +13 -0
  114. data/spec/support/matchers/type/have_currency_matcher.rb +7 -0
  115. data/spec/support/matchers/type/have_customer_type_matcher.rb +13 -0
  116. data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +7 -0
  117. data/spec/support/matchers/type/have_discount_type_matcher.rb +7 -0
  118. data/spec/support/matchers/type/have_email_matcher.rb +22 -0
  119. data/spec/support/matchers/type/have_house_work_type_matcher.rb +7 -0
  120. data/spec/support/matchers/type/have_nullable_date_matcher.rb +58 -0
  121. data/spec/support/matchers/type/have_nullable_matcher.rb +52 -0
  122. data/spec/support/matchers/type/have_nullable_string_matcher.rb +49 -0
  123. data/spec/support/matchers/type/have_sized_float_matcher.rb +8 -0
  124. data/spec/support/matchers/type/have_sized_integer_matcher.rb +8 -0
  125. data/spec/support/matchers/type/have_sized_string_matcher.rb +35 -0
  126. data/spec/support/matchers/type/have_vat_type_matcher.rb +7 -0
  127. data/spec/support/matchers/type/numeric_matcher.rb +50 -0
  128. data/spec/support/matchers/type/require_attribute_matcher.rb +69 -0
  129. data/spec/support/matchers/type/type_matcher.rb +38 -0
  130. data/spec/vcr_cassettes/customers/all.yml +119 -9
  131. data/spec/vcr_cassettes/customers/find_id_1.yml +8 -9
  132. data/spec/vcr_cassettes/customers/find_new.yml +46 -0
  133. data/spec/vcr_cassettes/customers/save_new.yml +9 -11
  134. data/spec/vcr_cassettes/customers/save_old.yml +9 -12
  135. data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +45 -0
  136. data/spec/vcr_cassettes/customers/search_by_name.yml +66 -0
  137. data/spec/vcr_cassettes/customers/search_miss.yml +45 -0
  138. data/spec/vcr_cassettes/invoices/all.yml +104 -0
  139. data/spec/vcr_cassettes/invoices/filter_hit.yml +46 -0
  140. data/spec/vcr_cassettes/invoices/filter_invalid.yml +42 -0
  141. data/spec/vcr_cassettes/invoices/find_id_1.yml +47 -0
  142. data/spec/vcr_cassettes/invoices/find_new.yml +49 -0
  143. data/spec/vcr_cassettes/invoices/save_new.yml +48 -0
  144. data/spec/vcr_cassettes/invoices/save_old.yml +49 -0
  145. data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +47 -0
  146. data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +47 -0
  147. data/spec/vcr_cassettes/invoices/search_by_name.yml +48 -0
  148. data/spec/vcr_cassettes/invoices/search_miss.yml +45 -0
  149. data/spec/vcr_cassettes/orders/all.yml +144 -0
  150. data/spec/vcr_cassettes/orders/filter_hit.yml +48 -0
  151. data/spec/vcr_cassettes/orders/filter_invalid.yml +42 -0
  152. data/spec/vcr_cassettes/orders/find_id_1.yml +48 -0
  153. data/spec/vcr_cassettes/orders/find_new.yml +49 -0
  154. data/spec/vcr_cassettes/orders/house_work_type_babysitting.yml +47 -0
  155. data/spec/vcr_cassettes/orders/house_work_type_cleaning.yml +47 -0
  156. data/spec/vcr_cassettes/orders/house_work_type_construction.yml +47 -0
  157. data/spec/vcr_cassettes/orders/house_work_type_cooking.yml +43 -0
  158. data/spec/vcr_cassettes/orders/house_work_type_electricity.yml +47 -0
  159. data/spec/vcr_cassettes/orders/house_work_type_gardening.yml +47 -0
  160. data/spec/vcr_cassettes/orders/house_work_type_glassmetalwork.yml +47 -0
  161. data/spec/vcr_cassettes/orders/house_work_type_grounddrainagework.yml +47 -0
  162. data/spec/vcr_cassettes/orders/house_work_type_hvac.yml +47 -0
  163. data/spec/vcr_cassettes/orders/house_work_type_masonry.yml +47 -0
  164. data/spec/vcr_cassettes/orders/house_work_type_othercare.yml +47 -0
  165. data/spec/vcr_cassettes/orders/house_work_type_othercosts.yml +47 -0
  166. data/spec/vcr_cassettes/orders/house_work_type_paintingwallpapering.yml +47 -0
  167. data/spec/vcr_cassettes/orders/house_work_type_snowplowing.yml +47 -0
  168. data/spec/vcr_cassettes/orders/house_work_type_textileclothing.yml +47 -0
  169. data/spec/vcr_cassettes/orders/house_work_type_tutoring.yml +43 -0
  170. data/spec/vcr_cassettes/orders/save_new.yml +48 -0
  171. data/spec/vcr_cassettes/orders/save_old.yml +49 -0
  172. data/spec/vcr_cassettes/orders/save_with_nested_model.yml +47 -0
  173. data/spec/vcr_cassettes/orders/search_by_name.yml +47 -0
  174. data/spec/vcr_cassettes/orders/search_miss.yml +45 -0
  175. metadata +301 -71
  176. data/lib/fortnox/api/models/attributes/country_code.rb +0 -17
  177. data/lib/fortnox/api/models/attributes/currency.rb +0 -17
  178. data/lib/fortnox/api/models/edi_information.rb +0 -28
  179. data/lib/fortnox/api/models/email_information.rb +0 -25
  180. data/lib/fortnox/api/models/row.rb +0 -82
  181. data/lib/fortnox/api/repositories/base/json_convertion.rb +0 -68
  182. data/lib/fortnox/api/repositories/base/options.rb +0 -33
  183. data/lib/fortnox/api/validators.rb +0 -1
  184. data/lib/fortnox/api/validators/attributes/country_code.rb +0 -42
  185. data/lib/fortnox/api/validators/attributes/currency.rb +0 -38
  186. data/lib/fortnox/api/validators/base.rb +0 -70
  187. data/lib/fortnox/api/validators/constant.rb +0 -21
  188. data/lib/fortnox/api/validators/customer.rb +0 -29
  189. data/lib/fortnox/api/validators/edi_information.rb +0 -11
  190. data/lib/fortnox/api/validators/email_information.rb +0 -19
  191. data/lib/fortnox/api/validators/invoice.rb +0 -33
  192. data/lib/fortnox/api/validators/row.rb +0 -22
  193. data/spec/fortnox/api/models/attributes/country_code_spec.rb +0 -23
  194. data/spec/fortnox/api/models/attributes/currency_spec.rb +0 -23
  195. data/spec/fortnox/api/models/attributes/dummy_model_context.rb +0 -9
  196. data/spec/fortnox/api/models/row_spec.rb +0 -13
  197. data/spec/fortnox/api/repositories/context.rb +0 -10
  198. data/spec/fortnox/api/repositories/examples.rb +0 -16
  199. data/spec/fortnox/api/validators/attributes/country_code_spec.rb +0 -9
  200. data/spec/fortnox/api/validators/attributes/currency_spec.rb +0 -9
  201. data/spec/fortnox/api/validators/attributes/examples_for_validate.rb +0 -29
  202. data/spec/fortnox/api/validators/base_spec.rb +0 -61
  203. data/spec/fortnox/api/validators/constant_spec.rb +0 -12
  204. data/spec/fortnox/api/validators/context.rb +0 -102
  205. data/spec/fortnox/api/validators/customer_spec.rb +0 -31
  206. data/spec/fortnox/api/validators/edi_information_spec.rb +0 -18
  207. data/spec/fortnox/api/validators/email_information_spec.rb +0 -26
  208. data/spec/fortnox/api/validators/invoice_spec.rb +0 -36
  209. data/spec/fortnox/api/validators/row_spec.rb +0 -27
  210. data/spec/fortnox/api/validators/validator_examples.rb +0 -20
  211. data/spec/support/matchers/models.rb +0 -27
  212. data/spec/support/matchers/validators.rb +0 -36
@@ -0,0 +1,189 @@
1
+ require "fortnox/api/types"
2
+ require "fortnox/api/models/label"
3
+
4
+ module Fortnox
5
+ module API
6
+ module Model
7
+ module DocumentBase
8
+ # Method length is ignored due to readability.
9
+ # rubocop:disable Metrics/MethodLength
10
+ def self.ify( base )
11
+ base.class_eval do
12
+
13
+ # Url Direct url to the record.
14
+ base.attribute :url, Types::Nullable::String.with( read_only: true )
15
+
16
+ # AdministrationFee The document administration fee.
17
+ base.attribute :administration_fee, Types::Nullable::Float
18
+
19
+ # AdministrationFeeVAT VAT of the document administration fee.
20
+ base.attribute :administration_fee_vat, Types::Nullable::Float.with( read_only: true )
21
+
22
+ # Address1 Document address 1. 1024 characters
23
+ base.attribute :address1, Types::Sized::String[ 1024 ]
24
+
25
+ # Address2 Document address 2. 1024 characters
26
+ base.attribute :address2, Types::Sized::String[ 1024 ]
27
+
28
+ # BasisTaxReduction Basis of tax reduction.
29
+ base.attribute :basis_tax_reduction, Types::Nullable::Float.with( read_only: true )
30
+
31
+ # Cancelled If the document is cancelled.
32
+ base.attribute :cancelled, Types::Nullable::Boolean.with( read_only: true )
33
+
34
+ # City City for the document address.
35
+ base.attribute :city, Types::Sized::String[ 1024 ]
36
+
37
+ # Comments Comments of the document
38
+ base.attribute :comments, Types::Sized::String[ 1024 ]
39
+
40
+ # ContributionPercent Document contribution in percent.
41
+ base.attribute :contribution_percent, Types::Nullable::Float.with( read_only: true )
42
+
43
+ # ContributionValue Document contribution in amount.
44
+ base.attribute :contribution_value, Types::Nullable::Float.with( read_only: true )
45
+
46
+ # Country Country for the document address.
47
+ base.attribute :country, Fortnox::API::Types::CountryCode
48
+
49
+ # CostCenter Code of the cost center.
50
+ base.attribute :cost_center, Types::Nullable::String
51
+
52
+ # Currency Code of the currency.
53
+ base.attribute :currency, Fortnox::API::Types::Currency
54
+
55
+ # CurrencyRate Currency rate used for the document
56
+ base.attribute :currency_rate, Types::Nullable::Float
57
+
58
+ # CurrencyUnit Currency unit used for the document
59
+ base.attribute :currency_unit, Types::Nullable::Float
60
+
61
+ # CustomerName Name of the customer. 1024 characters
62
+ base.attribute :customer_name, Types::Sized::String[ 1024 ]
63
+
64
+ # CustomerNumber Customer number of the customer. Required
65
+ base.attribute :customer_number, Types::Required::String
66
+
67
+ # DeliveryAddress1 Document delivery address 1.
68
+ base.attribute :delivery_address1, Types::Sized::String[ 1024 ]
69
+
70
+ # DeliveryAddress2 Document delivery address 2.
71
+ base.attribute :delivery_address2, Types::Sized::String[ 1024 ]
72
+
73
+ # DeliveryCity City for the document delivery address.
74
+ base.attribute :delivery_city, Types::Sized::String[ 1024 ]
75
+
76
+ # DeliveryCountry Country for the document delivery address.
77
+ base.attribute :delivery_country, Fortnox::API::Types::CountryCode
78
+
79
+ # DeliveryDate Date of delivery.
80
+ base.attribute :delivery_date, Types::Nullable::Date
81
+
82
+ # DeliveryName Name of the recipient of the delivery
83
+ base.attribute :delivery_name, Types::Sized::String[ 1024 ]
84
+
85
+ # DeliveryZipCode ZipCode for the document delivery address.
86
+ base.attribute :delivery_zip_code, Types::Sized::String[ 1024 ]
87
+
88
+ # DocumentNumber The document number.
89
+ base.attribute :document_number, Types::Nullable::Integer
90
+
91
+ # EmailInformation Separete EmailInformation object
92
+ base.attribute :email_information, Types::EmailInformation
93
+
94
+ # ExternalInvoiceReference1 External document reference 1. 80 characters
95
+ base.attribute :external_invoice_reference1, Types::Sized::String[ 80 ]
96
+
97
+ # ExternalInvoiceReference2 External document reference 2. 80 characters
98
+ base.attribute :external_invoice_reference2, Types::Sized::String[ 80 ]
99
+
100
+ # Freight Freight cost of the document. 12 digits (incl. decimals)
101
+ base.attribute :freight, Types::Sized::Float[ 0.0, 99_999_999_999.0 ]
102
+
103
+ # FreightVAT VAT of the freight cost.
104
+ base.attribute :freight_vat, Types::Nullable::Float.with( read_only: true )
105
+
106
+ # Gross Gross value of the document
107
+ base.attribute :gross, Types::Nullable::Float.with( read_only: true )
108
+
109
+ # HouseWork If there is any row of the document marked “house work”.
110
+ base.attribute :house_work, Types::Nullable::Boolean.with( read_only: true )
111
+
112
+ base.attribute :labels, Types::Strict::Array.member( Label )
113
+
114
+ # Net Net amount
115
+ base.attribute :net, Types::Nullable::Float.with( read_only: true )
116
+
117
+ # NotCompleted If the document is set as not completed.
118
+ base.attribute :not_completed, Types::Nullable::Boolean
119
+
120
+ # OfferReference Reference to the offer, if one exists.
121
+ base.attribute :offer_reference, Types::Nullable::Integer.with( read_only: true )
122
+
123
+ # OrganisationNumber Organisation number of the customer for the
124
+ # document.
125
+ base.attribute :organisation_number, Types::Nullable::String.with( read_only: true )
126
+
127
+ # OurReference Our reference. 50 characters
128
+ base.attribute :our_reference, Types::Sized::String[ 50 ]
129
+
130
+ # Phone1 Phone number 1 of the customer for the document. 1024 characters
131
+ base.attribute :phone1, Types::Sized::String[ 1024 ]
132
+
133
+ # Phone2 Phone number 2 of the customer for the document. 1024 characters
134
+ base.attribute :phone2, Types::Sized::String[ 1024 ]
135
+
136
+ # PriceList Code of the price list.
137
+ base.attribute :price_list, Types::Nullable::String
138
+
139
+ # PrintTemplate Print template of the document.
140
+ base.attribute :print_template, Types::Nullable::String
141
+
142
+ # Project Code of the project.
143
+ base.attribute :project, Types::Nullable::String
144
+
145
+ # Remarks Remarks of the document. 1024 characters
146
+ base.attribute :remarks, Types::Sized::String[ 1024 ]
147
+
148
+ # RoundOff Round off amount for the document.
149
+ base.attribute :round_off, Types::Nullable::Float.with( read_only: true )
150
+
151
+ # Sent If the document is printed or sent in any way.
152
+ base.attribute :sent, Types::Nullable::Boolean.with( read_only: true )
153
+
154
+ # TaxReduction The amount of tax reduction.
155
+ base.attribute :tax_reduction, Types::Nullable::Integer.with( read_only: true )
156
+
157
+ # TermsOfDelivery Code of the terms of delivery.
158
+ base.attribute :terms_of_delivery, Types::Nullable::String
159
+
160
+ # TermsOfPayment Code of the terms of payment.
161
+ base.attribute :terms_of_payment, Types::Nullable::String
162
+
163
+ # Total The total amount of the document.
164
+ base.attribute :total, Types::Nullable::Float.with( read_only: true )
165
+
166
+ # TotalVAT The total VAT amount of the document.
167
+ base.attribute :total_vat, Types::Nullable::Float.with( read_only: true )
168
+
169
+ # VATIncluded If the price of the document is including VAT.
170
+ base.attribute :vat_included, Types::Nullable::Boolean
171
+
172
+ # WayOfDelivery Code of the way of delivery.
173
+ base.attribute :way_of_delivery, Types::Nullable::String
174
+
175
+ # YourOrderNumber Your order number. 30 characters
176
+ base.attribute :your_order_number, Types::Sized::String[ 30 ]
177
+
178
+ # YourReference Your reference. 50 characters
179
+ base.attribute :your_reference, Types::Sized::String[ 50 ]
180
+
181
+ # ZipCode Zip code of the document. 1024 characters
182
+ base.attribute :zip_code, Types::Sized::String[ 1024 ]
183
+ end
184
+ end
185
+ # rubocop:enable Metrics/MethodLength
186
+ end
187
+ end
188
+ end
189
+ end
@@ -1,252 +1,86 @@
1
1
  require "fortnox/api/models/base"
2
- require "fortnox/api/models/edi_information"
3
- require "fortnox/api/models/email_information"
4
- require "fortnox/api/models/row"
2
+ require "fortnox/api/models/document_base"
5
3
 
6
4
  module Fortnox
7
5
  module API
8
6
  module Model
9
7
  class Invoice < Fortnox::API::Model::Base
8
+ UNIQUE_ID = :document_number
9
+ STUB = { customer_number: '' }.freeze
10
10
 
11
- #Url Direct url to the record.
12
- attribute :url, String, writer: :private
11
+ DocumentBase.ify( self )
13
12
 
14
13
  #UrlTaxReductionList Direct url to the tax reduction for the invoice.
15
- attribute :url_tax_reduction_list, String, writer: :private
14
+ attribute :url_tax_reduction_list, Types::Nullable::String.with( read_only: true )
16
15
 
17
16
  #AccountingMethod Accounting Method.
18
- attribute :accounting_method, String
19
-
20
- #AdministrationFee The invoice administration fee. 12 digits (incl. decimals)
21
- attribute :administration_fee, Float
22
-
23
- #AdministrationFeeVAT VAT of the invoice administration fee.
24
- attribute :administration_fee_vat, Float, writer: :private
25
-
26
- #Address1 Invoice address 1. 1024 characters
27
- attribute :address1, String
28
-
29
- #Address2 Invoice address 2. 1024 characters
30
- attribute :address2, String
17
+ attribute :accounting_method, Types::Nullable::String
31
18
 
32
19
  #Balance Balance of the invoice.
33
- attribute :balance, Float, writer: :private
34
-
35
- #BasisTaxReduction Basis of tax reduction.
36
- attribute :basis_tax_reduction, Float, writer: :private
20
+ attribute :balance, Types::Nullable::Float.with( read_only: true )
37
21
 
38
22
  #Booked If the invoice is bookkept.
39
- attribute :booked, Boolean, writer: :private
40
-
41
- #Cancelled If the invoice is cancelled.
42
- attribute :cancelled, Boolean, writer: :private
23
+ attribute :booked, Types::Nullable::Boolean.with( read_only: true )
43
24
 
44
25
  #Credit If the invoice is a credit invoice.
45
- attribute :credit, Boolean, writer: :private
26
+ attribute :credit, Types::Nullable::Boolean.with( read_only: true )
46
27
 
47
28
  #CreditInvoiceReference Reference to the credit invoice, if one exits.
48
- attribute :credit_invoice_reference, Integer
49
-
50
- #City City for the invoice address.
51
- attribute :city, String
52
-
53
- #Comments Comments of the invoice
54
- attribute :comments, String
29
+ attribute :credit_invoice_reference, Types::Nullable::Integer
55
30
 
56
31
  #ContractReference Reference to the contract, if one exists.
57
- attribute :contract_reference, Integer, writer: :private
58
-
59
- #ContributionPercent Invoice contribution in percent.
60
- attribute :contribution_percent, Float, writer: :private
61
-
62
- #ContributionValue Invoice contribution in amount.
63
- attribute :contribution_value, Float, writer: :private
64
-
65
- #Country Country for the invoice address.
66
- attribute :country, String
67
-
68
- # CostCenter Code of the cost center.
69
- attribute :cost_center, String
70
-
71
- #Currency Code of the currency.
72
- attribute :currency, String
73
-
74
- #CurrencyRate Currency rate used for the invoice. 16 digits
75
- attribute :currency_rate, Float
76
-
77
- #CurrencyUnit Currency unit used for the invoice. 16 digits
78
- attribute :currency_unit, Float
79
-
80
- #CustomerName Name of the customer. 1024 characters
81
- attribute :customer_name, String
82
-
83
- #CustomerNumber Customer number of the customer. Required
84
- attribute :customer_number, String
85
-
86
- #DeliveryAddress1 Invoice delivery address 1.
87
- attribute :delivery_address1, String
88
-
89
- #DeliveryAddress2 Invoice delivery address 2.
90
- attribute :delivery_address2, String
91
-
92
- #DeliveryCity City for the invoice delivery address.
93
- attribute :delivery_city, String
94
-
95
- #DeliveryCountry Country for the invoice delivery address.
96
- attribute :delivery_country, String
97
-
98
- #DeliveryDate Date of delivery.
99
- attribute :delivery_date, Date
100
-
101
- #DeliveryName Name of the recipient of the delivery
102
- attribute :delivery_name, String
103
-
104
- #DeliveryZipCode ZipCode for the invoice delivery address.
105
- attribute :delivery_zip_code, String
106
-
107
- #DocumentNumber The invoice number.
108
- attribute :document_number, Integer
32
+ attribute :contract_reference, Types::Nullable::Integer.with( read_only: true )
109
33
 
110
34
  #DueDate Due date of the invoice.
111
- attribute :due_date, Date
35
+ attribute :due_date, Types::Nullable::Date
112
36
 
113
37
  #EDIInformation Separate EDIInformation object
114
- attribute :edi_information, EDIInformation
115
-
116
- #EmailInformation Separete EmailInformation object
117
- attribute :email_information, EmailInformation
38
+ attribute :edi_information, Types::EDIInformation
118
39
 
119
40
  #EUQuarterlyReport EU Quarterly Report On / Off
120
- attribute :eu_quarterly_report, Boolean
121
-
122
- #ExternalInvoiceReference1 External invoice reference 1. 80 characters
123
- attribute :external_invoice_reference1, String
124
-
125
- #ExternalInvoiceReference2 External invoice reference 2. 80 characters
126
- attribute :external_invoice_reference2, String
127
-
128
- #Freight Freight cost of the invoice. 12 digits (incl. decimals)
129
- attribute :freight, Float
130
-
131
- #FreightVAT VAT of the freight cost.
132
- attribute :freight_vat, Float, writer: :private
133
-
134
- #Gross Gross value of the invoice
135
- attribute :gross, Float, writer: :private
136
-
137
- #HouseWork If there is any row of the invoice marked “house work”.
138
- attribute :house_work, Boolean, writer: :private
41
+ attribute :eu_quarterly_report, Types::Nullable::Boolean
139
42
 
140
43
  #InvoiceDate Invoice date.
141
- attribute :invoice_date, Date
44
+ attribute :invoice_date, Types::Nullable::Date
142
45
 
143
46
  #InvoicePeriodStart Start date of the invoice period.
144
- attribute :invoice_period_start, Date, writer: :private
47
+ attribute :invoice_period_start, Types::Nullable::Date.with( read_only: true )
145
48
 
146
49
  #InvoicePeriodEnd End date of the invoice period.
147
- attribute :invoice_period_end, Date, writer: :private
50
+ attribute :invoice_period_end, Types::Nullable::Date.with( read_only: true )
148
51
 
149
- #InvoiceRows Separate Row object
150
- attribute :invoice_rows, Array[Row]
52
+ #InvoiceRows Separate object
53
+ attribute :invoice_rows, Types::Strict::Array.member( Types::InvoiceRow )
151
54
 
152
55
  #InvoiceType The type of invoice.
153
- attribute :invoice_type, String
56
+ attribute :invoice_type, Types::Nullable::String
154
57
 
155
58
  #Language Language code.
156
- attribute :language, String
59
+ attribute :language, Types::Nullable::String
157
60
 
158
61
  #LastRemindDate Date of last reminder.
159
- attribute :last_remind_date, Date, writer: :private
160
-
161
- #Net Net amount
162
- attribute :net, Float, writer: :private
163
-
164
- #NotCompleted If the invoice is set as not completed.
165
- attribute :not_completed, Boolean
62
+ attribute :last_remind_date, Types::Nullable::Date.with( read_only: true )
166
63
 
167
64
  #NoxFinans If the invoice is managed by NoxFinans
168
- attribute :nox_finans, Boolean, writer: :private
65
+ attribute :nox_finans, Types::Nullable::Boolean.with( read_only: true )
169
66
 
170
67
  #OCR OCR number of the invoice.
171
- attribute :ocr, String
172
-
173
- #OfferReference Reference to the offer, if one exists.
174
- attribute :offer_reference, Integer, writer: :private
68
+ attribute :ocr, Types::Nullable::String
175
69
 
176
70
  #OrderReference Reference to the order, if one exists.
177
- attribute :order_reference, Integer, writer: :private
178
-
179
- #OrganisationNumber Organisation number of the customer for the invoice.
180
- attribute :organisation_number, String, writer: :private
181
-
182
- #OurReference Our reference. 50 characters
183
- attribute :our_reference, String
184
-
185
- #Phone1 Phone number 1 of the customer for the invoice. 1024 characters
186
- attribute :phone1, String
187
-
188
- #Phone2 Phone number 2 of the customer for the invoice. 1024 characters
189
- attribute :phone2, String
190
-
191
- #PriceList Code of the price list.
192
- attribute :price_list, String
193
-
194
- #PrintTemplate Print template of the invoice.
195
- attribute :print_template, String
196
-
197
- #Project Code of the project.
198
- attribute :project, String
199
-
200
- #Remarks Remarks of the invoice. 1024 characters
201
- attribute :remarks, String
71
+ attribute :order_reference, Types::Nullable::Integer.with( read_only: true )
202
72
 
203
73
  #Reminders Number of reminders sent to the customer.
204
- attribute :reminders, Integer, writer: :private
205
-
206
- #RoundOff Round off amount for the invoice.
207
- attribute :round_off, Float, writer: :private
208
-
209
- #Sent If the document is printed or sent in any way.
210
- attribute :sent, Boolean, writer: :private
211
-
212
- #TaxReduction The amount of tax reduction.
213
- attribute :tax_reduction, Integer, writer: :private
214
-
215
- #TermsOfDelivery Code of the terms of delivery.
216
- attribute :terms_of_delivery, String
217
-
218
- #TermsOfPayment Code of the terms of payment.
219
- attribute :terms_of_payment, String
220
-
221
- #Total The total amount of the invoice.
222
- attribute :total, Float, writer: :private
223
-
224
- #TotalVAT The total VAT amount of the invoice.
225
- attribute :total_vat, Float, writer: :private
226
-
227
- #VATIncluded If the price of the invoice is including VAT.
228
- attribute :vat_included, Boolean
74
+ attribute :reminders, Types::Nullable::Integer.with( read_only: true )
229
75
 
230
76
  #VoucherNumber Voucher number for the invoice.
231
- attribute :voucher_number, Integer, writer: :private
77
+ attribute :voucher_number, Types::Nullable::Integer.with( read_only: true )
232
78
 
233
79
  #VoucherSeries Voucher series for the invoice.
234
- attribute :voucher_series, String, writer: :private
80
+ attribute :voucher_series, Types::Nullable::String.with( read_only: true )
235
81
 
236
82
  #VoucherYear Voucher year for the invoice.
237
- attribute :voucher_year, Integer, writer: :private
238
-
239
- #WayOfDelivery Code of the way of delivery.
240
- attribute :way_of_delivery, String
241
-
242
- #YourOrderNumber Your order number. 30 characters
243
- attribute :your_order_number, String
244
-
245
- #YourReference Your reference. 50 characters
246
- attribute :your_reference, String
247
-
248
- #ZipCode Zip code of the invoice. 1024 characters
249
- attribute :zip_code, String
83
+ attribute :voucher_year, Types::Nullable::Integer.with( read_only: true )
250
84
  end
251
85
  end
252
86
  end