Rename Tool updates
diff --git a/accounts/doctype/account/account.js b/accounts/doctype/account/account.js
index 856b58a..071bf57 100644
--- a/accounts/doctype/account/account.js
+++ b/accounts/doctype/account/account.js
@@ -72,6 +72,7 @@
else alert("Please select master type");
}
+/*
// Get customer/supplier address
// -----------------------------------------
cur_frm.cscript.master_name = function(doc,cdt,cdn){
@@ -79,6 +80,7 @@
get_server_fields('get_address','','',doc,cdt,cdn);
}
}
+*/
// parent account get query
// -----------------------------------------
diff --git a/accounts/doctype/account/account.py b/accounts/doctype/account/account.py
index ed49c2d..f5e4a6d 100644
--- a/accounts/doctype/account/account.py
+++ b/accounts/doctype/account/account.py
@@ -260,3 +260,16 @@
def on_restore(self):
# rebuild tree
self.update_nsm_model()
+
+ # on rename
+ # ---------
+ def on_rename(self,newdn,olddn):
+ company_abbr = sql("select tc.abbr from `tabAccount` ta, `tabCompany` tc where ta.company = tc.name and ta.name=%s", olddn)[0][0]
+
+ newdnchk = newdn.split(" - ")
+
+ if newdnchk[-1].lower() != company_abbr.lower():
+ msgprint("Please add company abbreviation <b>%s</b>" %(company_abbr), raise_exception=1)
+ else:
+ account_name = " - ".join(newdnchk[:-1])
+ sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(account_name,olddn))
diff --git a/crm/doctype/customer/customer.py b/crm/doctype/customer/customer.py
index eba2fc0..42f9ea3 100644
--- a/crm/doctype/customer/customer.py
+++ b/crm/doctype/customer/customer.py
@@ -10,221 +10,248 @@
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
convert_to_lists = webnotes.conn.convert_to_lists
-
+
# -----------------------------------------------------------------------------------------
-
class DocType:
- def __init__(self, doc, doclist=[]):
- self.doc = doc
- self.doclist = doclist
-
+ def __init__(self, doc, doclist=[]):
+ self.doc = doc
+ self.doclist = doclist
+
# ******************************************************* autoname ***********************************************************
- def autoname(self):
- cust_master_name = get_defaults().get('cust_master_name')
- if cust_master_name == 'Customer Name':
-
- # filter out bad characters in name
- #cust = self.doc.customer_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
- cust = self.doc.customer_name
+ def autoname(self):
+ cust_master_name = get_defaults().get('cust_master_name')
+ if cust_master_name == 'Customer Name':
+ # filter out bad characters in name
+ #cust = self.doc.customer_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
+ cust = self.doc.customer_name
- supp = sql("select name from `tabSupplier` where name = %s", (cust))
- supp = supp and supp[0][0] or ''
- if supp:
- msgprint("You already have a Supplier with same name")
- raise Exception
- else:
- self.doc.name = cust
-
- else:
- self.doc.name = make_autoname(self.doc.naming_series+'.#####')
+ supp = sql("select name from `tabSupplier` where name = %s", (cust))
+ supp = supp and supp[0][0] or ''
+ if supp:
+ msgprint("You already have a Supplier with same name")
+ raise Exception
+ else:
+ self.doc.name = cust
+ else:
+ self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ******************************************************* triggers ***********************************************************
- # ----------------
- # get company abbr
- # -----------------
- def get_company_abbr(self):
- return get_value('Company', self.doc.company, 'abbr')
+ # ----------------
+ # get company abbr
+ # -----------------
+ def get_company_abbr(self):
+ return get_value('Company', self.doc.company, 'abbr')
- # -----------------------------------------------------------------------------------------------------
- # get parent account(i.e receivables group from company where default account head need to be created)
- # -----------------------------------------------------------------------------------------------------
- def get_receivables_group(self):
- g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
- g = g and g[0][0] or ''
- if not g:
- msgprint("Update Company master, assign a default group for Receivables")
- raise Exception
- return g
-
+ # -----------------------------------------------------------------------------------------------------
+ # get parent account(i.e receivables group from company where default account head need to be created)
+ # -----------------------------------------------------------------------------------------------------
+ def get_receivables_group(self):
+ g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
+ g = g and g[0][0] or ''
+ if not g:
+ msgprint("Update Company master, assign a default group for Receivables")
+ raise Exception
+ return g
+
# ******************************************************* validate *********************************************************
- # ----------------
- # validate values
- # ----------------
- def validate_values(self):
- # Master name by naming series -> Series field mandatory
- if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
- msgprint("Series is Mandatory.")
- raise Exception
+ # ----------------
+ # validate values
+ # ----------------
+ def validate_values(self):
+ # Master name by naming series -> Series field mandatory
+ if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
+ msgprint("Series is Mandatory.")
+ raise Exception
- # ---------
- # validate
- # ---------
- def validate(self):
- self.validate_values()
+ # ---------
+ # validate
+ # ---------
+ def validate(self):
+ self.validate_values()
# ******************************************************* on update *********************************************************
- # ------------------------
- # create customer address
- # ------------------------
- def create_customer_address(self):
- addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
- address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
+ # ------------------------
+ # create customer address
+ # ------------------------
+ def create_customer_address(self):
+ addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
+ address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
- if self.doc.phone_1:
- address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
- if self.doc.email_id:
- address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
- set(self.doc,'address', address_line)
-
- telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " + "\n" + "(fax): " + cstr(self.doc.fax_1)
- set(self.doc,'telephone',telephone)
+ if self.doc.phone_1:
+ address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
+ if self.doc.email_id:
+ address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
+ set(self.doc,'address', address_line)
+
+ telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " + "\n" + "(fax): " + cstr(self.doc.fax_1)
+ set(self.doc,'telephone',telephone)
- # ------------------------------------
- # create primary contact for customer
- # ------------------------------------
- def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
- c1 = Document('Contact')
- c1.first_name = nm
- c1.contact_name = nm
- c1.contact_no = phn_no
- c1.email_id = email_id
- c1.mobile_no = mob_no
- c1.fax = fax
- c1.contact_address = cont_addr
- c1.is_primary_contact = 'Yes'
- c1.is_customer =1
- c1.customer = self.doc.name
- c1.customer_name = self.doc.customer_name
- c1.customer_address = self.doc.address
- c1.customer_group = self.doc.customer_group
- c1.save(1)
+ # ------------------------------------
+ # create primary contact for customer
+ # ------------------------------------
+ def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
+ c1 = Document('Contact')
+ c1.first_name = nm
+ c1.contact_name = nm
+ c1.contact_no = phn_no
+ c1.email_id = email_id
+ c1.mobile_no = mob_no
+ c1.fax = fax
+ c1.contact_address = cont_addr
+ c1.is_primary_contact = 'Yes'
+ c1.is_customer =1
+ c1.customer = self.doc.name
+ c1.customer_name = self.doc.customer_name
+ c1.customer_address = self.doc.address
+ c1.customer_group = self.doc.customer_group
+ c1.save(1)
- # ------------------------
- # create customer contact
- # ------------------------
- def create_customer_contact(self):
- contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
- contact = contact and contact[0][0] or ''
- if not contact:
- # create primary contact for individual customer
- if self.doc.customer_type == 'Individual':
- self.create_p_contact(self.doc.customer_name,self.doc.phone_1,self.doc.email_id,'',self.doc.fax_1,self.doc.address)
-
- # create primary contact for lead
- elif self.doc.lead_name:
- c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1)
- self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '')
+ # ------------------------
+ # create customer contact
+ # ------------------------
+ def create_customer_contact(self):
+ contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
+ contact = contact and contact[0][0] or ''
+ if not contact:
+ # create primary contact for individual customer
+ if self.doc.customer_type == 'Individual':
+ self.create_p_contact(self.doc.customer_name,self.doc.phone_1,self.doc.email_id,'',self.doc.fax_1,self.doc.address)
+
+ # create primary contact for lead
+ elif self.doc.lead_name:
+ c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1)
+ self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '')
- # -------------------
- # update lead status
- # -------------------
- def update_lead_status(self):
- if self.doc.lead_name:
- sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name)
+ # -------------------
+ # update lead status
+ # -------------------
+ def update_lead_status(self):
+ if self.doc.lead_name:
+ sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name)
- # -------------------------------------------------------------------------
- # create accont head - in tree under receivables_group of selected company
- # -------------------------------------------------------------------------
- def create_account_head(self):
- if self.doc.company :
- abbr = self.get_company_abbr()
- if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
- parent_account = self.get_receivables_group()
- arg = {'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,'address':self.doc.address}
- # create
- ac = get_obj('GL Control').add_ac(cstr(arg))
- msgprint("Account Head created for "+ac)
- else :
- msgprint("Please Select Company under which you want to create account head")
+ # -------------------------------------------------------------------------
+ # create accont head - in tree under receivables_group of selected company
+ # -------------------------------------------------------------------------
+ def create_account_head(self):
+ if self.doc.company :
+ abbr = self.get_company_abbr()
+ if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
+ parent_account = self.get_receivables_group()
+ arg = {'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,'address':self.doc.address}
+ # create
+ ac = get_obj('GL Control').add_ac(cstr(arg))
+ msgprint("Account Head created for "+ac)
+ else :
+ msgprint("Please Select Company under which you want to create account head")
- # ----------------------------------------
- # update credit days and limit in account
- # ----------------------------------------
- def update_credit_days_limit(self):
- sql("update tabAccount set credit_days = '%s', credit_limit = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.credit_limit, self.doc.name + " - " + self.get_company_abbr()))
+ # ----------------------------------------
+ # update credit days and limit in account
+ # ----------------------------------------
+ def update_credit_days_limit(self):
+ sql("update tabAccount set credit_days = '%s', credit_limit = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.credit_limit, self.doc.name + " - " + self.get_company_abbr()))
- #create address and contact from lead
- def create_lead_address_contact(self):
- if self.doc.lead_name:
- details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, contact_no, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
- d = Document('Address')
- d.address_line1 = details[0]['address_line1']
- d.address_line2 = details[0]['address_line2']
- d.city = details[0]['city']
- d.country = details[0]['country']
- d.pincode = details[0]['pincode']
- d.state = details[0]['state']
- d.fax = details[0]['fax']
- d.email_id = details[0]['email_id']
- d.phone = details[0]['contact_no']
- d.customer = self.doc.name
- d.customer_name = self.doc.customer_name
- d.is_primary_address = 1
- d.address_type = 'Office'
- try:
- d.save(1)
- except NameError, e:
- pass
-
- c = Document('Contact')
- c.first_name = details[0]['lead_name']
- c.email_id = details[0]['email_id']
- c.phone = details[0]['contact_no']
- c.phone = details[0]['contact_no']
- c.customer = self.doc.name
- c.customer_name = self.doc.customer_name
- c.is_primary_contact = 1
- try:
- c.save(1)
- except NameError, e:
- pass
+ #create address and contact from lead
+ def create_lead_address_contact(self):
+ if self.doc.lead_name:
+ details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
+ d = Document('Address')
+ d.address_line1 = details[0]['address_line1']
+ d.address_line2 = details[0]['address_line2']
+ d.city = details[0]['city']
+ d.country = details[0]['country']
+ d.pincode = details[0]['pincode']
+ d.state = details[0]['state']
+ d.fax = details[0]['fax']
+ d.email_id = details[0]['email_id']
+ d.phone = details[0]['phone']
+ d.customer = self.doc.name
+ d.customer_name = self.doc.customer_name
+ d.is_primary_address = 1
+ d.address_type = 'Office'
+ try:
+ d.save(1)
+ except NameError, e:
+ pass
+
+ c = Document('Contact')
+ c.first_name = details[0]['lead_name']
+ c.email_id = details[0]['email_id']
+ c.phone = details[0]['phone']
+ c.mobile_no = details[0]['mobile_no']
+ c.customer = self.doc.name
+ c.customer_name = self.doc.customer_name
+ c.is_primary_contact = 1
+ try:
+ c.save(1)
+ except NameError, e:
+ pass
- # ----------
- # on update
- # ----------
- def on_update(self):
- # create customer addr
- #self.create_customer_address()
- # create customer contact
- #self.create_customer_contact()
- # update lead status
- self.update_lead_status()
- # create account head
- self.create_account_head()
- # update credit days and limit in account
- self.update_credit_days_limit()
- #create address and contact from lead
- self.create_lead_address_contact()
+ # ----------
+ # on update
+ # ----------
+ def on_update(self):
+ # create customer addr
+ #self.create_customer_address()
+ # create customer contact
+ #self.create_customer_contact()
+ # update lead status
+ self.update_lead_status()
+ # create account head
+ self.create_account_head()
+ # update credit days and limit in account
+ self.update_credit_days_limit()
+ #create address and contact from lead
+ self.create_lead_address_contact()
- def delete_customer_address(self):
- for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1):
- sql("delete from `tabAddress` where name=%s",(rec['name']))
-
- def delete_customer_contact(self):
- for rec in sql("select * from `tabContact` where customer='%s'" %(self.doc.name), as_dict=1):
- sql("delete from `tabContact` where name=%s",(rec['name']))
-
+ def delete_customer_address(self):
+ for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1):
+ sql("delete from `tabAddress` where name=%s",(rec['name']))
+
+ def delete_customer_contact(self):
+ for rec in sql("select * from `tabContact` where customer='%s'" %(self.doc.name), as_dict=1):
+ sql("delete from `tabContact` where name=%s",(rec['name']))
+
# ******************************************************* on trash *********************************************************
- def on_trash(self):
- self.delete_customer_address()
- self.delete_customer_contact()
- if self.doc.lead_name:
- sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
+ def on_trash(self):
+ self.delete_customer_address()
+ self.delete_customer_contact()
+ if self.doc.lead_name:
+ sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
+
+ # on rename
+ # ---------
+ def on_rename(self,newdn,olddn):
+ #update customer_name if not naming series
+ if get_defaults().get('cust_master_name') == 'Customer Name':
+ update_fields = [
+ ('Customer', 'name'),
+ ('Address', 'customer'),
+ ('Contact', 'customer'),
+ ('Customer Issue', 'customer'),
+ ('Delivery Note', 'customer'),
+ ('Enquiry', 'customer'),
+ ('Installation Note', 'customer'),
+ ('Maintenance Schedule', 'customer'),
+ ('Maintenance Visit', 'customer'),
+ ('Project', 'customer'),
+ ('Quotation', 'customer'),
+ ('Receivable Voucher', 'customer'),
+ ('Sales Order', 'customer'),
+ ('Serial No', 'customer'),
+ ('Shipping Address', 'customer'),
+ ('Stock Entry', 'customer'),
+ ('Support Ticket', 'customer'),
+ ('Ticket', 'customer')]
+ for rec in update_fields:
+ sql("update `tab%s` set customer_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn))
+
+ #update master_name in doctype account
+ sql("update `tabAccount` set master_name = '%s', master_type = 'Customer' where master_name = '%s'" %(newdn,olddn))
diff --git a/patches/patch.py b/patches/patch.py
index 1ffb099..15b5754 100644
--- a/patches/patch.py
+++ b/patches/patch.py
@@ -1,6 +1,6 @@
# REMEMBER to update this
# ========================
-last_patch = 305
+last_patch = 306
#-------------------------------------------
@@ -1187,9 +1187,9 @@
reload_doc('payroll', 'doctype', 'salary_structure')
reload_doc('payroll', 'doctype', 'salary_slip')
elif patch_no == 298:
- sql("update `tabDocField` set options = 'Link:Company' where parent = 'Attendance' and fieldname = 'company'")
- sql("update `tabDocField` set options = 'Link:Company' where parent = 'Expense Voucher' and fieldname = 'company'")
- sql("update `tabDocField` set options = 'Link:Company' where parent = 'Appraisal' and fieldname = 'company'")
+ sql("update `tabDocField` set options = 'link:Company' where parent = 'Attendance' and fieldname = 'company'")
+ sql("update `tabDocField` set options = 'link:Company' where parent = 'Expense Voucher' and fieldname = 'company'")
+ sql("update `tabDocField` set options = 'link:Company' where parent = 'Appraisal' and fieldname = 'company'")
elif patch_no == 299:
sql("update `tabDocPerm` set `match` = NULL where parent = 'Employee' and role = 'Employee'")
elif patch_no == 300:
@@ -1207,3 +1207,9 @@
reload_doc('setup', 'doctype', 'company')
elif patch_no == 305:
sql("update `tabDocField` set options = 'link:Company' where options='link:Company' and fieldname='company' and fieldtype='Select'")
+ elif patch_no == 306:
+ sql("update `tabDocField` set options = '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem' where parent = 'Rename Tool' and fieldname = 'select_doctype'")
+ sql("update `tabDocField` set options = 'link:Item' where parent = 'Raw Materials Supplied' and fieldname = 'po_item'")
+ sql("update `tabDocField` set options = 'Sales Order' where parent = 'Indent Detail' and fieldname = 'sales_order_no'")
+ sql("update `tabDocField` set options = 'link:Company', fieldtype = 'Select' where parent = 'Stock Ledger Entry' and fieldname = 'company'")
+ reload_doc('tools', 'doctype', 'rename_tool')
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index ac5d0d6..783a158 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -13,234 +13,239 @@
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
-
+
# -----------------------------------------------------------------------------------------
class DocType:
- def __init__(self,d,dl):
- self.doc, self.doclist = d,dl
-
- # Create default accounts
- # ---------------------------------------------------
- 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 = [['Application of Funds (Assets)','','Group','No','','Debit',self.doc.name,''],
- ['Current Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
- ['Accounts Receivable','Current Assets','Group','No','','Debit',self.doc.name,''],
- ['Bank Accounts','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
- ['Cash In Hand','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
- ['Cash','Cash In Hand','Ledger','No','Bank or Cash','Debit',self.doc.name,''],
- ['Loans and Advances (Assets)','Current Assets','Group','No','','Debit',self.doc.name,''],
- ['Securities and Deposits','Current Assets','Group','No','','Debit',self.doc.name,''],
- ['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
- ['Stock In Hand','Current Assets','Group','No','','Debit',self.doc.name,''],
- ['Stock','Stock In Hand','Ledger','No','','Debit',self.doc.name,''],
- ['Tax Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
- ['Fixed Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
- ['Capital Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
- ['Computers','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
- ['Furniture and Fixture','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
- ['Office Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
- ['Plant and Machinery','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
- ['Investments','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
- ['Temporary Accounts (Assets)','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
- ['Temporary Account (Assets)','Temporary Accounts (Assets)','Ledger','No','','Debit',self.doc.name,''],
- ['Source of Funds (Liabilities)','','Group','No','','Credit',self.doc.name,''],
- ['Capital Account','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Reserves and Surplus','Capital Account','Group','No','','Credit',self.doc.name,''],
- ['Shareholders Funds','Capital Account','Group','No','','Credit',self.doc.name,''],
- ['Current Liabilities','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Accounts Payable','Current Liabilities','Group','No','','Credit',self.doc.name,''],
- ['Duties and Taxes','Current Liabilities','Group','No','','Credit',self.doc.name,''],
- ['Loans (Liabilities)','Current Liabilities','Group','No','','Credit',self.doc.name,''],
- ['Secured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Unsecured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Bank Overdraft Account','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Temporary Accounts (Liabilities)','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
- ['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,''],
- ['Income','','Group','Yes','','Credit',self.doc.name,''],
- ['Direct Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
- ['Sales','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
- ['Service','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
- ['Indirect Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
- ['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''],
- ['Direct Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
- ['Cost of Goods Sold','Direct Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Indirect Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
- ['Advertising and Publicity','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
- ['Bad Debts Written Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Bank Charges','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Books and Periodicals','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Charity and Donations','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Commission on Sales','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Conveyance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Customer Entertainment Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Depreciation Account','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Freight and Forwarding Charges','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
- ['Legal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Miscellaneous Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
- ['Office Maintenance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Office Rent','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Postal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Print and Stationary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Rounded Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Salary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Sales Promotion Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
- ['Service Charges Paid','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Staff Welfare Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Telephone Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Travelling Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
- ['Water and Electricity Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,'']
- ]
-
- acc_list_india = [
- ['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['CENVAT','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
- ['CENVAT Service Tax','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['CENVAT Service Tax Cess 1','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['CENVAT Service Tax Cess 2','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['CENVAT Edu Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
- ['CENVAT SHE Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
- ['Excise Duty 4','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'4.00'],
- ['Excise Duty 8','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'8.00'],
- ['Excise Duty 10','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'10.00'],
- ['Excise Duty 14','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'14.00'],
- ['Excise Duty Edu Cess 2','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'2.00'],
- ['Excise Duty SHE Cess 1','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'1.00'],
- ['P L A','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['P L A - Cess Portion','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
- ['Edu. Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
- ['Edu. Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
- ['Edu. Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
- ['Excise Duty @ 4','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'4.00'],
- ['Excise Duty @ 8','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'8.00'],
- ['Excise Duty @ 10','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.00'],
- ['Excise Duty @ 14','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'14.00'],
- ['Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.3'],
- ['SHE Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
- ['SHE Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
- ['SHE Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
- ['Professional Tax','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['VAT','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Advertisement)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Commission)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Contractor)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Interest)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Rent)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
- ['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,'']
- ]
- # load common account heads
- for d in acc_list_common:
- self.add_acc(d)
+ def __init__(self,d,dl):
+ self.doc, self.doclist = d,dl
+
+ # Create default accounts
+ # ---------------------------------------------------
+ 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 = [['Application of Funds (Assets)','','Group','No','','Debit',self.doc.name,''],
+ ['Current Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+ ['Accounts Receivable','Current Assets','Group','No','','Debit',self.doc.name,''],
+ ['Bank Accounts','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
+ ['Cash In Hand','Current Assets','Group','No','Bank or Cash','Debit',self.doc.name,''],
+ ['Cash','Cash In Hand','Ledger','No','Bank or Cash','Debit',self.doc.name,''],
+ ['Loans and Advances (Assets)','Current Assets','Group','No','','Debit',self.doc.name,''],
+ ['Securities and Deposits','Current Assets','Group','No','','Debit',self.doc.name,''],
+ ['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
+ ['Stock In Hand','Current Assets','Group','No','','Debit',self.doc.name,''],
+ ['Stock','Stock In Hand','Ledger','No','','Debit',self.doc.name,''],
+ ['Tax Assets','Current Assets','Group','No','','Debit',self.doc.name,''],
+ ['Fixed Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+ ['Capital Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+ ['Computers','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+ ['Furniture and Fixture','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+ ['Office Equipments','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+ ['Plant and Machinery','Fixed Assets','Ledger','No','Fixed Asset Account','Debit',self.doc.name,''],
+ ['Investments','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+ ['Temporary Accounts (Assets)','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
+ ['Temporary Account (Assets)','Temporary Accounts (Assets)','Ledger','No','','Debit',self.doc.name,''],
+ ['Source of Funds (Liabilities)','','Group','No','','Credit',self.doc.name,''],
+ ['Capital Account','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Reserves and Surplus','Capital Account','Group','No','','Credit',self.doc.name,''],
+ ['Shareholders Funds','Capital Account','Group','No','','Credit',self.doc.name,''],
+ ['Current Liabilities','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Accounts Payable','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+ ['Duties and Taxes','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+ ['Loans (Liabilities)','Current Liabilities','Group','No','','Credit',self.doc.name,''],
+ ['Secured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Unsecured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Bank Overdraft Account','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Temporary Accounts (Liabilities)','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
+ ['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,''],
+ ['Income','','Group','Yes','','Credit',self.doc.name,''],
+ ['Direct Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
+ ['Sales','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
+ ['Service','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
+ ['Indirect Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
+ ['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Direct Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Cost of Goods Sold','Direct Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Indirect Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Advertising and Publicity','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+ ['Bad Debts Written Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Bank Charges','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Books and Periodicals','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Charity and Donations','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Commission on Sales','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Conveyance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Customer Entertainment Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Depreciation Account','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Freight and Forwarding Charges','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+ ['Legal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Miscellaneous Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+ ['Office Maintenance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Office Rent','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Postal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Print and Stationary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Rounded Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Salary','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Sales Promotion Expenses','Indirect Expenses','Ledger','Yes','Chargeable','Debit',self.doc.name,''],
+ ['Service Charges Paid','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Staff Welfare Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Telephone Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Travelling Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
+ ['Water and Electricity Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,'']
+ ]
+
+ acc_list_india = [
+ ['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['CENVAT','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+ ['CENVAT Service Tax','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['CENVAT Service Tax Cess 1','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['CENVAT Service Tax Cess 2','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['CENVAT Edu Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+ ['CENVAT SHE Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
+ ['Excise Duty 4','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'4.00'],
+ ['Excise Duty 8','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'8.00'],
+ ['Excise Duty 10','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'10.00'],
+ ['Excise Duty 14','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'14.00'],
+ ['Excise Duty Edu Cess 2','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'2.00'],
+ ['Excise Duty SHE Cess 1','Tax Assets','Ledger','No','Tax','Debit',self.doc.name,'1.00'],
+ ['P L A','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['P L A - Cess Portion','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
+ ['Edu. Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+ ['Edu. Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+ ['Edu. Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'2.00'],
+ ['Excise Duty @ 4','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'4.00'],
+ ['Excise Duty @ 8','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'8.00'],
+ ['Excise Duty @ 10','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.00'],
+ ['Excise Duty @ 14','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'14.00'],
+ ['Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'10.3'],
+ ['SHE Cess on Excise','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+ ['SHE Cess on Service Tax','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+ ['SHE Cess on TDS','Duties and Taxes','Ledger','No','Tax','Credit',self.doc.name,'1.00'],
+ ['Professional Tax','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['VAT','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Advertisement)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Commission)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Contractor)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Interest)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Rent)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
+ ['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,'']
+ ]
+ # load common account heads
+ for d in acc_list_common:
+ self.add_acc(d)
- country = sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'")
- country = country and cstr(country[0][0]) or ''
+ country = sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'")
+ country = country and cstr(country[0][0]) or ''
- # load taxes (only for India)
- if country == 'India':
- for d in acc_list_india:
- self.add_acc(d)
+ # load taxes (only for India)
+ if country == 'India':
+ for d in acc_list_india:
+ self.add_acc(d)
- # Create account
- # ---------------------------------------------------
- def add_acc(self,lst):
- ac = Document('Account')
- 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.old_parent = ''
- ac_obj = get_obj(doc=ac)
- ac_obj.validate()
- ac_obj.doc.save(1)
- ac_obj.on_update()
- sql("commit")
- sql("start transaction")
+ # Create account
+ # ---------------------------------------------------
+ def add_acc(self,lst):
+ ac = Document('Account')
+ 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.old_parent = ''
+ ac_obj = get_obj(doc=ac)
+ ac_obj.validate()
+ ac_obj.doc.save(1)
+ ac_obj.on_update()
+ sql("commit")
+ sql("start transaction")
- # Set letter head
- # ---------------------------------------------------
- def set_letter_head(self):
- if not self.doc.letter_head:
- if self.doc.address:
- header = """
+ # 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
+ """ % {'comp':self.doc.name,
+ 'add':self.doc.address.replace("\n",'<br>')}
+
+ self.doc.letter_head = header
- # Set default AR and AP group
- # ---------------------------------------------------
- def set_default_groups(self):
- if not self.doc.receivables_group:
- set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr)
- if not self.doc.payables_group:
- set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr)
-
-
- # Create default cost center
- # ---------------------------------------------------
- def create_default_cost_center(self):
- glc = get_obj('GL Control')
- cc_list = [{'cost_center_name':'Root','company_name':self.doc.name,'company_abbr':self.doc.abbr,'group_or_ledger':'Group','parent_cost_center':'','old_parent':''}, {'cost_center_name':'Default CC Ledger','company_name':self.doc.name,'company_abbr':self.doc.abbr,'group_or_ledger':'Ledger','parent_cost_center':'Root - ' + self.doc.abbr,'old_parent':''}]
- for c in cc_list:
- glc.add_cc(str(c))
-
-
- # On update
- # ---------------------------------------------------
- def on_update(self):
- self.set_letter_head()
- ac = sql("select name from tabAccount where account_name='Income' and company=%s", self.doc.name)
- if not ac:
- self.create_default_accounts()
- self.set_default_groups()
- cc = sql("select name from `tabCost Center` where cost_center_name = 'Root' and company_name = '%s'"%(self.doc.name))
- if not cc:
- self.create_default_cost_center()
+ # Set default AR and AP group
+ # ---------------------------------------------------
+ def set_default_groups(self):
+ if not self.doc.receivables_group:
+ set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr)
+ if not self.doc.payables_group:
+ set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr)
+
+
+ # Create default cost center
+ # ---------------------------------------------------
+ def create_default_cost_center(self):
+ glc = get_obj('GL Control')
+ cc_list = [{'cost_center_name':'Root','company_name':self.doc.name,'company_abbr':self.doc.abbr,'group_or_ledger':'Group','parent_cost_center':'','old_parent':''}, {'cost_center_name':'Default CC Ledger','company_name':self.doc.name,'company_abbr':self.doc.abbr,'group_or_ledger':'Ledger','parent_cost_center':'Root - ' + self.doc.abbr,'old_parent':''}]
+ for c in cc_list:
+ glc.add_cc(str(c))
+
+
+ # On update
+ # ---------------------------------------------------
+ def on_update(self):
+ self.set_letter_head()
+ ac = sql("select name from tabAccount where account_name='Income' and company=%s", self.doc.name)
+ if not ac:
+ self.create_default_accounts()
+ self.set_default_groups()
+ cc = sql("select name from `tabCost Center` where cost_center_name = 'Root' and company_name = '%s'"%(self.doc.name))
+ if not cc:
+ self.create_default_cost_center()
- # Trash accounts and cost centers for this company
- # ---------------------------------------------------
- #def on_trash1(self):
- # acc = sql("select name from tabAccount where company = '%s' and docstatus != 2 order by lft desc, rgt desc limit 2" % self.doc.name, debug=1)
- # for each in acc:
- # get_obj('Account', each[0]).on_trash()
-
- # cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name)
- # for each in cc:
- # get_obj('Cost Center', each[0]).on_trash()
-
- # msgprint("Company trashed. All the accounts and cost centers related to this company also trashed. You can restore it anytime from Setup -> Manage Trash")
-
- def on_trash(self):
- rec = sql("SELECT sum(ab.opening), sum(ab.balance), sum(ab.debit), sum(ab.credit) FROM `tabAccount Balance` ab, `tabAccount` a WHERE ab.account = a.name and a.company = %s", self.doc.name)
- if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
- #delete tabAccount Balance
- sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name)
- #delete tabAccount
- sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name)
-
- #delete cost center child table - budget detail
- sql("delete bd.* from `tabBudget Detail` bd, `tabCost Center` cc where bd.parent = cc.name and cc.company_name = %s", self.doc.name)
- #delete cost center
- sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name)
-
- #update value as blank for tabDefaultValue defkey=company
- sql("update `tabDefaultValue` set defvalue = '' where defkey='company' and defvalue = %s", self.doc.name)
-
- #update value as blank for tabSingles Manage Account
- sql("update `tabSingles` set value = '' where doctype='Manage Account' and field = 'default_company' and value = %s", self.doc.name)
+ # Trash accounts and cost centers for this company
+ # ---------------------------------------------------
+ #def on_trash1(self):
+ # acc = sql("select name from tabAccount where company = '%s' and docstatus != 2 order by lft desc, rgt desc limit 2" % self.doc.name, debug=1)
+ # for each in acc:
+ # get_obj('Account', each[0]).on_trash()
+
+ # cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name)
+ # for each in cc:
+ # get_obj('Cost Center', each[0]).on_trash()
+
+ # msgprint("Company trashed. All the accounts and cost centers related to this company also trashed. You can restore it anytime from Setup -> Manage Trash")
+
+ def on_trash(self):
+ rec = sql("SELECT sum(ab.opening), sum(ab.balance), sum(ab.debit), sum(ab.credit) FROM `tabAccount Balance` ab, `tabAccount` a WHERE ab.account = a.name and a.company = %s", self.doc.name)
+ if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
+ #delete tabAccount Balance
+ sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name)
+ #delete tabAccount
+ sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name)
+
+ #delete cost center child table - budget detail
+ sql("delete bd.* from `tabBudget Detail` bd, `tabCost Center` cc where bd.parent = cc.name and cc.company_name = %s", self.doc.name)
+ #delete cost center
+ sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name)
+
+ #update value as blank for tabDefaultValue defkey=company
+ sql("update `tabDefaultValue` set defvalue = '' where defkey='company' and defvalue = %s", self.doc.name)
+
+ #update value as blank for tabSingles Manage Account
+ sql("update `tabSingles` set value = '' where doctype='Manage Account' and field = 'default_company' and value = %s", self.doc.name)
- # Restore accounts and cost centers for this company
- # ---------------------------------------------------
- def on_restore(self):
- acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name)
- for each in acc:
- get_obj('Account', each[0]).on_restore()
-
- cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 2" % self.doc.name)
- for each in cc:
- get_obj('Cost Center', each[0]).on_restore()
-
- msgprint("Company restored. All the accounts and cost centers related to this company also restored.")
+ # Restore accounts and cost centers for this company
+ # ---------------------------------------------------
+ def on_restore(self):
+ acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name)
+ for each in acc:
+ get_obj('Account', each[0]).on_restore()
+
+ cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 2" % self.doc.name)
+ for each in cc:
+ get_obj('Cost Center', each[0]).on_restore()
+
+ msgprint("Company restored. All the accounts and cost centers related to this company also restored.")
+
+ # on rename
+ # ---------
+ def on_rename(self,newdn,olddn):
+ sql("update `tabCompany` set company_name = '%s' where name = '%s'" %(newdn,olddn))
diff --git a/setup/doctype/company/company.txt b/setup/doctype/company/company.txt
index 598ec29..529b682 100644
--- a/setup/doctype/company/company.txt
+++ b/setup/doctype/company/company.txt
@@ -1,6 +1,6 @@
[
{
- '_last_update': '1309168616',
+ '_last_update': '1309506817',
'allow_attach': None,
'allow_copy': None,
'allow_email': None,
@@ -29,7 +29,7 @@
'istable': None,
'max_attachments': None,
'menu_index': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'module': 'Setup',
'name': 'Company',
@@ -53,7 +53,7 @@
'subject': None,
'tag_fields': None,
'use_template': None,
- 'version': 91
+ 'version': 92
},
{
'amend': 0,
@@ -65,7 +65,7 @@
'execute': None,
'idx': 1,
'match': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'PERM00119',
'owner': 'Administrator',
@@ -79,8 +79,8 @@
'write': 1
},
{
- 'amend': 1,
- 'cancel': 1,
+ 'amend': 0,
+ 'cancel': 0,
'create': 1,
'creation': '2010-08-08 17:08:55',
'docstatus': 0,
@@ -88,7 +88,7 @@
'execute': None,
'idx': 2,
'match': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'PERM00120',
'owner': 'Administrator',
@@ -103,17 +103,17 @@
},
{
'amend': None,
- 'cancel': None,
+ 'cancel': 0,
'create': None,
- 'creation': '2011-06-29 18:02:47',
+ 'creation': '2010-08-08 17:08:55',
'docstatus': 0,
'doctype': 'DocPerm',
'execute': None,
'idx': 3,
'match': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'PERM00859',
+ 'name': 'PERM00121',
'owner': 'Administrator',
'parent': 'Company',
'parentfield': 'permissions',
@@ -127,7 +127,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-29 17:48:40',
+ 'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': 'Please Enter Company Name and Abbr and save the document. Once saved Accounting Settings will be populated automatically',
@@ -140,9 +140,9 @@
'idx': 1,
'in_filter': None,
'label': 'Details',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'FL05478',
+ 'name': 'FL05650',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -176,7 +176,7 @@
'idx': 2,
'in_filter': None,
'label': 'Company',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00695',
'no_column': None,
@@ -212,7 +212,7 @@
'idx': 3,
'in_filter': None,
'label': 'Abbr',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00696',
'no_column': None,
@@ -248,7 +248,7 @@
'idx': 4,
'in_filter': None,
'label': 'Address',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00697',
'no_column': None,
@@ -271,7 +271,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-04-19 17:40:13',
+ 'creation': '2011-04-19 18:48:56',
'default': None,
'depends_on': None,
'description': None,
@@ -284,9 +284,9 @@
'idx': 5,
'in_filter': None,
'label': 'Default Currency',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': '000003935',
+ 'name': '000031318',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -307,7 +307,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-29 17:48:40',
+ 'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': None,
@@ -320,9 +320,9 @@
'idx': 6,
'in_filter': None,
'label': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'FL05479',
+ 'name': 'FL05651',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -356,7 +356,7 @@
'idx': 7,
'in_filter': None,
'label': 'Phone No',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00699',
'no_column': None,
@@ -392,7 +392,7 @@
'idx': 8,
'in_filter': None,
'label': 'Email',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00700',
'no_column': None,
@@ -428,7 +428,7 @@
'idx': 9,
'in_filter': None,
'label': 'Fax',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00701',
'no_column': None,
@@ -464,7 +464,7 @@
'idx': 10,
'in_filter': None,
'label': 'Website',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00702',
'no_column': None,
@@ -487,7 +487,7 @@
{
'allow_on_submit': None,
'colour': 'White:FFF',
- 'creation': '2011-06-29 17:48:40',
+ 'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': 'Company registration numbers for your reference. Example: VAT Registration Numbers etc.',
@@ -500,9 +500,9 @@
'idx': 11,
'in_filter': None,
'label': 'Registration Info',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'FL05480',
+ 'name': 'FL05652',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -536,7 +536,7 @@
'idx': 12,
'in_filter': None,
'label': 'Registration Details',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00704',
'no_column': None,
@@ -559,7 +559,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-29 17:48:40',
+ 'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': 'eval:!doc.__islocal',
'description': None,
@@ -572,9 +572,9 @@
'idx': 13,
'in_filter': None,
'label': 'Accounting Settings',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'FL05481',
+ 'name': 'FL05653',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -608,7 +608,7 @@
'idx': 14,
'in_filter': None,
'label': 'Default Bank Account',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00706',
'no_column': None,
@@ -644,7 +644,7 @@
'idx': 15,
'in_filter': None,
'label': 'Receivables Group',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00707',
'no_column': None,
@@ -680,7 +680,7 @@
'idx': 16,
'in_filter': None,
'label': 'Payables Group',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00708',
'no_column': None,
@@ -703,7 +703,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-29 17:48:40',
+ 'creation': '2011-07-01 13:23:37',
'default': None,
'depends_on': None,
'description': None,
@@ -716,9 +716,9 @@
'idx': 17,
'in_filter': None,
'label': None,
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
- 'name': 'FL05482',
+ 'name': 'FL05654',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -752,7 +752,7 @@
'idx': 18,
'in_filter': None,
'label': 'If Yearly Budget Exceeded',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00710',
'no_column': None,
@@ -788,7 +788,7 @@
'idx': 19,
'in_filter': None,
'label': 'If Monthly Budget Exceeded',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00711',
'no_column': None,
@@ -824,7 +824,7 @@
'idx': 20,
'in_filter': None,
'label': 'Credit Days',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00712',
'no_column': None,
@@ -860,7 +860,7 @@
'idx': 21,
'in_filter': None,
'label': 'Credit Limit',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00713',
'no_column': None,
@@ -896,7 +896,7 @@
'idx': 22,
'in_filter': None,
'label': 'Trash Reason',
- 'modified': '2011-06-29 18:02:47',
+ 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator',
'name': 'FL00716',
'no_column': None,
diff --git a/srm/doctype/supplier/supplier.py b/srm/doctype/supplier/supplier.py
index 31d5b3d..55bf8b8 100644
--- a/srm/doctype/supplier/supplier.py
+++ b/srm/doctype/supplier/supplier.py
@@ -13,136 +13,155 @@
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
-
+
# -----------------------------------------------------------------------------------------
-
class DocType:
- def __init__(self, doc, doclist=[]):
- self.doc = doc
- self.doclist = doclist
+ def __init__(self, doc, doclist=[]):
+ self.doc = doc
+ self.doclist = doclist
- def autoname(self):
- #get default naming conventional from control panel
- supp_master_name = get_defaults()['supp_master_name']
+ def autoname(self):
+ #get default naming conventional from control panel
+ supp_master_name = get_defaults()['supp_master_name']
- if supp_master_name == 'Supplier Name':
-
- # filter out bad characters in name
- #supp = self.doc.supplier_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
- supp = self.doc.supplier_name
-
- cust = sql("select name from `tabCustomer` where name = '%s'" % (supp))
- cust = cust and cust[0][0] or ''
-
- if cust:
- msgprint("You already have a Customer with same name")
- raise Exception
- self.doc.name = supp
-
- else:
- self.doc.name = make_autoname(self.doc.naming_series+'.#####')
+ if supp_master_name == 'Supplier Name':
+
+ # filter out bad characters in name
+ #supp = self.doc.supplier_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
+ supp = self.doc.supplier_name
+
+ cust = sql("select name from `tabCustomer` where name = '%s'" % (supp))
+ cust = cust and cust[0][0] or ''
+
+ if cust:
+ msgprint("You already have a Customer with same name")
+ raise Exception
+ self.doc.name = supp
+
+ else:
+ self.doc.name = make_autoname(self.doc.naming_series+'.#####')
- # ----------------------------------------
- # update credit days and limit in account
- # ----------------------------------------
- def update_credit_days_limit(self):
- sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr()))
+ # ----------------------------------------
+ # update credit days and limit in account
+ # ----------------------------------------
+ def update_credit_days_limit(self):
+ sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr()))
- def on_update(self):
- if not self.doc.naming_series:
- self.doc.naming_series = ''
+ def on_update(self):
+ if not self.doc.naming_series:
+ self.doc.naming_series = ''
-
- # create address
- addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
- address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
- set(self.doc,'address', address_line)
+
+ # create address
+ addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
+ address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
+ set(self.doc,'address', address_line)
- # create account head
- self.create_account_head()
+ # create account head
+ self.create_account_head()
# update credit days and limit in account
- self.update_credit_days_limit()
+ self.update_credit_days_limit()
- def check_state(self):
- return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
-
- # ACCOUNTS
- # -------------------------------------------
- def get_payables_group(self):
- g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
- g = g and g[0][0] or ''
- if not g:
- msgprint("Update Company master, assign a default group for Payables")
- raise Exception
- return g
+ def check_state(self):
+ return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
+
+ # ACCOUNTS
+ # -------------------------------------------
+ def get_payables_group(self):
+ g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
+ g = g and g[0][0] or ''
+ if not g:
+ msgprint("Update Company master, assign a default group for Payables")
+ raise Exception
+ return g
- def add_account(self, ac, par, abbr):
- arg = {'account_name':ac,'parent_account':par, 'group_or_ledger':'Group', 'company':self.doc.company,'account_type':'','tax_rate':'0'}
- t = get_obj('GL Control').add_ac(cstr(arg))
- msgprint("Created Group " + t)
-
- def get_company_abbr(self):
- return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
-
- def get_parent_account(self, abbr):
- if (not self.doc.supplier_type):
- msgprint("Supplier Type is mandatory")
- raise Exception
-
- if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)):
+ def add_account(self, ac, par, abbr):
+ arg = {'account_name':ac,'parent_account':par, 'group_or_ledger':'Group', 'company':self.doc.company,'account_type':'','tax_rate':'0'}
+ t = get_obj('GL Control').add_ac(cstr(arg))
+ msgprint("Created Group " + t)
+
+ def get_company_abbr(self):
+ return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
+
+ def get_parent_account(self, abbr):
+ if (not self.doc.supplier_type):
+ msgprint("Supplier Type is mandatory")
+ raise Exception
+
+ if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)):
- # if not group created , create it
- self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
-
- return self.doc.supplier_type + " - " + abbr
+ # if not group created , create it
+ self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
+
+ return self.doc.supplier_type + " - " + abbr
- def validate(self):
- #validation for Naming Series mandatory field...
- if get_defaults()['supp_master_name'] == 'Naming Series':
- if not self.doc.naming_series:
- msgprint("Series is Mandatory.")
- raise Exception
-
-
- # create accont head - in tree under zone + territory
- # -------------------------------------------------------
- def create_account_head(self):
- if self.doc.company :
- abbr = self.get_company_abbr()
-
- if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
- parent_account = self.get_parent_account(abbr)
-
- arg = {'account_name':self.doc.name,'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company,'account_type':'','tax_rate':'0','master_type':'Supplier','master_name':self.doc.name,'address':self.doc.address}
- # create
- ac = get_obj('GL Control').add_ac(cstr(arg))
- msgprint("Created Account Head: "+ac)
-
- else :
- msgprint("Please select Company under which you want to create account head")
-
-
- def get_contacts(self,nm):
- if nm:
- contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
-
- return contact_details
- else:
- return ''
-
- def delete_supplier_address(self):
- for rec in sql("select * from `tabAddress` where supplier='%s'" %(self.doc.name), as_dict=1):
- sql("delete from `tabAddress` where name=%s",(rec['name']))
-
- def delete_supplier_contact(self):
- for rec in sql("select * from `tabContact` where supplier='%s'" %(self.doc.name), as_dict=1):
- sql("delete from `tabContact` where name=%s",(rec['name']))
-
- def on_trash(self):
- self.delete_supplier_address()
- self.delete_supplier_contact()
+ def validate(self):
+ #validation for Naming Series mandatory field...
+ if get_defaults()['supp_master_name'] == 'Naming Series':
+ if not self.doc.naming_series:
+ msgprint("Series is Mandatory.")
+ raise Exception
+
+
+ # create accont head - in tree under zone + territory
+ # -------------------------------------------------------
+ def create_account_head(self):
+ if self.doc.company :
+ abbr = self.get_company_abbr()
+
+ if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
+ parent_account = self.get_parent_account(abbr)
+
+ arg = {'account_name':self.doc.name,'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company,'account_type':'','tax_rate':'0','master_type':'Supplier','master_name':self.doc.name,'address':self.doc.address}
+ # create
+ ac = get_obj('GL Control').add_ac(cstr(arg))
+ msgprint("Created Account Head: "+ac)
+
+ else :
+ msgprint("Please select Company under which you want to create account head")
+
+
+ def get_contacts(self,nm):
+ if nm:
+ contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
+
+ return contact_details
+ else:
+ return ''
+
+ def delete_supplier_address(self):
+ for rec in sql("select * from `tabAddress` where supplier='%s'" %(self.doc.name), as_dict=1):
+ sql("delete from `tabAddress` where name=%s",(rec['name']))
+
+ def delete_supplier_contact(self):
+ for rec in sql("select * from `tabContact` where supplier='%s'" %(self.doc.name), as_dict=1):
+ sql("delete from `tabContact` where name=%s",(rec['name']))
+
+ def on_trash(self):
+ self.delete_supplier_address()
+ self.delete_supplier_contact()
+
+ # on rename
+ # ---------
+ def on_rename(self,newdn,olddn):
+ #update supplier_name if not naming series
+ if get_defaults().get('supp_master_name') == 'Supplier Name':
+ update_fields = [
+ ('Supplier', 'name'),
+ ('Address', 'supplier'),
+ ('Contact', 'supplier'),
+ ('Payable Voucher', 'supplier'),
+ ('Purchase Order', 'supplier'),
+ ('Purchase Receipt', 'supplier'),
+ ('Serial No', 'supplier'),
+ ('Supplier Quotation', 'supplier')]
+ for rec in update_fields:
+ sql("update `tab%s` set supplier_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn))
+
+ #update master_name in doctype account
+ sql("update `tabAccount` set master_name = '%s', master_type = 'Supplier' where master_name = '%s'" %(newdn,olddn))
diff --git a/tools/doctype/rename_tool/rename_tool.py b/tools/doctype/rename_tool/rename_tool.py
index 9b91193..ea12433 100644
--- a/tools/doctype/rename_tool/rename_tool.py
+++ b/tools/doctype/rename_tool/rename_tool.py
@@ -12,9 +12,9 @@
# call on_rename method if exists
obj = get_obj(self.doc.select_doctype, self.doc.document_to_rename)
if hasattr(obj, 'on_rename'):
- obj.on_rename(self.doc.new_name)
-
- # rename the document
+ obj.on_rename(self.doc.new_name,self.doc.document_to_rename)
+
+ # rename the document
webnotes.model.rename(self.doc.select_doctype, self.doc.document_to_rename, self.doc.new_name)
- webnotes.msgprint("Item renamed successfully")
\ No newline at end of file
+ webnotes.msgprint("Successfully renamed "+self.doc.select_doctype+" : '"+self.doc.document_to_rename+"' to <b>"+self.doc.new_name+"</b>")
diff --git a/tools/doctype/rename_tool/rename_tool.txt b/tools/doctype/rename_tool/rename_tool.txt
index 5947e67..497a6cc 100755
--- a/tools/doctype/rename_tool/rename_tool.txt
+++ b/tools/doctype/rename_tool/rename_tool.txt
@@ -1,6 +1,6 @@
[
{
- '_last_update': '1308739509',
+ '_last_update': '1309348691',
'allow_attach': None,
'allow_copy': None,
'allow_email': 1,
@@ -13,7 +13,7 @@
'client_script_core': None,
'client_string': None,
'colour': 'White:FFF',
- 'creation': '2011-06-23 11:03:25',
+ 'creation': '2011-06-22 18:42:33',
'description': None,
'docstatus': 0,
'doctype': 'DocType',
@@ -29,7 +29,7 @@
'istable': None,
'max_attachments': None,
'menu_index': None,
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
'module': 'Tools',
'name': 'Rename Tool',
@@ -53,21 +53,21 @@
'subject': None,
'tag_fields': None,
'use_template': None,
- 'version': 6
+ 'version': 7
},
{
'amend': None,
'cancel': None,
'create': 1,
- 'creation': '2011-06-23 11:03:25',
+ 'creation': '2011-06-22 18:42:33',
'docstatus': 0,
'doctype': 'DocPerm',
'execute': None,
'idx': 1,
'match': None,
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
- 'name': 'PERM00859',
+ 'name': 'PERM00833',
'owner': 'Administrator',
'parent': 'Rename Tool',
'parentfield': 'permissions',
@@ -80,8 +80,8 @@
},
{
'allow_on_submit': None,
- 'colour': None,
- 'creation': '2011-06-23 11:03:25',
+ 'colour': 'White:FFF',
+ 'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@@ -94,14 +94,14 @@
'idx': 1,
'in_filter': None,
'label': 'Select DocType',
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
- 'name': 'FL05599',
+ 'name': 'FL05557',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
'oldfieldtype': None,
- 'options': 'link:DocType',
+ 'options': '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem',
'owner': 'Administrator',
'parent': 'Rename Tool',
'parentfield': 'fields',
@@ -117,7 +117,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-23 11:03:25',
+ 'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@@ -130,9 +130,9 @@
'idx': 2,
'in_filter': None,
'label': 'Document to rename',
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
- 'name': 'FL05600',
+ 'name': 'FL05558',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -153,7 +153,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-23 11:03:25',
+ 'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@@ -166,9 +166,9 @@
'idx': 3,
'in_filter': None,
'label': 'New Name',
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
- 'name': 'FL05601',
+ 'name': 'FL05559',
'no_column': None,
'no_copy': None,
'oldfieldname': None,
@@ -189,7 +189,7 @@
{
'allow_on_submit': None,
'colour': None,
- 'creation': '2011-06-23 11:03:25',
+ 'creation': '2011-06-22 18:42:33',
'default': None,
'depends_on': None,
'description': None,
@@ -202,9 +202,9 @@
'idx': 4,
'in_filter': None,
'label': 'Rename',
- 'modified': '2011-06-23 11:03:25',
+ 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator',
- 'name': 'FL05602',
+ 'name': 'FL05560',
'no_column': None,
'no_copy': None,
'oldfieldname': None,