API Integration - TypeError: bad operand type for abs(): 'NoneType'

Hi all,

We are trying to submit sales orders programmatically with as few properties as possible to decrease our data load. We are running into this error:

(most recent call last):
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/app.py”, line 64, in application
response = frappe.api.handle()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/api.py”, line 130, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 230, in insert
self.run_before_save_methods()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 896, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 797, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 1073, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 1056, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/frappe/frappe/model/document.py”, line 791, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py”, line 36, in validate
super(SalesOrder, self).validate()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/erpnext/erpnext/controllers/selling_controller.py”, line 39, in validate
super(SellingController, self).validate()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/erpnext/erpnext/controllers/stock_controller.py”, line 21, in validate
super(StockController, self).validate()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 84, in validate
self.set_total_in_words()
File “/home/frappe/benches/bench-version-12-2020-09-25/apps/erpnext/erpnext/controllers/selling_controller.py”, line 118, in set_total_in_words
if self.is_rounded_total_disabled() else self.base_rounded_total)
TypeError: bad operand type for abs(): ‘NoneType’

It seems like something is wrong with the way ERPNext is calculating base_rounded_total? Can we disable is_rounded_total somewhere? Our item rates are all in float type and we are not passing in a base_rounded_total property, just letting ERPNext calculate it.

image
I have disabled rounded total and total in words, but we are still having this problem.

Actually we figured it out; the base_rounded_total was a red herring! We were not submitting the appropriate headers.

Make sure when you’re writing an API that you include content-type = application/json, folks, and it will go a long way. :stuck_out_tongue_winking_eye: