[fix] [minor] rename and merge for customer and supplier

This commit is contained in:
Nabin Hait 2013-11-26 15:03:51 +05:30
parent d3e7a6d57a
commit 131939a742
4 changed files with 42 additions and 49 deletions

View File

@ -348,4 +348,28 @@ def get_actual_expense(args):
from `tabGL Entry`
where account='%(account)s' and cost_center='%(cost_center)s'
and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s
""" % (args))[0][0]
""" % (args))[0][0]
def rename_account_for(dt, olddn, newdn, merge):
old_account = get_account_for(dt, olddn)
if old_account:
new_account = None
if not merge:
if old_account == olddn:
new_account = webnotes.rename_doc("Account", olddn, newdn)
else:
existing_new_account = get_account_for(dt, newdn)
new_account = webnotes.rename_doc("Account", old_account,
existing_new_account or newdn, merge=True if existing_new_account else False)
if new_account:
webnotes.conn.set_value("Account", new_account, "master_name", newdn)
def get_account_for(account_for_doctype, account_for):
if account_for_doctype in ["Customer", "Supplier"]:
account_for_field = "master_type"
elif account_for_doctype == "Warehouse":
account_for_field = "account_type"
return webnotes.conn.get_value("Account", {account_for_field: account_for_doctype,
"master_name": account_for})

View File

@ -148,21 +148,13 @@ class DocType(TransactionBase):
self.delete_supplier_contact()
self.delete_supplier_account()
def after_rename(self, old, new, merge=False):
#update supplier_name if not naming series
def before_rename(self, olddn, newdn, merge=False):
from accounts.utils import rename_account_for
rename_account_for("Supplier", olddn, newdn, merge)
def after_rename(self, olddn, newdn, merge=False):
if webnotes.defaults.get_global_default('supp_master_name') == 'Supplier Name':
webnotes.conn.set(self.doc, "supplier_name", new)
for account in webnotes.conn.sql("""select name, account_name from
tabAccount where master_name=%s and master_type='Supplier'""", old, as_dict=1):
if account.account_name != new:
merge_account = True if merge and webnotes.conn.get_value("Account",
{"master_name": new, "master_type": "Supplier"}) else False
webnotes.rename_doc("Account", account.name, new, merge=merge_account)
#update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s,
master_type = 'Supplier' where master_name = %s""" , (new, old))
webnotes.conn.set(self.doc, "supplier_name", newdn)
@webnotes.whitelist()
def get_dashboard_info(supplier):

View File

@ -143,21 +143,13 @@ class DocType(TransactionBase):
if self.doc.lead_name:
webnotes.conn.sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
def after_rename(self, old, new, merge=False):
#update customer_name if not naming series
def before_rename(self, olddn, newdn, merge=False):
from accounts.utils import rename_account_for
rename_account_for("Customer", olddn, newdn, merge)
def after_rename(self, olddn, newdn, merge=False):
if webnotes.defaults.get_global_default('cust_master_name') == 'Customer Name':
webnotes.conn.set(self.doc, "customer_name", new)
for account in webnotes.conn.sql("""select name, account_name from
tabAccount where master_name=%s and master_type='Customer'""", old, as_dict=1):
if account.account_name != new:
merge_account = True if merge and webnotes.conn.get_value("Account",
{"master_name": new, "master_type": "Customer"}) else False
webnotes.rename_doc("Account", account.name, new, merge=merge_account)
#update master_name in account record
webnotes.conn.sql("""update `tabAccount` set master_name = %s,
master_type = 'Customer' where master_name = %s""", (new, old))
webnotes.conn.set(self.doc, "customer_name", newdn)
@webnotes.whitelist()
def get_dashboard_info(customer):

View File

@ -73,7 +73,8 @@ class DocType:
if warehouse_account:
webnotes.delete_doc("Account", warehouse_account)
if sql("""select name from `tabStock Ledger Entry` where warehouse = %s""", self.doc.name):
if webnotes.conn.sql("""select name from `tabStock Ledger Entry`
where warehouse = %s""", self.doc.name):
msgprint("""Warehouse can not be deleted as stock ledger entry
exists for this warehouse.""", raise_exception=1)
@ -88,7 +89,8 @@ class DocType:
webnotes.conn.sql("delete from `tabBin` where warehouse=%s", olddn)
self.rename_account(olddn, new_warehouse, merge)
from accounts.utils import rename_account_for
rename_account_for("Warehouse", olddn, new_warehouse, merge)
return new_warehouse
@ -109,21 +111,4 @@ class DocType:
webnotes.conn.set_default("allow_negative_stock",
webnotes.conn.get_value("Stock Settings", None, "allow_negative_stock"))
webnotes.conn.auto_commit_on_many_writes = 0
def rename_account(self, olddn, newdn, merge):
old_account = webnotes.conn.get_value("Account",
{"account_type": "Warehouse", "master_name": olddn})
if old_account:
new_account = None
if not merge:
if old_account == olddn:
new_account = webnotes.rename_doc("Account", olddn, newdn)
else:
existing_new_account = webnotes.conn.get_value("Account",
{"account_type": "Warehouse", "master_name": newdn})
new_account = webnotes.rename_doc("Account", old_account,
existing_new_account or newdn, merge=True if existing_new_account else False)
if new_account:
webnotes.conn.set_value("Account", new_account, "master_name", newdn)
webnotes.conn.auto_commit_on_many_writes = 0