[cleanup] Default Warehouses created on Company creation. Warehouse names have Company abbreviation as suffix

This commit is contained in:
Rushabh Mehta
2013-07-10 18:59:55 +05:30
parent 982ad35fd2
commit ad71473f35
6 changed files with 69 additions and 58 deletions

View File

@@ -33,9 +33,28 @@ class DocType:
if self.doc.fields.get('__islocal') and len(self.doc.abbr) > 5:
webnotes.msgprint("Abbreviation cannot have more than 5 characters",
raise_exception=1)
# Create default accounts
# ---------------------------------------------------
def on_update(self):
if not webnotes.conn.sql("""select name from tabAccount
where company=%s and docstatus<2 limit 1""", self.doc.name):
self.create_default_accounts()
self.create_default_warehouses()
if not self.doc.cost_center:
self.create_default_cost_center()
self.set_default_accounts()
if self.doc.default_currency:
webnotes.conn.set_value("Currency", self.doc.default_currency, "enabled", 1)
def create_default_warehouses(self):
for whname in ("Stores", "Work In Progress", "Finished Goods"):
webnotes.bean({
"doctype":"Warehouse",
"company": self.doc.name
}).insert()
def create_default_accounts(self):
self.fld_dict = {'account_name':0,'parent_account':1,'group_or_ledger':2,'is_pl_account':3,'account_type':4,'debit_or_credit':5,'company':6,'tax_rate':7}
acc_list_common = [
@@ -162,32 +181,16 @@ class DocType:
for d in acc_list_india:
self.add_acc(d)
# Create account
# ---------------------------------------------------
def add_acc(self,lst):
ac = Document('Account')
account = webnotes.bean({
"doctype": "Account",
"freeze_account": "No",
"master_type": "",
})
for d in self.fld_dict.keys():
ac.fields[d] = (d == 'parent_account' and lst[self.fld_dict[d]]) and lst[self.fld_dict[d]] +' - '+ self.doc.abbr or lst[self.fld_dict[d]]
ac_obj = get_obj(doc=ac)
ac_obj.doc.freeze_account='No'
ac_obj.doc.master_type = ''
ac_obj.validate()
ac_obj.doc.save(1)
ac_obj.on_update()
# Set letter head
# ---------------------------------------------------
def set_letter_head(self):
if not self.doc.letter_head:
if self.doc.address:
header = """
<div><h3> %(comp)s </h3> %(add)s </div>
""" % {'comp':self.doc.name,
'add':self.doc.address.replace("\n",'<br>')}
self.doc.letter_head = header
account.doc.fields[d] = (d == 'parent_account' and lst[self.fld_dict[d]]) and lst[self.fld_dict[d]] +' - '+ self.doc.abbr or lst[self.fld_dict[d]]
account.insert()
def set_default_accounts(self):
accounts = {
@@ -209,8 +212,6 @@ class DocType:
if not self.doc.stock_adjustment_cost_center:
webnotes.conn.set(self.doc, "stock_adjustment_cost_center", self.doc.cost_center)
# Create default cost center
# ---------------------------------------------------
def create_default_cost_center(self):
cc_list = [
{
@@ -237,21 +238,6 @@ class DocType:
cc_bean.insert()
webnotes.conn.set(self.doc, "cost_center", "Main - " + self.doc.abbr)
def on_update(self):
self.set_letter_head()
if not webnotes.conn.sql("""select name from tabAccount
where company=%s and docstatus<2 limit 1""", self.doc.name):
self.create_default_accounts()
if not self.doc.cost_center:
self.create_default_cost_center()
self.set_default_accounts()
if self.doc.default_currency:
webnotes.conn.set_value("Currency", self.doc.default_currency, "enabled", 1)
def on_trash(self):
"""