resoved conflict in patch, company and renaming tools
This commit is contained in:
commit
a56fc00ea3
@ -72,6 +72,7 @@ cur_frm.fields_dict['master_name'].get_query=function(doc){
|
||||
else alert("Please select master type");
|
||||
}
|
||||
|
||||
/*
|
||||
// Get customer/supplier address
|
||||
// -----------------------------------------
|
||||
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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// parent account get query
|
||||
// -----------------------------------------
|
||||
|
@ -260,3 +260,16 @@ class DocType:
|
||||
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))
|
||||
|
@ -13,136 +13,155 @@ sql = webnotes.conn.sql
|
||||
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))
|
||||
|
@ -1,6 +1,7 @@
|
||||
# REMEMBER to update this
|
||||
# ========================
|
||||
last_patch = 306
|
||||
|
||||
last_patch = 308
|
||||
|
||||
#-------------------------------------------
|
||||
|
||||
@ -1187,9 +1188,9 @@ def execute(patch_no):
|
||||
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:
|
||||
@ -1208,5 +1209,14 @@ def execute(patch_no):
|
||||
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')
|
||||
elif patch_no == 307:
|
||||
sql("delete from `tabDocField` where parent = 'company' and label = 'Trash Company' and fieldtype = 'Button'")
|
||||
reload_doc('setup', 'doctype', 'company')
|
||||
elif patch_no == 308:
|
||||
from erpnext_structure_cleanup import run_patches
|
||||
run_patches()
|
||||
|
@ -10,221 +10,248 @@ set = webnotes.conn.set
|
||||
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))
|
||||
|
@ -13,234 +13,239 @@ sql = webnotes.conn.sql
|
||||
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))
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,9 +12,9 @@ class DocType:
|
||||
# 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")
|
||||
webnotes.msgprint("Successfully renamed "+self.doc.select_doctype+" : '"+self.doc.document_to_rename+"' to <b>"+self.doc.new_name+"</b>")
|
||||
|
Loading…
x
Reference in New Issue
Block a user