accodeing / fortnox-api

Gem that abstracts Fortnox's F3 API
GNU Lesser General Public License v3.0
9 stars 8 forks source link

Fix Customer SalesAccount type #214

Closed ehannes closed 2 years ago

ehannes commented 2 years ago

Apparently, SalesAccount attribute on Customer is a string, not an integer as the Number attribute in Account is.

According to the Fortnox documentation, in Customer a Sales Account is a "string 4 characters", but in Account the Numer attribute is an "integer [ 1000 .. 9999 ]". So Fortnox has different data types for "the same thing" on different endpoints :weary:

We are currently using the same implementation for validating both these attributes, but that's not a correct implementation. We get this error:

[Fortnox::API::Model::Customer.new] "3010" (String) has invalid type for :sales_account violates constraints
(type?(Integer, "3010") AND gteq?(0, "3010") AND lteq?(9999, "3010") failed) (Fortnox::API::AttributeError)

This is how the attribute is defined now, which is obviously wrong:

# SalesAccount  Sales account of the customer, 4 digits
attribute :sales_account, Types::AccountNumber
ehannes commented 2 years ago

There's a branch with a test for this: https://github.com/accodeing/fortnox-api/tree/fix-214-sales-account

ehannes commented 2 years ago

Fortnox... really?

If I create a Customer with the JSON payload below, with SalesAccount as a string just like the documentation tells me to

{"Customer":{"Name":"Customer with Sales Account","SalesAccount":"3001"}}

You return this:

{"Customer":{"@url":"https:\/\/api.fortnox.se\/3\/customers\/242",..., SalesAccount":3001}}

Why have you converted the string to an integer? You just told me through the documentation that this value, strangely enough, is a string! But then, when I fetch the same Customer I just created:

{"Customer": "@url":"https:\/\/api.fortnox.se\/3\/customers\/242", ..., "SalesAccount":"3001"}}

you give me SalesAccount as a ... string :tired_face: