Hello there,
I am working on customizing ERPNext and I have a custom DocType created called “Coffee Gathering Receipt”. And this DocType has a field called “total_price” which stores the total price of the coffee that is going to be store in warehouse. Now whenever a new document of this DocType is created, I need this total_price to be stored in the “Stock In Hand Account”, in the chart of accounts, as well.
To the DocType, I added the following custom script with the following configuration.
- Script Type:
DocType Event
- Module (for export):
Accounts
- Reference Document Type:
Coffee Gathering Receipt
- DocType Event:
After Save
- Script:
from frappe import _
def validate(doc, method):
stock_in_hand_account = frappe.get_doc("Account", {"account_name": "Stock In Hand"})
stock_in_hand_account.balance = stock_in_hand_account.balance + doc.quantity
stock_in_hand_account.save(ignore_permissions=True)
But now, after setting this, when I create a new document of the Coffee Gathering Receipt DocType, the following error appears. Here is the complete log.
App Versions
{
"erpnext": "14.33.2",
"frappe": "14.43.1",
"hrms": "15.0.0-dev",
"payments": "0.0.1"
}
Route
Form/Coffee Gathering Recipt/bd9dee727e
Traceback
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 94, in application
response = frappe.api.handle()
File "apps/frappe/frappe/api.py", line 54, in handle
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 47, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1620, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/desk/form/save.py", line 28, in savedocs
doc.save()
File "apps/frappe/frappe/model/document.py", line 305, in save
return self._save(*args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 356, in _save
self.run_post_save_methods()
File "apps/frappe/frappe/model/document.py", line 1082, in run_post_save_methods
self.run_method("on_update")
File "apps/frappe/frappe/model/document.py", line 918, in run_method
run_server_script_for_doc_event(self, method)
File "apps/frappe/frappe/core/doctype/server_script/server_script_utils.py", line 39, in run_server_script_for_doc_event
frappe.get_doc("Server Script", script_name).execute_doc(doc)
File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 103, in execute_doc
safe_exec(self.script, _locals={"doc": doc}, restrict_commit_rollback=True)
File "apps/frappe/frappe/utils/safe_exec.py", line 72, in safe_exec
exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used
File "<unknown>", line 6, in <module>
ImportError: __import__ not found
Request Data
{
"type": "POST",
"args": {
"doc": "{\"name\":\"bd9dee727e\",\"owner\":\"Administrator\",\"creation\":\"2023-08-10 08:02:23.318131\",\"modified\":\"2023-08-10 12:01:07.936031\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":0,\"eu\":1,\"nop\":0,\"jas\":1,\"cafe\":0,\"no\":\"245\",\"date\":\"2023-08-10\",\"name1\":\"Birhane\",\"gender\":\"MALE\",\"kebele\":\"10\",\"type_of_coffee_product\":\"Honey\",\"quantity\":111,\"price\":34,\"total_price\":\"2000\",\"purchase_employee\":\"Administrator\",\"name_of_warehouse\":\"Xerro\",\"doctype\":\"Coffee Gathering Recipt\",\"__last_sync_on\":\"2023-08-10T09:09:33.713Z\",\"__unsaved\":1}",
"action": "Save"
},
"btn": {
"jQuery360069523876303124541": {
"events": {
"click": [
{
"type": "click",
"origType": "click",
"guid": 904,
"namespace": ""
}
]
}
}
},
"freeze": true,
"headers": {},
"error_handlers": {},
"url": "/api/method/frappe.desk.form.save.savedocs"
}
Response Data
{
"exception": "ImportError: __import__ not found"
}
Can anyone help me out solving this problem?
Thanks.