Try ERPNext Buy Support Partners Foundation

Need to create a journal without giving rights to Account doctype

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.


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?

File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 272, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 295, in _save
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 229, in insert
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 888, in run_before_save_methods
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 787, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1058, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1041, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, 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/”, line 42, in validate
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/journal_entry/”, 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/”, line 150, in get_balance_on
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 179, in check_permission
self.raise_no_permission_to(permlevel or permtype)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 193, in raise_no_permission_to
raise frappe.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 = True)

add this flag as well

frappe.flags.ignore_account_permission = True

1 Like