From 5a31e228923d3ec2fe387e3e83eca3920cee6da4 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 6 Nov 2019 17:03:12 +0530 Subject: [PATCH 1/2] chore: frappe.rename_doc update --- .../clinical_procedure_template.py | 3 ++- .../healthcare_service_unit_type.py | 3 ++- .../doctype/lab_test_template/lab_test_template.py | 5 +++-- erpnext/patches/v9_2/rename_translated_domains_in_en.py | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py index 141329b3db..a8a9037e4a 100644 --- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py +++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe, json from frappe import _ from frappe.model.document import Document +from frappe.model.rename_doc import rename_doc from frappe.utils import nowdate class ClinicalProcedureTemplate(Document): @@ -115,7 +116,7 @@ def change_item_code_from_template(item_code, doc): "item_code": item_code})): frappe.throw(_("Code {0} already exist").format(item_code)) else: - frappe.rename_doc("Item", doc.item_code, item_code, ignore_permissions = True) + rename_doc("Item", doc.item_code, item_code, ignore_permissions=True) frappe.db.set_value("Clinical Procedure Template", doc.name, "item_code", item_code) return diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py index 650499454b..43f01c86b9 100644 --- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py +++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document +from frappe.model.rename_doc import rename_doc class HealthcareServiceUnitType(Document): def validate(self): @@ -107,7 +108,7 @@ def change_item_code(item, item_code, doc_name): if(item_exist): frappe.throw(_("Code {0} already exist").format(item_code)) else: - frappe.rename_doc("Item", item, item_code, ignore_permissions = True) + rename_doc("Item", item, item_code, ignore_permissions=True) frappe.db.set_value("Healthcare Service Unit Type", doc_name, "item_code", item_code) @frappe.whitelist() diff --git a/erpnext/healthcare/doctype/lab_test_template/lab_test_template.py b/erpnext/healthcare/doctype/lab_test_template/lab_test_template.py index 101e143c12..91488e3533 100644 --- a/erpnext/healthcare/doctype/lab_test_template/lab_test_template.py +++ b/erpnext/healthcare/doctype/lab_test_template/lab_test_template.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe, json from frappe.model.document import Document +from frappe.model.rename_doc import rename_doc from frappe import _ class LabTestTemplate(Document): @@ -112,9 +113,9 @@ def change_test_code_from_template(lab_test_code, doc): if(item_exist): frappe.throw(_("Code {0} already exist").format(lab_test_code)) else: - frappe.rename_doc("Item", doc.name, lab_test_code, ignore_permissions = True) + rename_doc("Item", doc.name, lab_test_code, ignore_permissions=True) frappe.db.set_value("Lab Test Template",doc.name,"lab_test_code",lab_test_code) - frappe.rename_doc("Lab Test Template", doc.name, lab_test_code, ignore_permissions = True) + rename_doc("Lab Test Template", doc.name, lab_test_code, ignore_permissions=True) return lab_test_code @frappe.whitelist() diff --git a/erpnext/patches/v9_2/rename_translated_domains_in_en.py b/erpnext/patches/v9_2/rename_translated_domains_in_en.py index aec5d438ec..e5a9e2461f 100644 --- a/erpnext/patches/v9_2/rename_translated_domains_in_en.py +++ b/erpnext/patches/v9_2/rename_translated_domains_in_en.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import frappe from frappe import _ +from frappe.model.rename_doc import rename_doc def execute(): frappe.reload_doc('stock', 'doctype', 'item') @@ -20,11 +21,11 @@ def execute(): if frappe.db.exists("Domain", domain): merge=True - frappe.rename_doc("Domain", translated_domain, domain, ignore_permissions=True, merge=merge) + rename_doc("Domain", translated_domain, domain, ignore_permissions=True, merge=merge) domain_settings = frappe.get_single("Domain Settings") active_domains = [d.domain for d in domain_settings.active_domains] - + try: for domain in active_domains: domain = frappe.get_doc("Domain", domain) From 1e4ea466d3a58c2433006cdccf919a7acd0763fa Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 11 Dec 2019 09:36:17 +0530 Subject: [PATCH 2/2] style: update/standardize rename_doc usage --- .../v11_0/merge_land_unit_with_location.py | 5 ++-- .../v11_0/rename_asset_adjustment_doctype.py | 4 ++-- .../patches/v11_0/rename_health_insurance.py | 3 +-- .../rename_healthcare_doctype_and_fields.py | 3 +-- .../rename_production_order_to_work_order.py | 9 ++++--- .../rename_supplier_type_to_supplier_group.py | 3 +-- .../rename_pricing_rule_child_doctypes.py | 3 +-- erpnext/stock/doctype/item/test_item.py | 3 +-- .../stock/doctype/warehouse/test_warehouse.py | 24 +++++++++++-------- 9 files changed, 27 insertions(+), 30 deletions(-) diff --git a/erpnext/patches/v11_0/merge_land_unit_with_location.py b/erpnext/patches/v11_0/merge_land_unit_with_location.py index 1ea486dfd5..7845da255a 100644 --- a/erpnext/patches/v11_0/merge_land_unit_with_location.py +++ b/erpnext/patches/v11_0/merge_land_unit_with_location.py @@ -4,19 +4,18 @@ from __future__ import unicode_literals import frappe -from frappe.model.rename_doc import rename_doc from frappe.model.utils.rename_field import rename_field def execute(): # Rename and reload the Land Unit and Linked Land Unit doctypes if frappe.db.table_exists('Land Unit') and not frappe.db.table_exists('Location'): - rename_doc('DocType', 'Land Unit', 'Location', force=True) + frappe.rename_doc('DocType', 'Land Unit', 'Location', force=True) frappe.reload_doc('assets', 'doctype', 'location') if frappe.db.table_exists('Linked Land Unit') and not frappe.db.table_exists('Linked Location'): - rename_doc('DocType', 'Linked Land Unit', 'Linked Location', force=True) + frappe.rename_doc('DocType', 'Linked Land Unit', 'Linked Location', force=True) frappe.reload_doc('assets', 'doctype', 'linked_location') diff --git a/erpnext/patches/v11_0/rename_asset_adjustment_doctype.py b/erpnext/patches/v11_0/rename_asset_adjustment_doctype.py index c03ab0b711..fad0cf7a45 100644 --- a/erpnext/patches/v11_0/rename_asset_adjustment_doctype.py +++ b/erpnext/patches/v11_0/rename_asset_adjustment_doctype.py @@ -3,9 +3,9 @@ from __future__ import unicode_literals import frappe -from frappe.model.rename_doc import rename_doc + def execute(): if frappe.db.table_exists("Asset Adjustment") and not frappe.db.table_exists("Asset Value Adjustment"): - rename_doc('DocType', 'Asset Adjustment', 'Asset Value Adjustment', force=True) + frappe.rename_doc('DocType', 'Asset Adjustment', 'Asset Value Adjustment', force=True) frappe.reload_doc('assets', 'doctype', 'asset_value_adjustment') \ No newline at end of file diff --git a/erpnext/patches/v11_0/rename_health_insurance.py b/erpnext/patches/v11_0/rename_health_insurance.py index 24d1ddf031..e605071a29 100644 --- a/erpnext/patches/v11_0/rename_health_insurance.py +++ b/erpnext/patches/v11_0/rename_health_insurance.py @@ -2,9 +2,8 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -from frappe.model.rename_doc import rename_doc import frappe def execute(): - rename_doc('DocType', 'Health Insurance', 'Employee Health Insurance', force=True) + frappe.rename_doc('DocType', 'Health Insurance', 'Employee Health Insurance', force=True) frappe.reload_doc('hr', 'doctype', 'employee_health_insurance') \ No newline at end of file diff --git a/erpnext/patches/v11_0/rename_healthcare_doctype_and_fields.py b/erpnext/patches/v11_0/rename_healthcare_doctype_and_fields.py index 8fdac07658..9705681b33 100644 --- a/erpnext/patches/v11_0/rename_healthcare_doctype_and_fields.py +++ b/erpnext/patches/v11_0/rename_healthcare_doctype_and_fields.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals import frappe -from frappe.model.rename_doc import rename_doc from frappe.model.utils.rename_field import rename_field from frappe.modules import scrub, get_doctype_module @@ -37,7 +36,7 @@ doc_rename_map = { def execute(): for dt in doc_rename_map: if frappe.db.exists('DocType', dt): - rename_doc('DocType', dt, doc_rename_map[dt], force=True) + frappe.rename_doc('DocType', dt, doc_rename_map[dt], force=True) for dn in field_rename_map: if frappe.db.exists('DocType', dn): diff --git a/erpnext/patches/v11_0/rename_production_order_to_work_order.py b/erpnext/patches/v11_0/rename_production_order_to_work_order.py index 2c27fbbc9d..2f620f413b 100644 --- a/erpnext/patches/v11_0/rename_production_order_to_work_order.py +++ b/erpnext/patches/v11_0/rename_production_order_to_work_order.py @@ -2,18 +2,17 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -from frappe.model.rename_doc import rename_doc -from frappe.model.utils.rename_field import rename_field import frappe +from frappe.model.utils.rename_field import rename_field def execute(): - rename_doc('DocType', 'Production Order', 'Work Order', force=True) + frappe.rename_doc('DocType', 'Production Order', 'Work Order', force=True) frappe.reload_doc('manufacturing', 'doctype', 'work_order') - rename_doc('DocType', 'Production Order Item', 'Work Order Item', force=True) + frappe.rename_doc('DocType', 'Production Order Item', 'Work Order Item', force=True) frappe.reload_doc('manufacturing', 'doctype', 'work_order_item') - rename_doc('DocType', 'Production Order Operation', 'Work Order Operation', force=True) + frappe.rename_doc('DocType', 'Production Order Operation', 'Work Order Operation', force=True) frappe.reload_doc('manufacturing', 'doctype', 'work_order_operation') frappe.reload_doc('projects', 'doctype', 'timesheet') diff --git a/erpnext/patches/v11_0/rename_supplier_type_to_supplier_group.py b/erpnext/patches/v11_0/rename_supplier_type_to_supplier_group.py index 52d4621c7b..c4b3838c71 100644 --- a/erpnext/patches/v11_0/rename_supplier_type_to_supplier_group.py +++ b/erpnext/patches/v11_0/rename_supplier_type_to_supplier_group.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals import frappe -from frappe.model.rename_doc import rename_doc from frappe.model.utils.rename_field import rename_field from frappe import _ from frappe.utils.nestedset import rebuild_tree @@ -9,7 +8,7 @@ def execute(): if frappe.db.table_exists("Supplier Group"): frappe.reload_doc('setup', 'doctype', 'supplier_group') elif frappe.db.table_exists("Supplier Type"): - rename_doc("DocType", "Supplier Type", "Supplier Group", force=True) + frappe.rename_doc("DocType", "Supplier Type", "Supplier Group", force=True) frappe.reload_doc('setup', 'doctype', 'supplier_group') frappe.reload_doc("accounts", "doctype", "pricing_rule") frappe.reload_doc("accounts", "doctype", "tax_rule") diff --git a/erpnext/patches/v12_0/rename_pricing_rule_child_doctypes.py b/erpnext/patches/v12_0/rename_pricing_rule_child_doctypes.py index 41ac8cff2b..b9ad622b0e 100644 --- a/erpnext/patches/v12_0/rename_pricing_rule_child_doctypes.py +++ b/erpnext/patches/v12_0/rename_pricing_rule_child_doctypes.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import frappe -from frappe.model.rename_doc import rename_doc doctypes = { 'Price Discount Slab': 'Promotional Scheme Price Discount', @@ -16,6 +15,6 @@ doctypes = { def execute(): for old_doc, new_doc in doctypes.items(): if not frappe.db.table_exists(new_doc) and frappe.db.table_exists(old_doc): - rename_doc('DocType', old_doc, new_doc) + frappe.rename_doc('DocType', old_doc, new_doc) frappe.reload_doc("accounts", "doctype", frappe.scrub(new_doc)) frappe.delete_doc("DocType", old_doc) diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index da53d8d6b1..cbd5e33b14 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -11,7 +11,6 @@ from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsE InvalidItemAttributeValueError, get_variant) from erpnext.stock.doctype.item.item import StockExistsForTemplate, InvalidBarcode from erpnext.stock.doctype.item.item import get_uom_conv_factor -from frappe.model.rename_doc import rename_doc from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.get_item_details import get_item_details @@ -348,7 +347,7 @@ class TestItem(unittest.TestCase): make_stock_entry(item_code="Test Item for Merging 2", target="_Test Warehouse 1 - _TC", qty=1, rate=100) - rename_doc("Item", "Test Item for Merging 1", "Test Item for Merging 2", merge=True) + frappe.rename_doc("Item", "Test Item for Merging 1", "Test Item for Merging 2", merge=True) self.assertFalse(frappe.db.exists("Item", "Test Item for Merging 1")) diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index dc39e101ce..e0483d3ab6 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -1,18 +1,22 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -from frappe.model.rename_doc import rename_doc -from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry + +import unittest + +import frappe from frappe.utils import cint -from erpnext import set_perpetual_inventory from frappe.test_runner import make_test_records -from erpnext.accounts.doctype.account.test_account import get_inventory_account, create_account import erpnext -import frappe -import unittest +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext import set_perpetual_inventory +from erpnext.accounts.doctype.account.test_account import get_inventory_account, create_account + + test_records = frappe.get_test_records('Warehouse') + class TestWarehouse(unittest.TestCase): def setUp(self): if not frappe.get_value('Item', '_Test Item'): @@ -41,7 +45,7 @@ class TestWarehouse(unittest.TestCase): # Rename with abbr if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"): frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC") - rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC") self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": "Test Warehouse for Renaming 1 - _TC"})) @@ -50,7 +54,7 @@ class TestWarehouse(unittest.TestCase): if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"): frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC") - rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3") self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": "Test Warehouse for Renaming 1 - _TC"})) @@ -58,7 +62,7 @@ class TestWarehouse(unittest.TestCase): # Another rename with multiple dashes if frappe.db.exists("Warehouse", "Test - Warehouse - Company - _TC"): frappe.delete_doc("Warehouse", "Test - Warehouse - Company - _TC") - rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company") + frappe.rename_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC", "Test - Warehouse - Company") def test_warehouse_merging(self): set_perpetual_inventory(1) @@ -78,7 +82,7 @@ class TestWarehouse(unittest.TestCase): {"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")) ) - rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC", + frappe.rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC", "Test Warehouse for Merging 2 - _TC", merge=True) self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - _TC"))