[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

@ -52,6 +52,22 @@ wn.module_page["Accounts"] = [
}, },
] ]
}, },
{
title: wn._("Setup"),
icon: "icon-wrench",
items: [
{
label: wn._("Company"),
description: wn._("Company Master."),
doctype:"Company"
},
{
label: wn._("Fiscal Year"),
description: wn._("Accounting Year."),
doctype:"Fiscal Year"
},
]
},
{ {
title: wn._("Tools"), title: wn._("Tools"),
icon: "icon-wrench", icon: "icon-wrench",

View File

@ -34,8 +34,27 @@ class DocType:
webnotes.msgprint("Abbreviation cannot have more than 5 characters", webnotes.msgprint("Abbreviation cannot have more than 5 characters",
raise_exception=1) 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): 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} 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 = [ acc_list_common = [
@ -162,32 +181,16 @@ class DocType:
for d in acc_list_india: for d in acc_list_india:
self.add_acc(d) self.add_acc(d)
# Create account
# ---------------------------------------------------
def add_acc(self,lst): 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(): 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]] 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]]
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()
account.insert()
# 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
def set_default_accounts(self): def set_default_accounts(self):
accounts = { accounts = {
@ -209,8 +212,6 @@ class DocType:
if not self.doc.stock_adjustment_cost_center: if not self.doc.stock_adjustment_cost_center:
webnotes.conn.set(self.doc, "stock_adjustment_cost_center", self.doc.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): def create_default_cost_center(self):
cc_list = [ cc_list = [
{ {
@ -238,21 +239,6 @@ class DocType:
webnotes.conn.set(self.doc, "cost_center", "Main - " + self.doc.abbr) 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): def on_trash(self):
""" """
Trash accounts and cost centers for this company if no gl entry exists Trash accounts and cost centers for this company if no gl entry exists

View File

@ -100,8 +100,10 @@ def import_country_and_currency():
def import_defaults(): def import_defaults():
records = [ records = [
# item group # item group
{'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'name': 'All Item Groups', 'parent_item_group': ''}, {'doctype': 'Item Group', 'item_group_name': 'All Item Groups', 'is_group': 'Yes', 'parent_item_group': ''},
{'doctype': 'Item Group', 'item_group_name': 'Default', 'is_group': 'No', 'name': 'Default', 'parent_item_group': 'All Item Groups'}, {'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
{'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
{'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
# deduction type # deduction type
{'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'}, {'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
@ -131,16 +133,25 @@ def import_defaults():
# customer group # customer group
{'doctype': 'Customer Group', 'customer_group_name': 'All Customer Groups', 'is_group': 'Yes', 'name': 'All Customer Groups', 'parent_customer_group': ''}, {'doctype': 'Customer Group', 'customer_group_name': 'All Customer Groups', 'is_group': 'Yes', 'name': 'All Customer Groups', 'parent_customer_group': ''},
{'doctype': 'Customer Group', 'customer_group_name': 'Default', 'is_group': 'No', 'name': 'Default Customer Group', 'parent_customer_group': 'All Customer Groups'}, {'doctype': 'Customer Group', 'customer_group_name': 'Individual', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
{'doctype': 'Customer Group', 'customer_group_name': 'Commercial', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
{'doctype': 'Customer Group', 'customer_group_name': 'Non Profit', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
{'doctype': 'Customer Group', 'customer_group_name': 'Government', 'is_group': 'No', 'parent_customer_group': 'All Customer Groups'},
# supplier type # supplier type
{'doctype': 'Supplier Type', 'name': 'Default Supplier Type', 'supplier_type': 'Default Supplier Type'}, {'doctype': 'Supplier Type', 'supplier_type': 'Services'},
{'doctype': 'Supplier Type', 'supplier_type': 'Local'},
{'doctype': 'Supplier Type', 'supplier_type': 'Raw Material'},
{'doctype': 'Supplier Type', 'supplier_type': 'Electrical'},
{'doctype': 'Supplier Type', 'supplier_type': 'Hardware'},
{'doctype': 'Supplier Type', 'supplier_type': 'Pharmaceutical'},
{'doctype': 'Supplier Type', 'supplier_type': 'Distributor'},
# Workstation # Workstation
{'doctype': 'Workstation', 'name': 'Default Workstation', 'workstation_name': 'Default Workstation', 'warehouse': 'Default Warehouse'}, {'doctype': 'Workstation', 'name': 'Default Workstation', 'workstation_name': 'Default Workstation', 'warehouse': 'Default Warehouse'},
# Sales Person # Sales Person
{'doctype': 'Sales Person', 'name': 'All Sales Persons', 'sales_person_name': 'All Sales Persons', 'is_group': "Yes", "parent_sales_person": ""}, {'doctype': 'Sales Person', 'sales_person_name': 'Sales Team', 'is_group': "Yes", "parent_sales_person": ""},
# UOM # UOM
{'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit'}, {'uom_name': 'Unit', 'doctype': 'UOM', 'name': 'Unit'},

View File

@ -28,6 +28,11 @@ class DocType:
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
def autoname(self):
suffix = " - " + webnotes.conn.get_value("Company", self.doc.company, "abbr")
if not self.doc.warehouse_name.endswith(suffix):
self.doc.name = self.doc.warehouse_name + suffix
def get_bin(self, item_code, warehouse=None): def get_bin(self, item_code, warehouse=None):
warehouse = warehouse or self.doc.name warehouse = warehouse or self.doc.name
bin = sql("select name from tabBin where item_code = %s and \ bin = sql("select name from tabBin where item_code = %s and \

View File

@ -2,13 +2,12 @@
{ {
"creation": "2013-03-07 18:50:32", "creation": "2013-03-07 18:50:32",
"docstatus": 0, "docstatus": 0,
"modified": "2013-07-10 18:37:24", "modified": "2013-07-10 18:46:40",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
{ {
"allow_rename": 1, "allow_rename": 1,
"autoname": "field:warehouse_name",
"description": "A logical Warehouse against which stock entries are made.", "description": "A logical Warehouse against which stock entries are made.",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Master", "document_type": "Master",

View File

@ -77,12 +77,6 @@ wn.module_page["Website"] = [
icon: "icon-wrench", icon: "icon-wrench",
right: true, right: true,
items: [ items: [
{
"route":"Form/Product Settings",
"label":wn._("Product Settings"),
"description":wn._("Settings for Product Catalog on the website."),
doctype:"Product Settings"
},
{ {
"route":"Form/About Us Settings", "route":"Form/About Us Settings",
"label":wn._("About Us Settings"), "label":wn._("About Us Settings"),