Error in generating sales invoice via REST Api

Hi Team,

We are facing problems in generating Sales Invoice using REST Api after the ERPNext 7 upgrade.

The data that we were sending is same. But the method is breaking and not generating the invoice.

Can you guys help us get around this problem? It is frustrating how the same thing doesnt go through after the upgrade. It takes time to study the API that you provided. Now after the upgrade, same thing doesnt work.

Input JSON that we are providing is -

{
“taxes_and_charges”: “POS Taxes”,
“items”: [
{
“cost_center”: “Paintball Walk Ins - D9”,
“qty”: 1,
“owner”: “###@###.com”,
“item_code”: “Field & Equipment Charges”,
“parenttype”: “Sales Invoice”,
“parentfield”: “items”
},
{
“cost_center”: “Paintball Walk Ins - D9”,
“qty”: 1,
“owner”: “###@###.com”,
“item_code”: “Paintballs - 50”,
“parenttype”: “Sales Invoice”,
“parentfield”: “items”
}
],
“taxes”: [
{
“charge_type”: “On Net Total”,
“description”: "VAT 4% ",
“parenttype”: “Sales Invoice”,
“account_head”: “VAT 4% - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Addl. VAT 1% ",
“parenttype”: “Sales Invoice”,
“account_head”: “VAT (Addl) - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Service Tax 14% ",
“parenttype”: “Sales Invoice”,
“account_head”: “Service Tax - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Swachh Bharat Cess 0.5% ",
“parenttype”: “Sales Invoice”,
“account_head”: “Swachh Bharat Cess - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
}
],
“cash_bank_account”: “Cash - D9”,
“is_pos”: 1,
“submit_on_creation”: 1,
“against_income_account”: “Service - D9,Sales - D9”,
“party_account_currency”: “INR”,
“owner”: “###@###.com”,
“price_list_currency”: “INR”,
“mode_of_payment”: “Cash”,
“customer_name”: “Retail Customer - From App”,
“update_stock”: 1,
“company”: “### Management LLP”,
“customer”: “Retail Customer - From App”,
“territory”: “Vadodara”,
“is_opening”: “No”,
“customer_group”: “Paintball Operator”,
“naming_series”: “R.#####”,
“currency”: “INR”,
“debit_to”: “Debtors - D9”,
“remarks”: “POS - 100300162”,
“posting_date”: “2016-07-02 04:22:07”,
“selling_price_list”: “Walk In”,
“discount_amount”: 100,
“apply_discount_on”: “Grand Total”
}

The error we are getting is as below -
Traceback (most recent call last):
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/api.py”, line 115, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 212, in insert
self.run_before_save_methods()
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 710, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 661, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 839, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 822, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/benches/bench-2016-08-29/apps/frappe/frappe/model/document.py”, line 655, in

fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 53, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/selling_controller.py”, line 32, in validate
super(SellingController, self).validate()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 35, in validate
self.calculate_taxes_and_totals()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 93, in calculate_taxes_and_totals
calculate_taxes_and_totals(self)
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 16, in init
self.calculate()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 27, in calculate
self.calculate_total_advance()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 417, in calculate_total_advance
self.calculate_outstanding_amount()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 424, in calculate_outstanding_amount
self.calculate_paid_amount()
File “/home/frappe/benches/bench-2016-08-29/apps/erpnext/erpnext/controllers/taxes_and_totals.py”, line 456, in calculate_paid_amount
payment.base_amount = flt(payment.amount * self.doc.conversion_rate)
TypeError: unsupported operand type(s) for *: ‘NoneType’ and ‘float’

Please help us with this on urgent basis.

Thanks,
Bhaumik Gandhi

1 Like

@saurabh6790 can you check?

Hi Team,

Can you please check this issue. It is very urgent.

This has been fixed in the latest release. Please update and check.

1 Like

Thanks. The issue has been solved.
Now getting one issue if I am sending with following data

“submit_on_creation”: 1,
“docstatus”: 1,

