I want to create journals from a custom doctype. The custom doctype when submitted will create a journal entry record and submit it. Somewhat like what is done for Asset revaluation using python script and not give the user access.
e.g. erpnext/asset_value_adjustment.py at master · frappe/erpnext · GitHub
For me, it fails with an error, that the has_permission has failed for doctype Account and gives an error as below, even though I have set the ignore_permissions flag for the doc.
Has anybody done this before?
ignore_permissions=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 272, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 295, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 229, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 888, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 781, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py”, line 42, in validate
self.set_account_and_party_balance()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py”, line 638, in set_account_and_party_balance
account_balance[d.account] = get_balance_on(account=d.account, date=self.posting_date)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/utils.py”, line 150, in get_balance_on
acc.check_permission(“read”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 179, in check_permission
self.raise_no_permission_to(permlevel or permtype)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 193, in raise_no_permission_to
raise frappe.PermissionError
PermissionError
The code is like this:
def make_journal_entry(accounts,date,bill_no=None): if len(accounts) <= 0: frappe.throw(_("Something went while creating journal entry")) jv_doc = frappe.get_doc(dict( doctype = "Journal Entry", posting_date = date, accounts = accounts, bill_no = bill_no )) jv_doc.flags.ignore_permissions = True jv_doc.save(ignore_permissions = True) jv_doc.submit() return jv_doc.name