Rename Tool updates

This commit is contained in:
Ravi Dey 2011-07-01 13:50:34 +05:30
parent c1c54c9400
commit 94a332a8ab
9 changed files with 667 additions and 595 deletions

View File

@ -72,6 +72,7 @@ cur_frm.fields_dict['master_name'].get_query=function(doc){
else alert("Please select master type"); else alert("Please select master type");
} }
/*
// Get customer/supplier address // Get customer/supplier address
// ----------------------------------------- // -----------------------------------------
cur_frm.cscript.master_name = function(doc,cdt,cdn){ cur_frm.cscript.master_name = function(doc,cdt,cdn){
@ -79,6 +80,7 @@ cur_frm.cscript.master_name = function(doc,cdt,cdn){
get_server_fields('get_address','','',doc,cdt,cdn); get_server_fields('get_address','','',doc,cdt,cdn);
} }
} }
*/
// parent account get query // parent account get query
// ----------------------------------------- // -----------------------------------------

View File

@ -260,3 +260,16 @@ class DocType:
def on_restore(self): def on_restore(self):
# rebuild tree # rebuild tree
self.update_nsm_model() 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))

View File

@ -10,221 +10,248 @@ set = webnotes.conn.set
sql = webnotes.conn.sql sql = webnotes.conn.sql
get_value = webnotes.conn.get_value get_value = webnotes.conn.get_value
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
class DocType: class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
# ******************************************************* autoname *********************************************************** # ******************************************************* autoname ***********************************************************
def autoname(self): def autoname(self):
cust_master_name = get_defaults().get('cust_master_name') cust_master_name = get_defaults().get('cust_master_name')
if cust_master_name == 'Customer Name': if cust_master_name == 'Customer Name':
# filter out bad characters in name
# filter out bad characters in name #cust = self.doc.customer_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
#cust = self.doc.customer_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','') cust = self.doc.customer_name
cust = self.doc.customer_name
supp = sql("select name from `tabSupplier` where name = %s", (cust)) supp = sql("select name from `tabSupplier` where name = %s", (cust))
supp = supp and supp[0][0] or '' supp = supp and supp[0][0] or ''
if supp: if supp:
msgprint("You already have a Supplier with same name") msgprint("You already have a Supplier with same name")
raise Exception raise Exception
else: else:
self.doc.name = cust self.doc.name = cust
else:
else: self.doc.name = make_autoname(self.doc.naming_series+'.#####')
self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ******************************************************* triggers *********************************************************** # ******************************************************* triggers ***********************************************************
# ---------------- # ----------------
# get company abbr # get company abbr
# ----------------- # -----------------
def get_company_abbr(self): def get_company_abbr(self):
return get_value('Company', self.doc.company, 'abbr') 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) # get parent account(i.e receivables group from company where default account head need to be created)
# ----------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------
def get_receivables_group(self): def get_receivables_group(self):
g = sql("select receivables_group from tabCompany where name=%s", self.doc.company) g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or '' g = g and g[0][0] or ''
if not g: if not g:
msgprint("Update Company master, assign a default group for Receivables") msgprint("Update Company master, assign a default group for Receivables")
raise Exception raise Exception
return g return g
# ******************************************************* validate ********************************************************* # ******************************************************* validate *********************************************************
# ---------------- # ----------------
# validate values # validate values
# ---------------- # ----------------
def validate_values(self): def validate_values(self):
# Master name by naming series -> Series field mandatory # Master name by naming series -> Series field mandatory
if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series: if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
msgprint("Series is Mandatory.") msgprint("Series is Mandatory.")
raise Exception raise Exception
# --------- # ---------
# validate # validate
# --------- # ---------
def validate(self): def validate(self):
self.validate_values() self.validate_values()
# ******************************************************* on update ********************************************************* # ******************************************************* on update *********************************************************
# ------------------------ # ------------------------
# create customer address # create customer address
# ------------------------ # ------------------------
def create_customer_address(self): 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] 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)) address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
if self.doc.phone_1: if self.doc.phone_1:
address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1) address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
if self.doc.email_id: if self.doc.email_id:
address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id) address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
set(self.doc,'address', address_line) 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) 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) set(self.doc,'telephone',telephone)
# ------------------------------------ # ------------------------------------
# create primary contact for customer # create primary contact for customer
# ------------------------------------ # ------------------------------------
def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr): def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
c1 = Document('Contact') c1 = Document('Contact')
c1.first_name = nm c1.first_name = nm
c1.contact_name = nm c1.contact_name = nm
c1.contact_no = phn_no c1.contact_no = phn_no
c1.email_id = email_id c1.email_id = email_id
c1.mobile_no = mob_no c1.mobile_no = mob_no
c1.fax = fax c1.fax = fax
c1.contact_address = cont_addr c1.contact_address = cont_addr
c1.is_primary_contact = 'Yes' c1.is_primary_contact = 'Yes'
c1.is_customer =1 c1.is_customer =1
c1.customer = self.doc.name c1.customer = self.doc.name
c1.customer_name = self.doc.customer_name c1.customer_name = self.doc.customer_name
c1.customer_address = self.doc.address c1.customer_address = self.doc.address
c1.customer_group = self.doc.customer_group c1.customer_group = self.doc.customer_group
c1.save(1) c1.save(1)
# ------------------------ # ------------------------
# create customer contact # create customer contact
# ------------------------ # ------------------------
def create_customer_contact(self): def create_customer_contact(self):
contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name)) contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
contact = contact and contact[0][0] or '' contact = contact and contact[0][0] or ''
if not contact: if not contact:
# create primary contact for individual customer # create primary contact for individual customer
if self.doc.customer_type == 'Individual': 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) 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 # create primary contact for lead
elif self.doc.lead_name: 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) 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 '') 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 # update lead status
# ------------------- # -------------------
def update_lead_status(self): def update_lead_status(self):
if self.doc.lead_name: if self.doc.lead_name:
sql("update `tabLead` set status='Converted' where name = %s", 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 # create accont head - in tree under receivables_group of selected company
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
def create_account_head(self): def create_account_head(self):
if self.doc.company : if self.doc.company :
abbr = self.get_company_abbr() abbr = self.get_company_abbr()
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)): if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
parent_account = self.get_receivables_group() 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} 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 # create
ac = get_obj('GL Control').add_ac(cstr(arg)) ac = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Account Head created for "+ac) msgprint("Account Head created for "+ac)
else : else :
msgprint("Please Select Company under which you want to create account head") msgprint("Please Select Company under which you want to create account head")
# ---------------------------------------- # ----------------------------------------
# update credit days and limit in account # update credit days and limit in account
# ---------------------------------------- # ----------------------------------------
def update_credit_days_limit(self): 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())) 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 #create address and contact from lead
def create_lead_address_contact(self): def create_lead_address_contact(self):
if self.doc.lead_name: 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) 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 = Document('Address')
d.address_line1 = details[0]['address_line1'] d.address_line1 = details[0]['address_line1']
d.address_line2 = details[0]['address_line2'] d.address_line2 = details[0]['address_line2']
d.city = details[0]['city'] d.city = details[0]['city']
d.country = details[0]['country'] d.country = details[0]['country']
d.pincode = details[0]['pincode'] d.pincode = details[0]['pincode']
d.state = details[0]['state'] d.state = details[0]['state']
d.fax = details[0]['fax'] d.fax = details[0]['fax']
d.email_id = details[0]['email_id'] d.email_id = details[0]['email_id']
d.phone = details[0]['contact_no'] d.phone = details[0]['phone']
d.customer = self.doc.name d.customer = self.doc.name
d.customer_name = self.doc.customer_name d.customer_name = self.doc.customer_name
d.is_primary_address = 1 d.is_primary_address = 1
d.address_type = 'Office' d.address_type = 'Office'
try: try:
d.save(1) d.save(1)
except NameError, e: except NameError, e:
pass pass
c = Document('Contact') c = Document('Contact')
c.first_name = details[0]['lead_name'] c.first_name = details[0]['lead_name']
c.email_id = details[0]['email_id'] c.email_id = details[0]['email_id']
c.phone = details[0]['contact_no'] c.phone = details[0]['phone']
c.phone = details[0]['contact_no'] c.mobile_no = details[0]['mobile_no']
c.customer = self.doc.name c.customer = self.doc.name
c.customer_name = self.doc.customer_name c.customer_name = self.doc.customer_name
c.is_primary_contact = 1 c.is_primary_contact = 1
try: try:
c.save(1) c.save(1)
except NameError, e: except NameError, e:
pass pass
# ---------- # ----------
# on update # on update
# ---------- # ----------
def on_update(self): def on_update(self):
# create customer addr # create customer addr
#self.create_customer_address() #self.create_customer_address()
# create customer contact # create customer contact
#self.create_customer_contact() #self.create_customer_contact()
# update lead status # update lead status
self.update_lead_status() self.update_lead_status()
# create account head # create account head
self.create_account_head() self.create_account_head()
# update credit days and limit in account # update credit days and limit in account
self.update_credit_days_limit() self.update_credit_days_limit()
#create address and contact from lead #create address and contact from lead
self.create_lead_address_contact() self.create_lead_address_contact()
def delete_customer_address(self): def delete_customer_address(self):
for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1): 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'])) sql("delete from `tabAddress` where name=%s",(rec['name']))
def delete_customer_contact(self): def delete_customer_contact(self):
for rec in sql("select * from `tabContact` where customer='%s'" %(self.doc.name), as_dict=1): 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'])) sql("delete from `tabContact` where name=%s",(rec['name']))
# ******************************************************* on trash ********************************************************* # ******************************************************* on trash *********************************************************
def on_trash(self): def on_trash(self):
self.delete_customer_address() self.delete_customer_address()
self.delete_customer_contact() self.delete_customer_contact()
if self.doc.lead_name: if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",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))

