ej2 / python-quickbooks

A Python library for accessing the Quickbooks API.
MIT License
394 stars 193 forks source link

.from_json() does not work #350

Closed andsimakov closed 3 months ago

andsimakov commented 5 months ago

I'm trying the library and going through the manual from README.md. It looks cumbersome to fill in fields of an objects one by one:

author = Author()
author.AccountType = 'Accounts Receivable'
author.Name = 'MyJobs'
author.save(qb=client)

What if I have a dozen of them and even nested objects? Instead manual suggests to use .from_json():

account.from_json(
 {
  "AccountType": "Accounts Receivable",
  "Name": "MyJobs"
 }
)
account.save(qb=client)

but the saving attempt fails saying Name is not specified. account.__dict__ returns those fields as empty. The doc example does not work.

Executing it step by step:

account = Account()
account.AccountType = "Accounts Receivable"
account.Name = "MyJobs"
account.save(qb=client)

causes the failure during the saving attempt:

quickbooks.exceptions.ValidationException: QB Validation Exception 2170: Invalid Enumeration
Invalid Enumeration : 
ej2 commented 3 months ago

The readme is wrong... from_json returns an object with the values set. It should be:

account = Account.from_json(
 {
  "AccountType": "Accounts Receivable",
  "Name": "MyJobs"
 }
)
account.save(qb=client)

I added a test for from_json and updated the readme. Changes will go out in the next release.

ej2 commented 3 months ago

Readme example updated in 0.9.8