Error in api call for sales invoice entry

I have check for the api call for sales invoice entry but getting the following error with trace back…

File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 62, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 119, in handle
“data”: frappe.get_doc(data).insert().as_dict()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 192, 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 666, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 887, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 870, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 660, 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 57, 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 17, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 34, in validate
self.set_missing_values(for_validate=True)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 242, in set_missing_values
self.debit_to = get_party_account(“Customer”, self.customer, self.company)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 175, in get_party_account
frappe.throw(_(“Please select a Company”))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 319, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
raise raise_exception(encode(msg))
ValidationError: Please select a Company

I have already pass the company name there but this showing an error…

following is my request object,

API URL: api/resource/Sales Invoice
Request:
{
“data”:{
“company”:“Demo Company”,
“posting_date” : “2017-10-14”,
“due_date”: “2017-10-30”,
“customer”:“350”,
“items”: [
{
“item_name”: “test”,
“description”: “test”,
“uom”: “Nos”,
“income_account”: “Sales - DC”,
“cost_center”: “Main - DC”
}
],
“customer_name”: “snd snd”,
“naming_series”: “SINV-”,
“debit_to”: “Cash - DC”
}
}

Hi what I would suggest is that you look at party.py

File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 175, in get_party_account
frappe.throw(_(“Please select a Company”))

its on line 175

Try to see what conditions who have not met.

You can also print the variables that are in there.

Another option is that you create an invoice manually and create a script to get the dict:

invoice_dict = frappe.get_doc(“Sales Invoice”,some_invoice_name).get_dict()

invoice_dict will give you the complete dict

,after getting the dict you may start replacing the values.

I have solved issue by passing the following request object…,

{
“company”:“Demo Company”,
“posting_date” : “2017-10-14”,
“due_date”: “2017-10-30”,
“customer”:“350”,
“conversion_rate”:1,
“plc_conversion_rate”:1,
“items”: [
{
“item_name”: “test”,
“description”: “test”,
“uom”: “Nos”,
“income_account”: “Sales - DC”,
“doctype”:“Sales Invoice Item”,
“base_amount” : 8.0,
“rate” : 4.0,
“amount” : 8.0,
“base_rate”: 4.0,
“cost_center”: “Main - DC”,
“conversion_factor”:1
}
],
“customer_name”: “snd snd”,
“naming_series”: “SINV-”,
“debit_to”: “Debtors - DC”,
“Status”: “Paid”,
“doc_status” :1
}