View File

@ -1,6 +1,6 @@
# REMEMBER to update this # REMEMBER to update this
# ======================== # ========================
last_patch = 305 last_patch = 306
#------------------------------------------- #-------------------------------------------
@ -1187,9 +1187,9 @@ def execute(patch_no):
reload_doc('payroll', 'doctype', 'salary_structure') reload_doc('payroll', 'doctype', 'salary_structure')
reload_doc('payroll', 'doctype', 'salary_slip') reload_doc('payroll', 'doctype', 'salary_slip')
elif patch_no == 298: 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 = '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 = '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 = 'Appraisal' and fieldname = 'company'")
elif patch_no == 299: elif patch_no == 299:
sql("update `tabDocPerm` set `match` = NULL where parent = 'Employee' and role = 'Employee'") sql("update `tabDocPerm` set `match` = NULL where parent = 'Employee' and role = 'Employee'")
elif patch_no == 300: elif patch_no == 300:
@ -1207,3 +1207,9 @@ def execute(patch_no):
reload_doc('setup', 'doctype', 'company') reload_doc('setup', 'doctype', 'company')
elif patch_no == 305: elif patch_no == 305:
sql("update `tabDocField` set options = 'link:Company' where options='link:Company' and fieldname='company' and fieldtype='Select'") 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')

