[rename] [fix] merge should be passed to on_rename method of controller for further processing

This commit is contained in:
Anand Doshi 2013-05-09 12:45:18 +05:30
parent 4f8a81ca97
commit bddd5d9b0c
8 changed files with 73 additions and 9 deletions

View File

@ -187,7 +187,7 @@ class DocType:
sql("""delete from `tabGL Entry` where account = %s and
ifnull(is_cancelled, 'No') = 'Yes'""", self.doc.name)
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
company_abbr = webnotes.conn.get_value("Company", self.doc.company, "abbr")
parts = new.split(" - ")

View File

@ -87,7 +87,7 @@ class DocType(DocTypeNestedSet):
self.validate_mandatory()
self.validate_budget_details()
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
company_abbr = webnotes.conn.get_value("Company", self.doc.company_name, "abbr")
parts = new.split(" - ")

View File

@ -168,7 +168,7 @@ class DocType(TransactionBase):
self.delete_supplier_communication()
self.delete_supplier_account()
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
#update supplier_name if not naming series
if webnotes.defaults.get_global_default('supp_master_name') == 'Supplier Name':
update_fields = [
@ -186,7 +186,7 @@ class DocType(TransactionBase):
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:
webnotes.rename_doc("Account", account.name, new)
webnotes.rename_doc("Account", account.name, new, merge=merge)
#update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s,

View File

@ -216,7 +216,7 @@ class DocType(TransactionBase):
if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
#update customer_name if not naming series
if webnotes.defaults.get_global_default('cust_master_name') == 'Customer Name':
update_fields = [
@ -244,7 +244,7 @@ class DocType(TransactionBase):
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:
webnotes.rename_doc("Account", account.name, new)
webnotes.rename_doc("Account", account.name, new, merge=merge)
#update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s,

View File

@ -1,4 +1,60 @@
from __future__ import unicode_literals
import webnotes
import unittest
class TestCustomer(unittest.TestCase):
def test_rename(self):
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"),
(("_Test Customer 1",),))
webnotes.rename_doc("Customer", "_Test Customer 1", "_Test Customer 1 Renamed")
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1 Renamed"),
(("_Test Customer 1 Renamed",),))
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"), ())
def test_merge(self):
from webnotes.test_runner import make_test_records
make_test_records("Sales Invoice")
# clear transactions for new name
webnotes.conn.sql("""delete from `tabSales Invoice` where customer='_Test Customer 1'""")
# check if they exist
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"),
(("_Test Customer",),))
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"),
(("_Test Customer 1",),))
self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"),
(("_Test Customer - _TC",),))
self.assertEqual(webnotes.conn.exists("Account", "_Test Customer 1 - _TC"),
(("_Test Customer 1 - _TC",),))
# check if transactions exists
self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where customer='_Test Customer'""", )[0][0], 0)
self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where debit_to='_Test Customer - _TC'""", )[0][0], 0)
webnotes.rename_doc("Customer", "_Test Customer", "_Test Customer 1", merge=True)
# check that no transaction exists for old name
self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where customer='_Test Customer 1'""", )[0][0], 0)
self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where debit_to='_Test Customer 1 - _TC'""", )[0][0], 0)
# check that transactions exist for new name
self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where customer='_Test Customer'""", )[0][0], 0)
self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice`
where debit_to='_Test Customer - _TC'""", )[0][0], 0)
# check that old name doesn't exist
self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), ())
self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), ())
test_records = [
[{
"doctype": "Customer",
@ -7,5 +63,13 @@ test_records = [
"customer_group": "_Test Customer Group",
"territory": "_Test Territory",
"company": "_Test Company"
}],
[{
"doctype": "Customer",
"customer_name": "_Test Customer 1",
"customer_type": "Individual",
"customer_group": "_Test Customer Group",
"territory": "_Test Territory",
"company": "_Test Company"
}]
]

View File

@ -287,7 +287,7 @@ class DocType:
where doctype='Global Defaults' and field='default_company'
and value=%s""", self.doc.name)
def on_rename(self,newdn,olddn):
def on_rename(self,newdn,olddn, merge=False):
webnotes.conn.sql("""update `tabCompany` set company_name=%s
where name=%s""", (newdn, olddn))

View File

@ -272,7 +272,7 @@ class DocType(DocListController):
from webnotes.webutils import clear_cache
clear_cache(self.doc.page_name)
def on_rename(self,newdn,olddn):
def on_rename(self,newdn,olddn, merge=False):
webnotes.conn.sql("update tabItem set item_code = %s where name = %s", (newdn, olddn))
if self.doc.page_name:
from webnotes.webutils import clear_cache

View File

@ -117,7 +117,7 @@ class DocType(StockController):
self.make_stock_ledger_entry(1)
self.make_gl_entries()
def on_rename(self, new, old):
def on_rename(self, new, old, merge=False):
"""rename serial_no text fields"""
for dt in webnotes.conn.sql("""select parent from tabDocField
where fieldname='serial_no' and fieldtype='Text'"""):