def execute(): webnotes.reload_doc("core", "doctype", "doctype") tables = webnotes.conn.sql_list("show tables") if not "tabMaterial Request Item" in tables: webnotes.rename_doc("DocType", "Purchase Request Item", "Material Request Item", force=True) if not "tabMaterial Request" in tables: webnotes.rename_doc("DocType", "Purchase Request", "Material Request", force=True) webnotes.reload_doc("buying", "search_criteria", "pending_po_items_to_bill") webnotes.reload_doc("buying", "search_criteria", "pending_po_items_to_receive") webnotes.reload_doc("stock", "doctype", "material_request") webnotes.reload_doc("stock", "doctype", "material_request_item") webnotes.conn.sql("""update `tabMaterial Request` set material_request_type='Purchase'""") os.system("rm -rf app/buying/doctype/purchase_request") os.system("rm -rf app/buying/doctype/purchase_request_item") os.system("rm -rf app/hr/doctype/holiday_block_list") os.system("rm -rf app/hr/doctype/holiday_block_list_allow") os.system("rm -rf app/hr/doctype/holiday_block_list_date") for dt in ("Purchase Request", "Purchase Request Item"): if webnotes.conn.exists("DocType", dt): webnotes.delete_doc("DocType", dt)
def execute(): webnotes.reload_doc("core", "doctype", "doctype") tables = webnotes.conn.sql_list("show tables") if not "tabMaterial Request Item" in tables: webnotes.rename_doc("DocType", "Purchase Request Item", "Material Request Item", force=True) if not "tabMaterial Request" in tables: webnotes.rename_doc("DocType", "Purchase Request", "Material Request", force=True) webnotes.reload_doc("stock", "doctype", "material_request") webnotes.reload_doc("stock", "doctype", "material_request_item") webnotes.conn.sql( """update `tabMaterial Request` set material_request_type='Purchase'""" ) os.system("rm -rf app/buying/doctype/purchase_request") os.system("rm -rf app/buying/doctype/purchase_request_item") os.system("rm -rf app/hr/doctype/holiday_block_list") os.system("rm -rf app/hr/doctype/holiday_block_list_allow") os.system("rm -rf app/hr/doctype/holiday_block_list_date") for dt in ("Purchase Request", "Purchase Request Item"): if webnotes.conn.exists("DocType", dt): webnotes.delete_doc("DocType", dt)
def execute(): webnotes.reload_doc('website', 'doctype', 'blogger') webnotes.rename_doc("DocType", "Blog", "Blog Post", force=True) webnotes.reload_doc('website', 'doctype', 'blog_post') webnotes.conn.sql('''update tabBlogger set posts=(select count(*) from `tabBlog Post` where ifnull(blogger,"")=tabBlogger.name)''') webnotes.conn.sql("""update `tabBlog Post` set published_on=date(creation)""")
def on_rename(self, new, old): #update customer_name if not naming series if webnotes.defaults.get_global_default('cust_master_name') == 'Customer Name': update_fields = [ ('Customer', 'name'), ('Address', 'customer'), ('Contact', 'customer'), ('Customer Issue', 'customer'), ('Delivery Note', 'customer'), ('Opportunity', 'customer'), ('Installation Note', 'customer'), ('Maintenance Schedule', 'customer'), ('Maintenance Visit', 'customer'), ('Project', 'customer'), ('Quotation', 'customer'), ('Sales Invoice', 'customer'), ('Sales Order', 'customer'), ('Serial No', 'customer'), ('Shipping Address', 'customer'), ('Stock Entry', 'customer'), ('Support Ticket', 'customer')] for rec in update_fields: sql("""update `tab%s` set customer_name = %s where `%s` = %s""" % (rec[0], "%s" ,rec[1], "%s"), (new, old)) 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) #update master_name in doctype account webnotes.conn.sql("""update `tabAccount` set master_name = %s, master_type = 'Customer' where master_name = %s""", (new,old))
def add_or_update_sitemap(self): page_name = self.get_page_name() existing_page_name = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype, "docname": self.doc.name}) opts = webnotes._dict({ "page_or_generator": "Generator", "ref_doctype":self.doc.doctype, "docname": self.doc.name, "page_name": page_name, "link_name": self._website_config.name, "lastmod": webnotes.utils.get_datetime(self.doc.modified).strftime("%Y-%m-%d"), "parent_website_sitemap": self.doc.parent_website_sitemap, "page_title": self.get_page_title() \ if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name) }) if self.meta.get_field("public_read"): opts.public_read = self.doc.public_read opts.public_write = self.doc.public_write else: opts.public_read = 1 if existing_page_name: if existing_page_name != page_name: webnotes.rename_doc("Website Sitemap", existing_page_name, page_name, ignore_permissions=True) update_sitemap(page_name, opts) else: add_to_sitemap(opts)
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 = [('Supplier', 'name'), ('Address', 'supplier'), ('Contact', 'supplier'), ('Purchase Invoice', 'supplier'), ('Purchase Order', 'supplier'), ('Purchase Receipt', 'supplier'), ('Serial No', 'supplier')] for rec in update_fields: sql("update `tab%s` set supplier_name = %s where `%s` = %s" % \ (rec[0], '%s', rec[1], '%s'), (new, old)) 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, merge=merge) #update master_name in doctype account webnotes.conn.sql( """update `tabAccount` set master_name = %s, master_type = 'Supplier' where master_name = %s""", (new, old))
def execute(): webnotes.reload_doc('website', 'doctype', 'blogger') webnotes.rename_doc("DocType", "Blog", "Blog Post", force=True) webnotes.reload_doc('website', 'doctype', 'blog_post') webnotes.conn.sql('''update tabBlogger set posts=(select count(*) from `tabBlog Post` where ifnull(blogger,"")=tabBlogger.name)''') webnotes.conn.sql( """update `tabBlog Post` set published_on=date(creation)""")
def _rename_record(dt): for d in webnotes.conn.sql( "select name from `tab%s` where company=%s" % (dt, '%s'), company): parts = d[0].split(" - ") if parts[-1].lower() == old.lower(): name_without_abbr = " - ".join(parts[:-1]) webnotes.rename_doc(dt, d[0], name_without_abbr + " - " + new)
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 execute(): email_lead = {} for name, email in webnotes.conn.sql("""select name, email_id from `tabLead` where ifnull(email_id, '')!='' order by creation asc"""): email = extract_email_id(email) if email: if email not in email_lead: email_lead[email] = name else: webnotes.rename_doc("Lead", name, email_lead[email], force=True, merge=True)
def rename_account_for(dt, olddn, newdn, merge, company): old_account = get_account_for(dt, olddn) if old_account: new_account = None if not merge: if old_account == add_abbr_if_missing(olddn, company): new_account = webnotes.rename_doc("Account", old_account, 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) webnotes.conn.set_value("Account", new_account or old_account, "master_name", newdn)
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 rename_module(): webnotes.reload_doc("core", "doctype", "role") webnotes.reload_doc("core", "doctype", "page") webnotes.reload_doc("core", "doctype", "module_def") if webnotes.conn.exists("Role", "Production User"): webnotes.rename_doc("Role", "Production User", "Manufacturing User") if webnotes.conn.exists("Role", "Production Manager"): webnotes.rename_doc("Role", "Production Manager", "Manufacturing Manager") if webnotes.conn.exists("Page", "manufacturing-home"): webnotes.delete_doc("Page", "production-home") else: webnotes.rename_doc("Page", "production-home", "manufacturing-home") if webnotes.conn.exists("Module Def", "Production"): webnotes.rename_doc("Module Def", "Production", "Manufacturing") modules_list = webnotes.conn.get_global('modules_list') if modules_list: webnotes.conn.set_global( "modules_list", modules_list.replace("Production", "Manufacturing")) # set end of life to null if "0000-00-00" webnotes.conn.sql( """update `tabItem` set end_of_life=null where end_of_life='0000-00-00'""" )
def rename_module(): webnotes.reload_doc("core", "doctype", "role") webnotes.reload_doc("core", "doctype", "page") webnotes.reload_doc("core", "doctype", "module_def") if webnotes.conn.exists("Role", "Production User"): webnotes.rename_doc("Role", "Production User", "Manufacturing User") if webnotes.conn.exists("Role", "Production Manager"): webnotes.rename_doc("Role", "Production Manager", "Manufacturing Manager") if webnotes.conn.exists("Page", "manufacturing-home"): webnotes.delete_doc("Page", "production-home") else: webnotes.rename_doc("Page", "production-home", "manufacturing-home") if webnotes.conn.exists("Module Def", "Production"): webnotes.rename_doc("Module Def", "Production", "Manufacturing") modules_list = webnotes.conn.get_global('modules_list') if modules_list: webnotes.conn.set_global("modules_list", modules_list.replace("Production", "Manufacturing")) # set end of life to null if "0000-00-00" webnotes.conn.sql("""update `tabItem` set end_of_life=null where end_of_life='0000-00-00'""")
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': webnotes.conn.sql("""update `tabCustomer` set customer_name = %s where name = %s""", (new, old)) 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, merge=merge) #update master_name in doctype account webnotes.conn.sql("""update `tabAccount` set master_name = %s, master_type = 'Customer' where master_name = %s""", (new,old))
def after_rename(self, old, new, merge=False): #update customer_name if not naming series 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))
def execute(): webnotes.reload_doc("core", "doctype", "doctype") tables = webnotes.conn.sql_list("show tables") if "tabPacked Item" not in tables: webnotes.rename_doc("DocType", "Delivery Note Packing Item", "Packed Item", force=True) webnotes.reload_doc("stock", "doctype", "packed_item") if os.path.exists("app/stock/doctype/delivery_note_packing_item"): os.system("rm -rf app/stock/doctype/delivery_note_packing_item") if webnotes.conn.exists("DocType", "Delivery Note Packing Item"): webnotes.delete_doc("DocType", "Delivery Note Packing Item")
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)
def execute(): from webnotes.utils import get_base_path import shutil webnotes.reload_doc("core", "doctype", "doctype") tables = webnotes.conn.sql_list("show tables") if "tabApplicable Territory" not in tables: webnotes.rename_doc("DocType", "For Territory", "Applicable Territory", force=True) webnotes.reload_doc("setup", "doctype", "applicable_territory") path = os.path.join(get_base_path(), "app", "setup", "doctype", "for_territory") if os.path.exists(path): shutil.rmtree(path) if webnotes.conn.exists("DocType", "For Territory"): webnotes.delete_doc("DocType", "For Territory")
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"), ()) # create back _Test Customer webnotes.bean(copy=test_records[0]).insert()
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"), ())
def on_rename(self, new, old): #update supplier_name if not naming series if get_defaults().get('supp_master_name') == 'Supplier Name': update_fields = [ ('Supplier', 'name'), ('Address', 'supplier'), ('Contact', 'supplier'), ('Purchase Invoice', 'supplier'), ('Purchase Order', 'supplier'), ('Purchase Receipt', 'supplier'), ('Serial No', 'supplier')] for rec in update_fields: sql("update `tab%s` set supplier_name = %s where `%s` = %s" % \ (rec[0], '%s', rec[1], '%s'), (new, old)) 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) #update master_name in doctype account webnotes.conn.sql("""update `tabAccount` set master_name = %s, master_type = 'Supplier' where master_name = %s""" , (new,old))
def on_rename(self, new, old): #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'), ('Opportunity', 'customer'), ('Installation Note', 'customer'), ('Maintenance Schedule', 'customer'), ('Maintenance Visit', 'customer'), ('Project', 'customer'), ('Quotation', 'customer'), ('Sales Invoice', 'customer'), ('Sales Order', 'customer'), ('Serial No', 'customer'), ('Shipping Address', 'customer'), ('Stock Entry', 'customer'), ('Support Ticket', 'customer'), ('Task', 'customer')] for rec in update_fields: sql( """update `tab%s` set customer_name = %s where `%s` = %s""" % (rec[0], "%s", rec[1], "%s"), (new, old)) 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) #update master_name in doctype account webnotes.conn.sql( """update `tabAccount` set master_name = %s, master_type = 'Customer' where master_name = %s""", (new, old))
def rename_doc(doctype, old_name, new_name, merge=False): new_name = webnotes.rename_doc(doctype, old_name, new_name, merge=merge) return new_name
def _rename_record(dt): for d in webnotes.conn.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company): parts = d[0].split(" - ") if parts[-1].lower() == old.lower(): name_without_abbr = " - ".join(parts[:-1]) webnotes.rename_doc(dt, d[0], name_without_abbr + " - " + new)