From 2e0cc41fc6634403d392d3c41fe203e1e2e9dacf Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 11 Jun 2013 17:33:37 +0530 Subject: [PATCH] [chart of accounts/cost center] [add account/cost center] fix in permission issue --- accounts/utils.py | 2 -- buying/doctype/supplier/supplier.py | 19 ++++++++++++------- selling/doctype/customer/customer.py | 16 +++++++++------- setup/doctype/company/company.py | 6 ++++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/accounts/utils.py b/accounts/utils.py index 31e622166e..eb240e796c 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -125,7 +125,6 @@ def add_ac(args=None): ac.doc.doctype = "Account" ac.doc.old_parent = "" ac.doc.freeze_account = "No" - ac.ignore_permissions = 1 ac.insert() return ac.doc.name @@ -138,7 +137,6 @@ def add_cc(args=None): cc = webnotes.bean(args) cc.doc.doctype = "Cost Center" cc.doc.old_parent = "" - cc.ignore_permissions = 1 cc.insert() return cc.doc.name diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py index d41b86c32c..f506439bad 100644 --- a/buying/doctype/supplier/supplier.py +++ b/buying/doctype/supplier/supplier.py @@ -24,7 +24,6 @@ from webnotes.model.doc import make_autoname sql = webnotes.conn.sql -from accounts.utils import add_ac from utilities.transaction_base import TransactionBase class DocType(TransactionBase): @@ -71,14 +70,16 @@ class DocType(TransactionBase): return g def add_account(self, ac, par, abbr): - ac = add_ac({ + ac_bean = webnotes.bean({ + "doctype": "Account", 'account_name':ac, 'parent_account':par, 'group_or_ledger':'Group', 'company':self.doc.company, - 'account_type':'', - 'tax_rate':'0' + "freeze_account": "No", }) + ac_bean.ignore_permissions = True + ac_bean.insert() msgprint(_("Created Group ") + ac) @@ -109,8 +110,8 @@ class DocType(TransactionBase): parent_account = self.get_parent_account(abbr) if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)): - - ac = add_ac({ + ac_bean = webnotes.bean({ + "doctype": "Account", 'account_name': self.doc.name, 'parent_account': parent_account, 'group_or_ledger':'Ledger', @@ -119,8 +120,12 @@ class DocType(TransactionBase): 'tax_rate': '0', 'master_type': 'Supplier', 'master_name': self.doc.name, + "freeze_account": "No" }) - msgprint(_("Created Account Head: ") + ac) + ac_bean.ignore_permissions = True + ac_bean.insert() + + msgprint(_("Created Account Head: ") + ac_bean.doc.name) else: self.check_parent_account(parent_account, abbr) else : diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index 72e12b7942..65ac865304 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -115,18 +115,20 @@ class DocType(TransactionBase): if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)): parent_account = self.get_receivables_group() # create - from accounts.utils import add_ac - ac = add_ac({ - 'account_name':self.doc.name, + ac_bean = webnotes.bean({ + "doctype": "Account", + 'account_name': self.doc.name, 'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company, - 'account_type':'', - 'tax_rate':'0', 'master_type':'Customer', - 'master_name':self.doc.name + 'master_name':self.doc.name, + "freeze_account": "No" }) - msgprint("Account Head: %s created" % ac) + ac_bean.ignore_permissions = True + ac_bean.insert() + + msgprint("Account Head: %s created" % ac_bean.doc.name) else : msgprint("Please Select Company under which you want to create account head") diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py index 9863d7d28b..2564503833 100644 --- a/setup/doctype/company/company.py +++ b/setup/doctype/company/company.py @@ -222,7 +222,6 @@ class DocType: # Create default cost center # --------------------------------------------------- def create_default_cost_center(self): - from accounts.utils import add_cc cc_list = [ { 'cost_center_name':'Root', @@ -244,7 +243,10 @@ class DocType: } ] for cc in cc_list: - add_cc(cc) + cc.update({"doctype": "Cost Center"}) + cc_bean = webnotes.bean(cc) + cc_bean.ignore_permissions = True + cc_bean.insert() webnotes.conn.set_value("Company", self.doc.name, "cost_center", "Default CC Ledger - " + self.doc.abbr)