View File

@ -13,234 +13,239 @@ sql = webnotes.conn.sql
get_value = webnotes.conn.get_value get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
class DocType: class DocType:
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d,dl self.doc, self.doclist = d,dl
# Create default accounts # Create default accounts
# --------------------------------------------------- # ---------------------------------------------------
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 = [['Application of Funds (Assets)','','Group','No','','Debit',self.doc.name,''], 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,''], ['Current Assets','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
['Accounts Receivable','Current 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,''], ['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 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,''], ['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,''], ['Loans and Advances (Assets)','Current Assets','Group','No','','Debit',self.doc.name,''],
['Securities and Deposits','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,''], ['Earnest Money','Securities and Deposits','Ledger','No','','Debit',self.doc.name,''],
['Stock In Hand','Current Assets','Group','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,''], ['Stock','Stock In Hand','Ledger','No','','Debit',self.doc.name,''],
['Tax Assets','Current Assets','Group','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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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 Accounts (Assets)','Application of Funds (Assets)','Group','No','','Debit',self.doc.name,''],
['Temporary Account (Assets)','Temporary Accounts (Assets)','Ledger','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,''], ['Source of Funds (Liabilities)','','Group','No','','Credit',self.doc.name,''],
['Capital Account','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,''], ['Reserves and Surplus','Capital Account','Group','No','','Credit',self.doc.name,''],
['Shareholders Funds','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,''], ['Current Liabilities','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
['Accounts Payable','Current 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,''], ['Duties and Taxes','Current Liabilities','Group','No','','Credit',self.doc.name,''],
['Loans (Liabilities)','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,''], ['Secured Loans','Loans (Liabilities)','Group','No','','Credit',self.doc.name,''],
['Unsecured 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,''], ['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 Accounts (Liabilities)','Source of Funds (Liabilities)','Group','No','','Credit',self.doc.name,''],
['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,''], ['Temporary Account (Liabilities)','Temporary Accounts (Liabilities)','Ledger','No','','Credit',self.doc.name,''],
['Income','','Group','Yes','','Credit',self.doc.name,''], ['Income','','Group','Yes','','Credit',self.doc.name,''],
['Direct Income','Income','Group','Yes','Income Account','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,''], ['Sales','Direct Income','Ledger','Yes','Income Account','Credit',self.doc.name,''],
['Service','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,''], ['Indirect Income','Income','Group','Yes','Income Account','Credit',self.doc.name,''],
['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''], ['Expenses','','Group','Yes','Expense Account','Debit',self.doc.name,''],
['Direct Expenses','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,''], ['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,''], ['Indirect Expenses','Expenses','Group','Yes','Expense Account','Debit',self.doc.name,''],
['Advertising and Publicity','Indirect Expenses','Ledger','Yes','Chargeable','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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['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,''], ['Legal Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
['Miscellaneous Expenses','Indirect Expenses','Ledger','Yes','Chargeable','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 Maintenance Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
['Office Rent','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,''], ['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,''], ['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,''], ['Rounded Off','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
['Salary','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,''], ['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,''], ['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,''], ['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,''], ['Telephone Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,''],
['Travelling 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,''] ['Water and Electricity Expenses','Indirect Expenses','Ledger','Yes','Expense Account','Debit',self.doc.name,'']
] ]
acc_list_india = [ acc_list_india = [
['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''], ['CENVAT Capital Goods','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
['CENVAT','Tax Assets','Ledger','No','Chargeable','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','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 1','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
['CENVAT Service Tax Cess 2','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 Edu Cess','Tax Assets','Ledger','No','Chargeable','Debit',self.doc.name,''],
['CENVAT SHE 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 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 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 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 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 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'], ['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','Tax Assets','Ledger','No','','Debit',self.doc.name,''],
['P L A - Cess Portion','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 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 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'], ['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 @ 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 @ 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 @ 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'], ['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'], ['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 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 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'], ['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,''], ['Professional Tax','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
['VAT','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 (Advertisement)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
['TDS (Commission)','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 (Contractor)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
['TDS (Interest)','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 (Rent)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''],
['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,''] ['TDS (Salary)','Duties and Taxes','Ledger','No','','Credit',self.doc.name,'']
] ]
# load common account heads # load common account heads
for d in acc_list_common: for d in acc_list_common:
self.add_acc(d) self.add_acc(d)
country = sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'") country = sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'")
country = country and cstr(country[0][0]) or '' country = country and cstr(country[0][0]) or ''
# load taxes (only for India) # load taxes (only for India)
if country == 'India': if country == 'India':
for d in acc_list_india: for d in acc_list_india:
self.add_acc(d) self.add_acc(d)
# Create account # Create account
# --------------------------------------------------- # ---------------------------------------------------
def add_acc(self,lst): def add_acc(self,lst):
ac = Document('Account') ac = Document('Account')
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]] 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.old_parent = ''
ac_obj = get_obj(doc=ac) ac_obj = get_obj(doc=ac)
ac_obj.validate() ac_obj.validate()
ac_obj.doc.save(1) ac_obj.doc.save(1)
ac_obj.on_update() ac_obj.on_update()
sql("commit") sql("commit")
sql("start transaction") sql("start transaction")
# Set letter head # Set letter head
# --------------------------------------------------- # ---------------------------------------------------
def set_letter_head(self): def set_letter_head(self):
if not self.doc.letter_head: if not self.doc.letter_head:
if self.doc.address: if self.doc.address:
header = """ header = """
<div><h3> %(comp)s </h3> %(add)s </div> <div><h3> %(comp)s </h3> %(add)s </div>
""" % {'comp':self.doc.name, """ % {'comp':self.doc.name,
'add':self.doc.address.replace("\n",'<br>')} 'add':self.doc.address.replace("\n",'<br>')}
self.doc.letter_head = header self.doc.letter_head = header
# Set default AR and AP group # Set default AR and AP group
# --------------------------------------------------- # ---------------------------------------------------
def set_default_groups(self): def set_default_groups(self):
if not self.doc.receivables_group: if not self.doc.receivables_group:
set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr) set(self.doc, 'receivables_group', 'Accounts Receivable - '+self.doc.abbr)
if not self.doc.payables_group: if not self.doc.payables_group:
set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr) set(self.doc, 'payables_group', 'Accounts Payable - '+self.doc.abbr)
# Create default cost center # Create default cost center
# --------------------------------------------------- # ---------------------------------------------------
def create_default_cost_center(self): def create_default_cost_center(self):
glc = get_obj('GL Control') 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':''}] 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: for c in cc_list:
glc.add_cc(str(c)) glc.add_cc(str(c))
# On update # On update
# --------------------------------------------------- # ---------------------------------------------------
def on_update(self): def on_update(self):
self.set_letter_head() self.set_letter_head()
ac = sql("select name from tabAccount where account_name='Income' and company=%s", self.doc.name) ac = sql("select name from tabAccount where account_name='Income' and company=%s", self.doc.name)
if not ac: if not ac:
self.create_default_accounts() self.create_default_accounts()
self.set_default_groups() self.set_default_groups()
cc = sql("select name from `tabCost Center` where cost_center_name = 'Root' and company_name = '%s'"%(self.doc.name)) cc = sql("select name from `tabCost Center` where cost_center_name = 'Root' and company_name = '%s'"%(self.doc.name))
if not cc: if not cc:
self.create_default_cost_center() self.create_default_cost_center()
# Trash accounts and cost centers for this company # Trash accounts and cost centers for this company
# --------------------------------------------------- # ---------------------------------------------------
#def on_trash1(self): #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) # 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: # for each in acc:
# get_obj('Account', each[0]).on_trash() # get_obj('Account', each[0]).on_trash()
# cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name) # cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus != 2" % self.doc.name)
# for each in cc: # for each in cc:
# get_obj('Cost Center', each[0]).on_trash() # 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") # 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): 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) 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: if rec[0][0] == 0 and rec[0][1] == 0 and rec[0][2] == 0 and rec[0][3] == 0:
#delete tabAccount Balance #delete tabAccount Balance
sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name) sql("delete ab.* from `tabAccount Balance` ab, `tabAccount` a where ab.account = a.name and a.company = %s", self.doc.name)
#delete tabAccount #delete tabAccount
sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name) sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name)
#delete cost center child table - budget detail #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) 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 #delete cost center
sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name) 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 #update value as blank for tabDefaultValue defkey=company
sql("update `tabDefaultValue` set defvalue = '' where defkey='company' and defvalue = %s", self.doc.name) sql("update `tabDefaultValue` set defvalue = '' where defkey='company' and defvalue = %s", self.doc.name)
#update value as blank for tabSingles Manage Account #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) 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 # Restore accounts and cost centers for this company
# --------------------------------------------------- # ---------------------------------------------------
def on_restore(self): def on_restore(self):
acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name) acc = sql("select name from tabAccount where company = '%s' and docstatus = 2" % self.doc.name)
for each in acc: for each in acc:
get_obj('Account', each[0]).on_restore() get_obj('Account', each[0]).on_restore()
cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 2" % self.doc.name) cc = sql("select name from `tabCost Center` where company_name = '%s' and docstatus = 2" % self.doc.name)
for each in cc: for each in cc:
get_obj('Cost Center', each[0]).on_restore() get_obj('Cost Center', each[0]).on_restore()
msgprint("Company restored. All the accounts and cost centers related to this company also restored.") 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))

View File

@ -1,6 +1,6 @@
[ [
{ {
'_last_update': '1309168616', '_last_update': '1309506817',
'allow_attach': None, 'allow_attach': None,
'allow_copy': None, 'allow_copy': None,
'allow_email': None, 'allow_email': None,
@ -29,7 +29,7 @@
'istable': None, 'istable': None,
'max_attachments': None, 'max_attachments': None,
'menu_index': None, 'menu_index': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'module': 'Setup', 'module': 'Setup',
'name': 'Company', 'name': 'Company',
@ -53,7 +53,7 @@
'subject': None, 'subject': None,
'tag_fields': None, 'tag_fields': None,
'use_template': None, 'use_template': None,
'version': 91 'version': 92
}, },
{ {
'amend': 0, 'amend': 0,
@ -65,7 +65,7 @@
'execute': None, 'execute': None,
'idx': 1, 'idx': 1,
'match': None, 'match': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'PERM00119', 'name': 'PERM00119',
'owner': 'Administrator', 'owner': 'Administrator',
@ -79,8 +79,8 @@
'write': 1 'write': 1
}, },
{ {
'amend': 1, 'amend': 0,
'cancel': 1, 'cancel': 0,
'create': 1, 'create': 1,
'creation': '2010-08-08 17:08:55', 'creation': '2010-08-08 17:08:55',
'docstatus': 0, 'docstatus': 0,
@ -88,7 +88,7 @@
'execute': None, 'execute': None,
'idx': 2, 'idx': 2,
'match': None, 'match': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'PERM00120', 'name': 'PERM00120',
'owner': 'Administrator', 'owner': 'Administrator',
@ -103,17 +103,17 @@
}, },
{ {
'amend': None, 'amend': None,
'cancel': None, 'cancel': 0,
'create': None, 'create': None,
'creation': '2011-06-29 18:02:47', 'creation': '2010-08-08 17:08:55',
'docstatus': 0, 'docstatus': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'execute': None, 'execute': None,
'idx': 3, 'idx': 3,
'match': None, 'match': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'PERM00859', 'name': 'PERM00121',
'owner': 'Administrator', 'owner': 'Administrator',
'parent': 'Company', 'parent': 'Company',
'parentfield': 'permissions', 'parentfield': 'permissions',
@ -127,7 +127,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-29 17:48:40', 'creation': '2011-07-01 13:23:37',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': 'Please Enter Company Name and Abbr and save the document. Once saved Accounting Settings will be populated automatically', '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, 'idx': 1,
'in_filter': None, 'in_filter': None,
'label': 'Details', 'label': 'Details',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05478', 'name': 'FL05650',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -176,7 +176,7 @@
'idx': 2, 'idx': 2,
'in_filter': None, 'in_filter': None,
'label': 'Company', 'label': 'Company',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00695', 'name': 'FL00695',
'no_column': None, 'no_column': None,
@ -212,7 +212,7 @@
'idx': 3, 'idx': 3,
'in_filter': None, 'in_filter': None,
'label': 'Abbr', 'label': 'Abbr',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00696', 'name': 'FL00696',
'no_column': None, 'no_column': None,
@ -248,7 +248,7 @@
'idx': 4, 'idx': 4,
'in_filter': None, 'in_filter': None,
'label': 'Address', 'label': 'Address',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00697', 'name': 'FL00697',
'no_column': None, 'no_column': None,
@ -271,7 +271,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-04-19 17:40:13', 'creation': '2011-04-19 18:48:56',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -284,9 +284,9 @@
'idx': 5, 'idx': 5,
'in_filter': None, 'in_filter': None,
'label': 'Default Currency', 'label': 'Default Currency',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': '000003935', 'name': '000031318',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -307,7 +307,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-29 17:48:40', 'creation': '2011-07-01 13:23:37',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -320,9 +320,9 @@
'idx': 6, 'idx': 6,
'in_filter': None, 'in_filter': None,
'label': None, 'label': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05479', 'name': 'FL05651',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -356,7 +356,7 @@
'idx': 7, 'idx': 7,
'in_filter': None, 'in_filter': None,
'label': 'Phone No', 'label': 'Phone No',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00699', 'name': 'FL00699',
'no_column': None, 'no_column': None,
@ -392,7 +392,7 @@
'idx': 8, 'idx': 8,
'in_filter': None, 'in_filter': None,
'label': 'Email', 'label': 'Email',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00700', 'name': 'FL00700',
'no_column': None, 'no_column': None,
@ -428,7 +428,7 @@
'idx': 9, 'idx': 9,
'in_filter': None, 'in_filter': None,
'label': 'Fax', 'label': 'Fax',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00701', 'name': 'FL00701',
'no_column': None, 'no_column': None,
@ -464,7 +464,7 @@
'idx': 10, 'idx': 10,
'in_filter': None, 'in_filter': None,
'label': 'Website', 'label': 'Website',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00702', 'name': 'FL00702',
'no_column': None, 'no_column': None,
@ -487,7 +487,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': 'White:FFF', 'colour': 'White:FFF',
'creation': '2011-06-29 17:48:40', 'creation': '2011-07-01 13:23:37',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': 'Company registration numbers for your reference. Example: VAT Registration Numbers etc.', 'description': 'Company registration numbers for your reference. Example: VAT Registration Numbers etc.',
@ -500,9 +500,9 @@
'idx': 11, 'idx': 11,
'in_filter': None, 'in_filter': None,
'label': 'Registration Info', 'label': 'Registration Info',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05480', 'name': 'FL05652',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -536,7 +536,7 @@
'idx': 12, 'idx': 12,
'in_filter': None, 'in_filter': None,
'label': 'Registration Details', 'label': 'Registration Details',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00704', 'name': 'FL00704',
'no_column': None, 'no_column': None,
@ -559,7 +559,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-29 17:48:40', 'creation': '2011-07-01 13:23:37',
'default': None, 'default': None,
'depends_on': 'eval:!doc.__islocal', 'depends_on': 'eval:!doc.__islocal',
'description': None, 'description': None,
@ -572,9 +572,9 @@
'idx': 13, 'idx': 13,
'in_filter': None, 'in_filter': None,
'label': 'Accounting Settings', 'label': 'Accounting Settings',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05481', 'name': 'FL05653',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -608,7 +608,7 @@
'idx': 14, 'idx': 14,
'in_filter': None, 'in_filter': None,
'label': 'Default Bank Account', 'label': 'Default Bank Account',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00706', 'name': 'FL00706',
'no_column': None, 'no_column': None,
@ -644,7 +644,7 @@
'idx': 15, 'idx': 15,
'in_filter': None, 'in_filter': None,
'label': 'Receivables Group', 'label': 'Receivables Group',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00707', 'name': 'FL00707',
'no_column': None, 'no_column': None,
@ -680,7 +680,7 @@
'idx': 16, 'idx': 16,
'in_filter': None, 'in_filter': None,
'label': 'Payables Group', 'label': 'Payables Group',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00708', 'name': 'FL00708',
'no_column': None, 'no_column': None,
@ -703,7 +703,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-29 17:48:40', 'creation': '2011-07-01 13:23:37',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -716,9 +716,9 @@
'idx': 17, 'idx': 17,
'in_filter': None, 'in_filter': None,
'label': None, 'label': None,
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05482', 'name': 'FL05654',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -752,7 +752,7 @@
'idx': 18, 'idx': 18,
'in_filter': None, 'in_filter': None,
'label': 'If Yearly Budget Exceeded', 'label': 'If Yearly Budget Exceeded',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00710', 'name': 'FL00710',
'no_column': None, 'no_column': None,
@ -788,7 +788,7 @@
'idx': 19, 'idx': 19,
'in_filter': None, 'in_filter': None,
'label': 'If Monthly Budget Exceeded', 'label': 'If Monthly Budget Exceeded',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00711', 'name': 'FL00711',
'no_column': None, 'no_column': None,
@ -824,7 +824,7 @@
'idx': 20, 'idx': 20,
'in_filter': None, 'in_filter': None,
'label': 'Credit Days', 'label': 'Credit Days',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00712', 'name': 'FL00712',
'no_column': None, 'no_column': None,
@ -860,7 +860,7 @@
'idx': 21, 'idx': 21,
'in_filter': None, 'in_filter': None,
'label': 'Credit Limit', 'label': 'Credit Limit',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00713', 'name': 'FL00713',
'no_column': None, 'no_column': None,
@ -896,7 +896,7 @@
'idx': 22, 'idx': 22,
'in_filter': None, 'in_filter': None,
'label': 'Trash Reason', 'label': 'Trash Reason',
'modified': '2011-06-29 18:02:47', 'modified': '2011-07-01 13:46:45',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL00716', 'name': 'FL00716',
'no_column': None, 'no_column': None,

View File

@ -13,136 +13,155 @@ sql = webnotes.conn.sql
get_value = webnotes.conn.get_value get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------
class DocType: class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
def autoname(self): def autoname(self):
#get default naming conventional from control panel #get default naming conventional from control panel
supp_master_name = get_defaults()['supp_master_name'] supp_master_name = get_defaults()['supp_master_name']
if supp_master_name == 'Supplier Name': if supp_master_name == 'Supplier Name':
# filter out bad characters in name # filter out bad characters in name
#supp = self.doc.supplier_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','') #supp = self.doc.supplier_name.replace('&','and').replace('.','').replace("'",'').replace('"','').replace(',','').replace('`','')
supp = self.doc.supplier_name supp = self.doc.supplier_name
cust = sql("select name from `tabCustomer` where name = '%s'" % (supp)) cust = sql("select name from `tabCustomer` where name = '%s'" % (supp))
cust = cust and cust[0][0] or '' cust = cust and cust[0][0] or ''
if cust: if cust:
msgprint("You already have a Customer with same name") msgprint("You already have a Customer with same name")
raise Exception raise Exception
self.doc.name = supp self.doc.name = supp
else: else:
self.doc.name = make_autoname(self.doc.naming_series+'.#####') self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ---------------------------------------- # ----------------------------------------
# update credit days and limit in account # update credit days and limit in account
# ---------------------------------------- # ----------------------------------------
def update_credit_days_limit(self): 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())) 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): def on_update(self):
if not self.doc.naming_series: if not self.doc.naming_series:
self.doc.naming_series = '' self.doc.naming_series = ''
# create address # create address
addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode] 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)) address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
set(self.doc,'address', address_line) set(self.doc,'address', address_line)
# create account head # create account head
self.create_account_head() self.create_account_head()
# update credit days and limit in account # update credit days and limit in account
self.update_credit_days_limit() self.update_credit_days_limit()
def check_state(self): 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)]) return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# ACCOUNTS # ACCOUNTS
# ------------------------------------------- # -------------------------------------------
def get_payables_group(self): def get_payables_group(self):
g = sql("select payables_group from tabCompany where name=%s", self.doc.company) g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or '' g = g and g[0][0] or ''
if not g: if not g:
msgprint("Update Company master, assign a default group for Payables") msgprint("Update Company master, assign a default group for Payables")
raise Exception raise Exception
return g return g
def add_account(self, ac, par, 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'} 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)) t = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Created Group " + t) msgprint("Created Group " + t)
def get_company_abbr(self): def get_company_abbr(self):
return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0] return sql("select abbr from tabCompany where name=%s", self.doc.company)[0][0]
def get_parent_account(self, abbr): def get_parent_account(self, abbr):
if (not self.doc.supplier_type): if (not self.doc.supplier_type):
msgprint("Supplier Type is mandatory") msgprint("Supplier Type is mandatory")
raise Exception raise Exception
if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)): if not sql("select name from tabAccount where name=%s", (self.doc.supplier_type + " - " + abbr)):
# if not group created , create it # if not group created , create it
self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr) self.add_account(self.doc.supplier_type, self.get_payables_group(), abbr)
return self.doc.supplier_type + " - " + abbr return self.doc.supplier_type + " - " + abbr
def validate(self): def validate(self):
#validation for Naming Series mandatory field... #validation for Naming Series mandatory field...
if get_defaults()['supp_master_name'] == 'Naming Series': if get_defaults()['supp_master_name'] == 'Naming Series':
if not self.doc.naming_series: if not self.doc.naming_series:
msgprint("Series is Mandatory.") msgprint("Series is Mandatory.")
raise Exception raise Exception
# create accont head - in tree under zone + territory # create accont head - in tree under zone + territory
# ------------------------------------------------------- # -------------------------------------------------------
def create_account_head(self): def create_account_head(self):
if self.doc.company : if self.doc.company :
abbr = self.get_company_abbr() abbr = self.get_company_abbr()
if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)): if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)):
parent_account = self.get_parent_account(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} 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 # create
ac = get_obj('GL Control').add_ac(cstr(arg)) ac = get_obj('GL Control').add_ac(cstr(arg))
msgprint("Created Account Head: "+ac) msgprint("Created Account Head: "+ac)
else : else :
msgprint("Please select Company under which you want to create account head") msgprint("Please select Company under which you want to create account head")
def get_contacts(self,nm): def get_contacts(self,nm):
if 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)) 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 return contact_details
else: else:
return '' return ''
def delete_supplier_address(self): def delete_supplier_address(self):
for rec in sql("select * from `tabAddress` where supplier='%s'" %(self.doc.name), as_dict=1): 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'])) sql("delete from `tabAddress` where name=%s",(rec['name']))
def delete_supplier_contact(self): def delete_supplier_contact(self):
for rec in sql("select * from `tabContact` where supplier='%s'" %(self.doc.name), as_dict=1): 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'])) sql("delete from `tabContact` where name=%s",(rec['name']))
def on_trash(self): def on_trash(self):
self.delete_supplier_address() self.delete_supplier_address()
self.delete_supplier_contact() 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))

