mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 07:02:54 +00:00
[rename with merge] updated on_rename function for item, warehouse, al tree type documents
This commit is contained in:
@@ -18,7 +18,7 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
from webnotes.utils import flt, fmt_money
|
from webnotes.utils import flt, fmt_money
|
||||||
from webnotes import msgprint
|
from webnotes import msgprint, _
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
get_value = webnotes.conn.get_value
|
get_value = webnotes.conn.get_value
|
||||||
@@ -198,8 +198,21 @@ class DocType:
|
|||||||
parts.append(company_abbr)
|
parts.append(company_abbr)
|
||||||
|
|
||||||
# rename account name
|
# rename account name
|
||||||
account_name = " - ".join(parts[:-1])
|
new_account_name = " - ".join(parts[:-1])
|
||||||
sql("update `tabAccount` set account_name = %s where name = %s", (account_name, old))
|
sql("update `tabAccount` set account_name = %s where name = %s", (new_account_name, old))
|
||||||
|
|
||||||
|
if merge:
|
||||||
|
new_name = " - ".join(parts)
|
||||||
|
val = list(webnotes.conn.get_value("Account", new_name,
|
||||||
|
["group_or_ledger", "debit_or_credit", "is_pl_account"]))
|
||||||
|
|
||||||
|
if val != [self.doc.group_or_ledger, self.doc.debit_or_credit, self.doc.is_pl_account]:
|
||||||
|
msgprint(_("""Merging is only possible if following \
|
||||||
|
properties are same in both records.
|
||||||
|
Group or Ledger, Debit or Credit, Is PL Account"""), raise_exception=1)
|
||||||
|
|
||||||
|
from webnotes.utils.nestedset import rebuild_tree
|
||||||
|
rebuild_tree("Account", "parent_account")
|
||||||
|
|
||||||
return " - ".join(parts)
|
return " - ".join(parts)
|
||||||
|
|
||||||
|
|||||||
@@ -99,4 +99,6 @@ class DocType(DocTypeNestedSet):
|
|||||||
webnotes.conn.sql("update `tabCost Center` set cost_center_name = %s where name = %s", \
|
webnotes.conn.sql("update `tabCost Center` set cost_center_name = %s where name = %s", \
|
||||||
(cost_center_name, old))
|
(cost_center_name, old))
|
||||||
|
|
||||||
|
super(DocType, self).on_rename(new, old, merge, "group_or_ledger")
|
||||||
|
|
||||||
return " - ".join(parts)
|
return " - ".join(parts)
|
||||||
|
|||||||
@@ -280,8 +280,14 @@ class DocType(DocListController):
|
|||||||
from webnotes.webutils import clear_cache
|
from webnotes.webutils import clear_cache
|
||||||
clear_cache(self.doc.page_name)
|
clear_cache(self.doc.page_name)
|
||||||
|
|
||||||
def on_rename(self,newdn,olddn, merge=False):
|
def on_rename(self, newdn, olddn, merge=False):
|
||||||
webnotes.conn.sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
|
webnotes.conn.sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
|
||||||
if self.doc.page_name:
|
if self.doc.page_name:
|
||||||
from webnotes.webutils import clear_cache
|
from webnotes.webutils import clear_cache
|
||||||
clear_cache(self.doc.page_name)
|
clear_cache(self.doc.page_name)
|
||||||
|
|
||||||
|
if merge:
|
||||||
|
from stock.stock_ledger import update_entries_after
|
||||||
|
for wh in webnotes.conn.sql("""select warehouse from `tabBin`
|
||||||
|
where item_code=%s""", newdn):
|
||||||
|
update_entries_after({"item_code": newdn, "warehouse": wh})
|
||||||
@@ -204,3 +204,9 @@ class DocType:
|
|||||||
else:
|
else:
|
||||||
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
|
||||||
|
|
||||||
|
def on_rename(self, newdn, olddn, merge=False):
|
||||||
|
if merge:
|
||||||
|
from stock.stock_ledger import update_entries_after
|
||||||
|
for item_code in webnotes.conn.sql("""select item_code from `tabBin`
|
||||||
|
where warehouse=%s""", newdn):
|
||||||
|
update_entries_after({"item_code": item_code, "warehouse": newdn})
|
||||||
|
|||||||
Reference in New Issue
Block a user