creating creditors
Closed this issue · 2 comments
Does not work as documented. The helper function produces an error.
creditor.number = economic.creditors.next_available_number
There appears to be no function corresponding to this for creditors, not even in the SOAP API. I've written to e-conomics for a clarification.
The best work-around I can think of is currently to "get all" and find the last, highest creditor number. Or wait (gasp!) until e-conomics implements said get_next_available_number.
Otherwise, creating a creditor works, as long as you provide an unused number.
Strangely, 'creditor.save' no longer works if you go into the GUI, and delete the creditor you just created via 'creditor.save'.
I suspect our documentation is wrong here, probably the result of copy/pasting it from Debtor
that does have the next_available_number
method.
Having it available would be helpful, I'm sure, but it's probably not feasible unless E-conomic adds it to the API. I'd be interested in hearing what they have to say.
Their answer went:
The GetNextAvailableNumber method was only implemented for the most used entities years back. The criteria for whether or not an entity qualified to have this functionality or not I am not aware.
If you don’t want to use the Creditor_GetAll, you will need to store and maintain locally the creditor numbers you are using in e-conomic.
Med venlig hilsen / Best regards
Jostein Ågedal
Senior Developer
=====end answer===
sigh
So if
result = client.call(:debtor_get_next_available_number, cookies: auth_cookies)
Ruby code most useful to achieve a 'get next available number' somewhat synonymous to above for Creditor would be:
assuming:
client = Savon.client(wsdl: "https://api.e-conomic.com/secure/api1/EconomicWebService.asmx?wsdl")
auth_cookies = result.http.cookies
def :creditor_get_next_available_number
result = client.call(:creditor_get_all, cookies: auth_cookies)
list = result.to_hash[:creditor_get_all_response][:creditor_get_all_result][:creditor_handle]
arr = list.flat_map(&:values)
arr.map! { |i| i.to_i }.sort!
return arr.last + 1
end