View File

@ -12,9 +12,9 @@ class DocType:
# call on_rename method if exists # call on_rename method if exists
obj = get_obj(self.doc.select_doctype, self.doc.document_to_rename) obj = get_obj(self.doc.select_doctype, self.doc.document_to_rename)
if hasattr(obj, 'on_rename'): if hasattr(obj, 'on_rename'):
obj.on_rename(self.doc.new_name) obj.on_rename(self.doc.new_name,self.doc.document_to_rename)
# rename the document # rename the document
webnotes.model.rename(self.doc.select_doctype, self.doc.document_to_rename, self.doc.new_name) webnotes.model.rename(self.doc.select_doctype, self.doc.document_to_rename, self.doc.new_name)
webnotes.msgprint("Item renamed successfully") webnotes.msgprint("Successfully renamed "+self.doc.select_doctype+" : '"+self.doc.document_to_rename+"' to <b>"+self.doc.new_name+"</b>")

View File

@ -1,6 +1,6 @@
[ [
{ {
'_last_update': '1308739509', '_last_update': '1309348691',
'allow_attach': None, 'allow_attach': None,
'allow_copy': None, 'allow_copy': None,
'allow_email': 1, 'allow_email': 1,
@ -13,7 +13,7 @@
'client_script_core': None, 'client_script_core': None,
'client_string': None, 'client_string': None,
'colour': 'White:FFF', 'colour': 'White:FFF',
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'description': None, 'description': None,
'docstatus': 0, 'docstatus': 0,
'doctype': 'DocType', 'doctype': 'DocType',
@ -29,7 +29,7 @@
'istable': None, 'istable': None,
'max_attachments': None, 'max_attachments': None,
'menu_index': None, 'menu_index': None,
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'module': 'Tools', 'module': 'Tools',
'name': 'Rename Tool', 'name': 'Rename Tool',
@ -53,21 +53,21 @@
'subject': None, 'subject': None,
'tag_fields': None, 'tag_fields': None,
'use_template': None, 'use_template': None,
'version': 6 'version': 7
}, },
{ {
'amend': None, 'amend': None,
'cancel': None, 'cancel': None,
'create': 1, 'create': 1,
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'docstatus': 0, 'docstatus': 0,
'doctype': 'DocPerm', 'doctype': 'DocPerm',
'execute': None, 'execute': None,
'idx': 1, 'idx': 1,
'match': None, 'match': None,
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'PERM00859', 'name': 'PERM00833',
'owner': 'Administrator', 'owner': 'Administrator',
'parent': 'Rename Tool', 'parent': 'Rename Tool',
'parentfield': 'permissions', 'parentfield': 'permissions',
@ -80,8 +80,8 @@
}, },
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': 'White:FFF',
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -94,14 +94,14 @@
'idx': 1, 'idx': 1,
'in_filter': None, 'in_filter': None,
'label': 'Select DocType', 'label': 'Select DocType',
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05599', 'name': 'FL05557',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
'oldfieldtype': None, 'oldfieldtype': None,
'options': 'link:DocType', 'options': '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem',
'owner': 'Administrator', 'owner': 'Administrator',
'parent': 'Rename Tool', 'parent': 'Rename Tool',
'parentfield': 'fields', 'parentfield': 'fields',
@ -117,7 +117,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -130,9 +130,9 @@
'idx': 2, 'idx': 2,
'in_filter': None, 'in_filter': None,
'label': 'Document to rename', 'label': 'Document to rename',
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05600', 'name': 'FL05558',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -153,7 +153,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -166,9 +166,9 @@
'idx': 3, 'idx': 3,
'in_filter': None, 'in_filter': None,
'label': 'New Name', 'label': 'New Name',
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05601', 'name': 'FL05559',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,
@ -189,7 +189,7 @@
{ {
'allow_on_submit': None, 'allow_on_submit': None,
'colour': None, 'colour': None,
'creation': '2011-06-23 11:03:25', 'creation': '2011-06-22 18:42:33',
'default': None, 'default': None,
'depends_on': None, 'depends_on': None,
'description': None, 'description': None,
@ -202,9 +202,9 @@
'idx': 4, 'idx': 4,
'in_filter': None, 'in_filter': None,
'label': 'Rename', 'label': 'Rename',
'modified': '2011-06-23 11:03:25', 'modified': '2011-06-30 19:21:07',
'modified_by': 'Administrator', 'modified_by': 'Administrator',
'name': 'FL05602', 'name': 'FL05560',
'no_column': None, 'no_column': None,
'no_copy': None, 'no_copy': None,
'oldfieldname': None, 'oldfieldname': None,