with above json for submit the Sales Invoice then ERPNEXT says

ValidationError: Account None is invalid. Account Currency must be INR


File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/api.py”, line 115, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 231, in insert
self.run_post_save_methods()
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 731, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 661, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 839, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 822, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/model/document.py”, line 655, in

fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 115, in on_submit
self.make_gl_entries()
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 494, in make_gl_entries
gl_entries = self.get_gl_entries()
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 533, in get_gl_entries
self.make_pos_gl_entries(gl_entries)
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 634, in make_pos_gl_entries
}, payment_mode_account_currency)
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 261, in get_gl_dict
self.validate_account_currency(gl_dict.account, account_currency)
File “/home/frappe/benches/bench-2016-09-01/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 273, in validate_account_currency
.format(account, _(" or ").join(valid_currency)))
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/init.py”, line 299, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/init.py”, line 292, in msgprint
_raise_exception()
File “/home/frappe/benches/bench-2016-09-01/apps/frappe/frappe/init.py”, line 265, in _raise_exception
raise raise_exception, encode(msg)
ValidationError: Account None is invalid. Account Currency must be INR

Seems like you have not mentioned account in the Payment Modes table.

Thanks for suggest me to put account in payments it works
Now, I am sending json with account but still getting following message and i have looked into stock ledger about units of items and its not negative there.

NegativeStockError: 2500.0 units of
Item Paintballs @ Store needed in
Warehouse D9A @ Vadodara - D9 on 2016-08-28 14:44:20.540602 for
Sales Invoice R02057 to complete this transaction.

HERE IS the JSON that sending to ERPNEXT
{
“taxes_and_charges”: “POS Taxes”,
“items”: [
{
“cost_center”: “Paintball - D9”,
“qty”: 7,
“owner”: “dhaval@d9adventures.com”,
“item_code”: “Paintballs - 50”,
“parenttype”: “Sales Invoice”,
“parentfield”: “items”
}
],
“taxes”: [
{
“charge_type”: “On Net Total”,
“description”: "VAT 4% ",
“parenttype”: “Sales Invoice”,
“account_head”: “VAT 4% - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Addl. VAT 1% ",
“parenttype”: “Sales Invoice”,
“account_head”: “VAT (Addl) - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Service Tax 14% ",
“parenttype”: “Sales Invoice”,
“account_head”: “Service Tax - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
},
{
“charge_type”: “On Net Total”,
“description”: "Swachh Bharat Cess 0.5% ",
“parenttype”: “Sales Invoice”,
“account_head”: “Swachh Bharat Cess - D9”,
“parentfield”: “taxes”,
“included_in_print_rate”: 1
}
],
“cash_bank_account”: “Cash - D9”,
“is_pos”: 1,
“submit_on_creation”: 1,
“docstatus”: 1,
“against_income_account”: “Service - D9,Sales - D9”,
“party_account_currency”: “INR”,
“owner”: “dhaval@d9adventures.com”,
“price_list_currency”: “INR”,
“payments”: [
{
“mode_of_payment”: “Cash”,
“amount”: 140,
“account”: “Cash - D9”
}
],
“customer_name”: “Retail Customer - From App”,
“update_stock”: 1,
“company”: “Delta 9 Sports Management LLP”,
“customer”: “Retail Customer - From App”,
“territory”: “Vadodara”,
“is_opening”: “No”,
“customer_group”: “Paintball Operator”,
“naming_series”: “R.#####”,
“currency”: “INR”,
“debit_to”: “Debtors - D9”,
“remarks”: “POS - 100300485”,
“posting_date”: “2016-08-27 22:23:46”,
“selling_price_list”: “Walk In”,
“discount_amount”: 0,
“apply_discount_on”: “Grand Total”
}

i’m facing the same issue with version 8. i guess it appeared again in version 8.

i think this issue appeared again in version 8

see if you can have a look.

i’m still facing the same issue. anyone who is using v8 REST API to post Sales Invoices with Payment