Closed ehannes closed 5 years ago
Sverige
is ok:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'Sverige', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
=> #<Fortnox::API::Model::Order url=nil administration_fee=0.0 administration_fee_vat=0.0 address1="" address2="" basis_tax_reduction=0.0 cancelled=false city="" comments="" contribution_percent=0.0 contribution_value=0.0 country="Sverige" cost_center="" currency="SEK" currency_rate=1.0 currency_unit=1.0 customer_name="Old name" customer_number="1" delivery_address1="" delivery_address2="" delivery_city="" delivery_country=nil delivery_date=nil delivery_name="" delivery_zip_code="" document_number=309 email_information=#<Fortnox::API::Types::EmailInformation email_address_to="" email_address_cc=nil email_address_bcc=nil email_subject="Order {no} bifogas" email_body=" "> external_invoice_reference1="" external_invoice_reference2="" freight=0.0 freight_vat=0.0 gross=0.0 housework=false labels=[] net=0.0 not_completed=false offer_reference=0 organisation_number="860101-8735" our_reference="" phone1="" phone2="" price_list="A" print_template="oc" project="" remarks="" round_off=0.0 sent=false tax_reduction=nil terms_of_delivery="" terms_of_payment="0" total=0.0 total_vat=0.0 vat_included=false way_of_delivery="" your_order_number="" your_reference="" zip_code="" copy_remarks=false invoice_reference=0 order_date=#<Date: 2018-03-28 ((2458206j,0s,0n),+0s,2299161j)> order_rows=[#<Fortnox::API::Types::OrderRow account_number=1250 article_number="0000" contribution_percent=0.0 contribution_value=0.0 cost_center="" delivered_quantity=0.0 description="Testartikel" discount=0.0 discount_type="PERCENT" housework=false housework_hours_to_report=nil housework_type=nil price=0.0 project="" total=0.0 unit="" vat=0 ordered_quantity=1.0>]>
Sweden
is not ok:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'Sweden', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
Fortnox::API::RemoteServerError: Ogiltigt land: Sweden
BUT United Kingdom
is ok: :confused:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'United Kingdom', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
=> #<Fortnox::API::Model::Order url=nil administration_fee=0.0 administration_fee_vat=0.0 address1="" address2="" basis_tax_reduction=0.0 cancelled=false city="" comments="" contribution_percent=0.0 contribution_value=0.0 country="United Kingdom" cost_center="" currency="SEK" currency_rate=1.0 currency_unit=1.0 customer_name="Old name" customer_number="1" delivery_address1="" delivery_address2="" delivery_city="" delivery_country=nil delivery_date=nil delivery_name="" delivery_zip_code="" document_number=310 email_information=#<Fortnox::API::Types::EmailInformation email_address_to="" email_address_cc=nil email_address_bcc=nil email_subject="Order {no} bifogas" email_body=" "> external_invoice_reference1="" external_invoice_reference2="" freight=0.0 freight_vat=0.0 gross=0.0 housework=false labels=[] net=0.0 not_completed=false offer_reference=0 organisation_number="860101-8735" our_reference="" phone1="" phone2="" price_list="A" print_template="oc" project="" remarks="" round_off=0.0 sent=false tax_reduction=nil terms_of_delivery="" terms_of_payment="0" total=0.0 total_vat=0.0 vat_included=false way_of_delivery="" your_order_number="" your_reference="" zip_code="" copy_remarks=false invoice_reference=0 order_date=#<Date: 2018-03-28 ((2458206j,0s,0n),+0s,2299161j)> order_rows=[#<Fortnox::API::Types::OrderRow account_number=1250 article_number="0000" contribution_percent=0.0 contribution_value=0.0 cost_center="" delivered_quantity=0.0 description="Testartikel" discount=0.0 discount_type="PERCENT" housework=false housework_hours_to_report=nil housework_type=nil price=0.0 project="" total=0.0 unit="" vat=0 ordered_quantity=1.0>]>
Storbritannien
is ok:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'Storbritannien', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
=> #<Fortnox::API::Model::Order url=nil administration_fee=0.0 administration_fee_vat=0.0 address1="" address2="" basis_tax_reduction=0.0 cancelled=false city="" comments="" contribution_percent=0.0 contribution_value=0.0 country="Storbritannien" cost_center="" currency="SEK" currency_rate=1.0 currency_unit=1.0 customer_name="Old name" customer_number="1" delivery_address1="" delivery_address2="" delivery_city="" delivery_country=nil delivery_date=nil delivery_name="" delivery_zip_code="" document_number=311 email_information=#<Fortnox::API::Types::EmailInformation email_address_to="" email_address_cc=nil email_address_bcc=nil email_subject="Order {no} bifogas" email_body=" "> external_invoice_reference1="" external_invoice_reference2="" freight=0.0 freight_vat=0.0 gross=0.0 housework=false labels=[] net=0.0 not_completed=false offer_reference=0 organisation_number="860101-8735" our_reference="" phone1="" phone2="" price_list="A" print_template="oc" project="" remarks="" round_off=0.0 sent=false tax_reduction=nil terms_of_delivery="" terms_of_payment="0" total=0.0 total_vat=0.0 vat_included=false way_of_delivery="" your_order_number="" your_reference="" zip_code="" copy_remarks=false invoice_reference=0 order_date=#<Date: 2018-03-28 ((2458206j,0s,0n),+0s,2299161j)> order_rows=[#<Fortnox::API::Types::OrderRow account_number=1250 article_number="0000" contribution_percent=0.0 contribution_value=0.0 cost_center="" delivered_quantity=0.0 description="Testartikel" discount=0.0 discount_type="PERCENT" housework=false housework_hours_to_report=nil housework_type=nil price=0.0 project="" total=0.0 unit="" vat=0 ordered_quantity=1.0>]>
But England
is an Ogiltigt land
:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'England', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
Fortnox::API::RemoteServerError: Ogiltigt land: England
Country codes are not supported:
pry(main)> Fortnox::API::Repository::Order.new.save(Fortnox::API::Model::Order.new(customer_number: '1', country: 'SE', order_rows: [Fortnox::API::Types::OrderRow.new(ordered_quantity: 1, article_number: '0000')]))
Fortnox::API::RemoteServerError: Ogiltigt land: SE
In their interface, you can search by country codes, but it's the English or the Swedish name that can be set. (Actually, in their interface, if it's a foreign key, you can only set the English name. If the country is Sweden, you can only set it to Sverige. But if you set the country to Storbritannien
via the API, then you get Storbritannien
in the Fortnox interface as well).
The country that is set is the customer country. I guess the same rules apply to DeliveryCountry
, which is another attribute.
Notice that the implementation for Customer
differs. That model has a country_code
attribute (which uses country codes) and a read only attribute country
which holds the country name set by Fortnox. Why did they not use this implementation in Order
s and Invoice
s?
I asked Fortnox to send me the list list of countries that Fortnox allows. Here it is:
KOD | English | Svenska |
---|---|---|
AF | Afghanistan | Afghanistan |
AL | Albania | Albanien |
DZ | Algeria | Algeriet |
VI | Virgin Islands U.S. | Amerikanska Jungfruöarna |
AS | American Samoa | Amerikanska Samoa |
AD | Andorra | Andorra |
AO | Angola | Angola |
AI | Anguilla | Anguilla |
AQ | Antarctica | Antarktis |
AG | Antigua and Barbuda | Antigua och Barbuda |
AR | Argentina | Argentina |
AM | Armenia | Armenien |
AW | Aruba | Aruba |
AU | Australia | Australien |
AZ | Azerbaijan | Azerbajdzjan |
BS | Bahamas | Bahamas |
BH | Bahrain | Bahrain |
BD | Bangladesh | Bangladesh |
BB | Barbados | Barbados |
BE | Belgium | Belgien |
BZ | Belize | Belize |
BJ | Benin | Benin |
BM | Bermuda | Bermuda |
BT | Bhutan | Bhutan |
BO | Bolivia, Plurinational State of | Bolivia |
BA | Bosnia and Herzegovina | Bosnien och Hercegovina |
BW | Botswana | Botswana |
BV | Bouvet Island | Bouvetön |
BR | Brazil | Brasilien |
VG | Virgin Islands British | Brittiska Jungfruöarna |
IO | British Indian Ocean Territory | Brittiska territoriet i Indiska Oceanen |
BN | Brunei Darussalam | Brunei |
BG | Bulgaria | Bulgarien |
BF | Burkina Faso | Burkina Faso |
MM | Myanmar | Burma |
BI | Burundi | Burundi |
KY | Cayman Islands | Caymanöarna |
CF | Central African Republic | Centralafrikanska republiken |
CL | Chile | Chile |
CO | Colombia | Colombia |
CK | Cook Islands | Cooköarna |
CR | Costa Rica | Costa Rica |
CY | Cyprus | Cypern |
DK | Denmark | Danmark |
CD | Congo, the Democratic Republic of the | Demokratiska republiken Kongo |
DJ | Djibouti | Djibouti |
DM | Dominica | Dominica |
DO | Dominican Republic | Dominikanska republiken |
EC | Ecuador | Ecuador |
EG | Egypt | Egypten |
GQ | Equatorial Guinea | Ekvatorialguinea |
SV | El Salvador | El Salvador |
CI | Côte d'Ivoire | Elfenbenskusten |
ER | Eritrea | Eritrea |
EE | Estonia | Estland |
ET | Ethiopia | Etiopien |
FK | Falkland Islands (Malvinas) | Falklandsöarna |
FJ | Fiji | Fiji |
PH | Philippines | Filippinerna |
FI | Finland | Finland |
FX | France Metropolitan | France métropolitaine (Frankrike europeiska delen) |
FR | France | Frankrike |
GF | French Guiana | Franska Guyana |
PF | French Polynesia | Franska Polynesien |
TF | French Southern Territories | Franska södra territorierna |
FO | Faroe Islands | Färöarna |
AE | United Arab Emirates | Förenade Arabemiraten |
GA | Gabon | Gabon |
GM | Gambia | Gambia |
GE | Georgia | Georgien |
GH | Ghana | Ghana |
GI | Gibraltar | Gibraltar |
GR | Greece | Grekland |
GD | Grenada | Grenada |
GL | Greenland | Grönland |
GP | Guadeloupe | Guadeloupe |
GU | Guam | Guam |
GT | Guatemala | Guatemala |
GG | Guernsey | Guernsey |
GN | Guinea | Guinea |
GW | Guinea-Bissau | Guinea Bissau |
GY | Guyana | Guyana |
HT | Haiti | Haiti |
HM | Heard Island and McDonald Islands | Heard- och McDonaldsöarna |
HN | Honduras | Honduras |
HK | Hong Kong | Hongkong |
IN | India | Indien |
ID | Indonesia | Indonesien |
IQ | Iraq | Irak |
IR | Iran, Islamic Republic of | Iran |
IE | Ireland | Irland |
IS | Iceland | Island |
IM | Isle of Man | Isle of Man |
IL | Israel | Israel |
IT | Italy | Italien |
JM | Jamaica | Jamaica |
JP | Japan | Japan |
YE | Yemen | Jemen |
JE | Jersey | Jersey |
JO | Jordan | Jordanien |
CX | Christmas Island | Julön |
KH | Cambodia | Kambodja |
CM | Cameroon | Kamerun |
CA | Canada | Kanada |
CV | Cape Verde | Kap Verde |
KZ | Kazakhstan | Kazakstan |
KE | Kenya | Kenya |
CN | China | Kina |
KG | Kyrgyzstan | Kirgizistan |
KI | Kiribati | Kiribati |
CC | Cocos (Keeling) Islands | Kokosöarna |
KM | Comoros | Komorerna |
CG | Congo | Kongo-Brazzaville |
HR | Croatia | Kroatien |
CU | Cuba | Kuba |
KW | Kuwait | Kuwait |
LA | Lao People's Democratic Republic | Laos |
LS | Lesotho | Lesotho |
LV | Latvia | Lettland |
LB | Lebanon | Libanon |
LR | Liberia | Liberia |
LY | Libya | Libyen |
LI | Liechtenstein | Liechtenstein |
LT | Lithuania | Litauen |
LU | Luxembourg | Luxemburg |
MO | Macao | Macau |
MG | Madagascar | Madagaskar |
MK | Macedonia, the former Yugoslav Republic of | Makedonien |
MW | Malawi | Malawi |
MY | Malaysia | Malaysia |
MV | Maldives | Maldiverna |
ML | Mali | Mali |
MT | Malta | Malta |
MA | Morocco | Marocko |
MH | Marshall Islands | Marshallöarna |
MQ | Martinique | Martinique |
MR | Mauritania | Mauretanien |
MU | Mauritius | Mauritius |
YT | Mayotte | Mayotte |
MX | Mexico | Mexiko |
FM | Micronesia, Federated States of | Mikronesiska federationen |
MZ | Mozambique | Moçambique |
MD | Moldova, Republic of | Moldavien |
MC | Monaco | Monaco |
MN | Mongolia | Mongoliet |
ME | Montenegro | Montenegro |
MS | Montserrat | Montserrat |
NA | Namibia | Namibia |
NR | Nauru | Nauru |
NL | Netherlands | Nederländerna |
AN | Netherlands Antilles | Nederländska Antillerna |
NP | Nepal | Nepal |
NI | Nicaragua | Nicaragua |
NE | Niger | Niger |
NG | Nigeria | Nigeria |
NU | Niue | Niue |
KP | Korea, Democratic People's Republic of | Nordkorea |
MP | Northern Mariana Islands | Nordmarianerna |
NF | Norfolk Island | Norfolkön |
NO | Norway | Norge |
NC | New Caledonia | Nya Kaledonien |
NZ | New Zealand | Nya Zeeland |
OM | Oman | Oman |
PK | Pakistan | Pakistan |
PW | Palau | Palau |
PA | Panama | Panama |
PG | Papua New Guinea | Papua Nya Guinea |
PY | Paraguay | Paraguay |
PE | Peru | Peru |
PN | Pitcairn | Pitcairnöarna |
PL | Poland | Polen |
PT | Portugal | Portugal |
PR | Puerto Rico | Puerto Rico |
QA | Qatar | Qatar |
RE | Réunion | Réunion |
RO | Romania | Rumänien |
RW | Rwanda | Rwanda |
RU | Russian Federation | Ryssland |
KN | Saint Kitts and Nevis | Saint Kitts och Nevis |
LC | Saint Lucia | Saint Lucia |
VC | Saint Vincent and the Grenadines | Saint Vincent och Grenadinerna |
BL | Saint Barthélemy | Saint-Barthélemy |
PM | Saint Pierre and Miquelon | Saint-Pierre och Miquelon |
SB | Solomon Islands | Salomonöarna |
WS | Samoa | Samoa |
SM | San Marino | San Marino |
SH | Saint Helena Ascension and Tristan da Cunha | Sankta Helena |
ST | Sao Tome and Principe | São Tomé och Príncipe |
SA | Saudi Arabia | Saudiarabien |
CH | Switzerland | Schweiz |
SN | Senegal | Senegal |
RS | Serbia | Serbien |
SC | Seychelles | Seychellerna |
SL | Sierra Leone | Sierra Leone |
SG | Singapore | Singapore |
SK | Slovakia | Slovakien |
SI | Slovenia | Slovenien |
SO | Somalia | Somalia |
ES | Spain | Spanien |
LK | Sri Lanka | Sri Lanka |
GB | United Kingdom | Storbritannien |
SD | Sudan | Sudan |
SR | Suriname | Surinam |
SJ | Svalbard and Jan Mayen | Svalbard och Jan Mayen |
SE | Sweden | Sverige |
SZ | Swaziland | Swaziland |
ZA | South Africa | Sydafrika |
KR | Korea Republic of | Sydkorea |
SY | Syrian Arab Republic | Syrien |
TJ | Tajikistan | Tadzjikistan |
TW | Taiwan Province of China | Taiwan |
TZ | Tanzania United Republic of | Tanzania |
TD | Chad | Tchad |
TH | Thailand | Thailand |
CZ | Czech Republic | Tjeckien |
TG | Togo | Togo |
TK | Tokelau | Tokelauöarna |
TO | Tonga | Tonga |
TT | Trinidad and Tobago | Trinidad och Tobago |
TN | Tunisia | Tunisien |
TR | Turkey | Turkiet |
TM | Turkmenistan | Turkmenistan |
TC | Turks and Caicos Islands | Turks- och Caicosöarna |
TV | Tuvalu | Tuvalu |
DE | Germany | Tyskland |
UG | Uganda | Uganda |
UA | Ukraine | Ukraina |
HU | Hungary | Ungern |
UY | Uruguay | Uruguay |
US | United States | USA |
UM | United States Minor Outlying Islands | USA:s yttre öar |
UZ | Uzbekistan | Uzbekistan |
VU | Vanuatu | Vanuatu |
VA | Holy See (Vatican City State) | Vatikanstaten |
VE | Venezuela, Bolivarian Republic of | Venezuela |
VN | Viet Nam | Vietnam |
BY | Belarus | Vitryssland |
EH | Western Sahara | Västsahara |
WF | Wallis and Futuna | Wallis- och Futunaöarna |
ZM | Zambia | Zambia |
ZW | Zimbabwe | Zimbabwe |
AX | Åland Islands | Åland |
AT | Austria | Österrike |
TL | Timor-Leste | Östtimor |
When we wrote the validations for
Invoice
andOrder
, we assumed Fortnox API uses country codes for theCountry
attribute. Unfortunately, that is not true.Country
is a string containing the full country name! If you look at the documentation examples, you see that they have"Country": "Sverige"
, and I recently got this error in one of our apps when a user tried to fetch an Order from Fortnox API:[Fortnox::API::Model::Order.new] "United Kingdom" (String) has invalid type for :country violates constraints (included_in?(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI"...
If you read the documentation for
Invoice
, it says that the string "Must be a name of an existing country.". What that means I do not know, so I've send a question to Fortnox API support. Apparently, you can write the country name in both Swedish (as the documentation exampel) and English (as the example above). What other languages are supported? Why do they not use country codes? There are so many questions... :confused: :question: