From 665568d87ed9b8c09516c7a672d29a75dbd73472 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 13 May 2016 15:56:00 +0530 Subject: [PATCH] ignore permissions while creating records from charts builder portal --- .../account/chart_of_accounts/chart_of_accounts.py | 4 +++- erpnext/accounts/utils.py | 8 +++++++- erpnext/setup/doctype/company/company.py | 10 ++++++---- .../setup/doctype/company/fixtures/india/__init__.py | 4 +++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py index aaa0a18dbf..e2e21fa347 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py +++ b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py @@ -6,7 +6,7 @@ import frappe, os, json from frappe.utils import cstr from unidecode import unidecode -def create_charts(chart_name, company): +def create_charts(chart_name, company, ignore_permissions=False): chart = get_chart(chart_name) if chart: @@ -44,6 +44,8 @@ def create_charts(chart_name, company): if root_account or frappe.local.flags.allow_unverified_charts: account.flags.ignore_mandatory = True + account.flags.ignore_permissions = ignore_permissions + account.insert() accounts.append(account_name_in_db) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 077fcb4599..683b84b3d6 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -131,12 +131,18 @@ def add_ac(args=None): args.pop("cmd") ac = frappe.new_doc("Account") + + if args.get("ignore_permissions"): + ac.flags.ignore_permissions = True + args.pop("ignore_permissions") + ac.update(args) ac.old_parent = "" ac.freeze_account = "No" if cint(ac.get("is_root")): ac.parent_account = None - ac.flags.ignore_mandatory = True + ac.flags.ignore_mandatory = True + ac.insert() return ac.name diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index c12fb8c8b9..800e19e10a 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -67,7 +67,7 @@ class Company(Document): self.create_default_accounts() self.create_default_warehouses() - self.install_country_fixtures() + self.install_country_fixtures() if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": self.name}): self.create_default_cost_center() @@ -92,19 +92,21 @@ class Company(Document): stock_group = frappe.db.get_value("Account", {"account_type": "Stock", "is_group": 1, "company": self.name}) if stock_group: - frappe.get_doc({ + warehouse = frappe.get_doc({ "doctype":"Warehouse", "warehouse_name": whname, "company": self.name, "create_account_under": stock_group - }).insert() + }) + warehouse.flags.ignore_permissions = self.flags.ignore_permissions + warehouse.insert() def create_default_accounts(self): if not self.chart_of_accounts: self.chart_of_accounts = "Standard" from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts - create_charts(self.chart_of_accounts, self.name) + create_charts(self.chart_of_accounts, self.name, self.flags.ignore_permissions) frappe.db.set(self, "default_receivable_account", frappe.db.get_value("Account", {"company": self.name, "account_type": "Receivable"})) diff --git a/erpnext/setup/doctype/company/fixtures/india/__init__.py b/erpnext/setup/doctype/company/fixtures/india/__init__.py index 55185ac223..e39c41005b 100644 --- a/erpnext/setup/doctype/company/fixtures/india/__init__.py +++ b/erpnext/setup/doctype/company/fixtures/india/__init__.py @@ -14,6 +14,8 @@ def install(company): for d in docs: try: - frappe.get_doc(d).insert() + doc = frappe.get_doc(d) + doc.flags.ignore_permissions = True + doc.insert() except frappe.NameError: pass