AttributeError: 'int' object has no attribute 'has_key'

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 264, in _save
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 772, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 892, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 54, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 33, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 16, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 38, in validate
self.calculate_taxes_and_totals()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 101, in calculate_taxes_and_totals
calculate_taxes_and_totals(self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 15, in init
self.calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 19, in calculate
self._calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 33, in _calculate
self.calculate_taxes()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 181, in calculate_taxes
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 233, in get_current_tax_amount
tax_rate = self._get_tax_rate(tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 155, in _get_tax_rate
if item_tax_map.has_key(tax.account_head):
AttributeError: ‘int’ object has no attribute ‘has_key’

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 56, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 42, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 264, in _save
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 772, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 892, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 54, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 33, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 16, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 38, in validate
self.calculate_taxes_and_totals()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 101, in calculate_taxes_and_totals
calculate_taxes_and_totals(self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 15, in init
self.calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 19, in calculate
self._calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 33, in _calculate
self.calculate_taxes()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 181, in calculate_taxes
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 233, in get_current_tax_amount
tax_rate = self._get_tax_rate(tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 155, in _get_tax_rate
if item_tax_map.has_key(tax.account_head):
AttributeError: ‘int’ object has no attribute ‘has_key’

@Jermaine_Gray: have you applied any customizations to SalesInvoice DocType?

Yes, just add 2 customer field for interface to use.

@Jermaine_Gray what version are you on? can you check Help → About

Can you put this in a GitHub Issue?

I manage to recreate the issue with my server.

  1. Create invoice using the API
  2. Cancel same invoice in ERPNEXT
  3. Try to report invoice and i got this message.

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 254, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 193, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 772, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 892, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 54, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 33, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 16, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 38, in validate
self.calculate_taxes_and_totals()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 101, in calculate_taxes_and_totals
calculate_taxes_and_totals(self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 15, in init
self.calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 19, in calculate
self._calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 33, in _calculate
self.calculate_taxes()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 181, in calculate_taxes
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 233, in get_current_tax_amount
tax_rate = self._get_tax_rate(tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 155, in _get_tax_rate
if item_tax_map.has_key(tax.account_head):
AttributeError: ‘int’ object has no attribute ‘has_key’

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 56, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 42, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 907, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 254, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 193, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 772, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 892, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 54, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 33, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 16, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 38, in validate
self.calculate_taxes_and_totals()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 101, in calculate_taxes_and_totals
calculate_taxes_and_totals(self)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 15, in init
self.calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 19, in calculate
self._calculate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 33, in _calculate
self.calculate_taxes()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 181, in calculate_taxes
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 233, in get_current_tax_amount
tax_rate = self._get_tax_rate(tax, item_tax_map)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 155, in _get_tax_rate
if item_tax_map.has_key(tax.account_head):
AttributeError: ‘int’ object has no attribute ‘has_key’

What are you passing in item_tax_rate? It must be in the format “{‘TAX1’: 10, ‘TAX2’: 4}”.