Example #1
0
    def test_item_merging(self):
        create_item("Test Item for Merging 1")
        create_item("Test Item for Merging 2")

        make_stock_entry(item_code="Test Item for Merging 1",
                         target="_Test Warehouse - _TC",
                         qty=1,
                         rate=100)
        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)

        self.assertFalse(frappe.db.exists("Item", "Test Item for Merging 1"))

        self.assertTrue(
            frappe.db.get_value(
                "Bin", {
                    "item_code": "Test Item for Merging 2",
                    "warehouse": "_Test Warehouse - _TC"
                }))

        self.assertTrue(
            frappe.db.get_value(
                "Bin", {
                    "item_code": "Test Item for Merging 2",
                    "warehouse": "_Test Warehouse 1 - _TC"
                }))
Example #2
0
def execute():
	for dt in doc_rename_map:
		if frappe.db.exists('DocType', dt):
			rename_doc('DocType', dt, doc_rename_map[dt], force=True)

	for dn in field_rename_map:
		if frappe.db.exists('DocType', dn):
			frappe.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))

	for dt, field_list in field_rename_map.items():
		if frappe.db.exists('DocType', dt):
			for field in field_list:
				if frappe.db.has_column(dt, field[0]):
					rename_field(dt, field[0], field[1])

	if frappe.db.exists('DocType', 'Practitioner Service Unit Schedule'):
		if frappe.db.has_column('Practitioner Service Unit Schedule', 'parentfield'):
			frappe.db.sql("""
				update `tabPractitioner Service Unit Schedule` set parentfield = 'practitioner_schedules'
				where parentfield = 'physician_schedules' and parenttype = 'Healthcare Practitioner'
			""")

	if frappe.db.exists("DocType", "Healthcare Practitioner"):
		frappe.reload_doc("healthcare", "doctype", "healthcare_practitioner")
		frappe.reload_doc("healthcare", "doctype", "practitioner_service_unit_schedule")
		if frappe.db.has_column('Healthcare Practitioner', 'physician_schedule'):
			for doc in frappe.get_all('Healthcare Practitioner'):
				_doc = frappe.get_doc('Healthcare Practitioner', doc.name)
				if _doc.physician_schedule:
					_doc.append('practitioner_schedules', {'schedule': _doc.physician_schedule})
					_doc.save()
Example #3
0
def merge(key, duplicates):
    old_key = key

    for dup in sorted(json.loads(duplicates)[key], reverse=True):
        rename_doc("Customer", old_key, dup['customer'], merge=True)

        old_key = dup['customer']
Example #4
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 1 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))

		# 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")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 2 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 2 - _TC"}))
		self.assertFalse(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		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")

		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 3 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
Example #5
0
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.reload_doc("accounts", "doctype", frappe.scrub(new_doc))
            frappe.delete_doc("DocType", old_doc)
Example #6
0
	def test_warehouse_merging(self):
		set_perpetual_inventory(1)

		create_warehouse("Test Warehouse for Merging 1")
		create_warehouse("Test Warehouse for Merging 2")

		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - _TC",
			qty=1, rate=100)
		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC",
			qty=1, rate=100)

		existing_bin_qty = (
			cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty"))
			+ cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty"))
		)

		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"))

		bin_qty = frappe.db.get_value("Bin",
			{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")

		self.assertEqual(bin_qty, existing_bin_qty)

		self.assertFalse(frappe.db.exists("Account", "Test Warehouse for Merging 1 - _TC"))
		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Merging 2 - _TC"))
		self.assertTrue(frappe.db.get_value("Account",
			filters={"warehouse": "Test Warehouse for Merging 2 - _TC"}))
Example #7
0
	def test_warehouse_merging(self):
		set_perpetual_inventory(1)

		create_warehouse("Test Warehouse for Merging 1")
		create_warehouse("Test Warehouse for Merging 2")

		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 1 - _TC",
			qty=1, rate=100)
		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC",
			qty=1, rate=100)

		existing_bin_qty = (
			cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty"))
			+ cint(frappe.db.get_value("Bin",
				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty"))
		)

		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"))

		bin_qty = frappe.db.get_value("Bin",
			{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")

		self.assertEqual(bin_qty, existing_bin_qty)

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Merging 2 - _TC"}))
Example #8
0
def setup_folder_path(filename, new_parent):
	file = frappe.get_doc("File", filename)
	file.folder = new_parent
	file.save()

	if file.is_folder:
		from frappe.model.rename_doc import rename_doc
		rename_doc("File", file.name, file.get_name_based_on_parent_folder(), ignore_permissions=True)
Example #9
0
def change_item_code(item, item_code, doc_name):
    if frappe.db.exists({'doctype': 'Item', 'item_code': item_code}):
        frappe.throw(
            _('Item with Item Code {0} already exists').format(item_code))
    else:
        rename_doc('Item', item, item_code, ignore_permissions=True)
        frappe.db.set_value('Healthcare Service Unit Type', doc_name,
                            'item_code', item_code)
def execute():
	if frappe.db.table_exists("Email Alert Recipient") and not frappe.db.table_exists("Notification Recipient"):
		rename_doc('DocType', 'Email Alert Recipient', 'Notification Recipient')
		frappe.reload_doc('email', 'doctype', 'notification_recipient')

	if frappe.db.table_exists("Email Alert") and not frappe.db.table_exists("Notification"):
		rename_doc('DocType', 'Email Alert', 'Notification')
		frappe.reload_doc('email', 'doctype', 'notification')
def change_item_code(item, item_code, doc_name):
    if frappe.db.exists({"doctype": "Item", "item_code": item_code}):
        frappe.throw(
            _("Item with Item Code {0} already exists").format(item_code))
    else:
        rename_doc("Item", item, item_code, ignore_permissions=True)
        frappe.db.set_value("Healthcare Service Unit Type", doc_name,
                            "item_code", item_code)
Example #12
0
def test_xero(id="INV4093"):
    # from xero import Xero
    # from xero.auth import PublicCredentials
    consumer_key = "06RRGPYM4SJXFEMRODT6F0GYJ42UKA"
    # consumer_secret = "COMNDKTM2AU54WADYU1I1YVBBRE4ZL"
    # credentials = PublicCredentials(consumer_key, consumer_secret)
    # print credentials.url
    from xero import Xero
    from xero.auth import PrivateCredentials
    import os
    file = "privatekey.pem"
    with open(os.path.dirname(os.path.abspath(__file__)) + '/data/' + file) as keyfile:
        rsa_key = keyfile.read()
    # print rsa_key
    credentials = PrivateCredentials(consumer_key, rsa_key)
    xero = Xero(credentials)
    invoices = xero.invoices.filter(raw='AmountDue > 0')
    # invoices = xero.invoices.filter(InvoiceNumber="INV4093")
    for inv in invoices:
        print inv
        inv = xero.invoices.get(inv['InvoiceNumber'])[0]
        inv_name = frappe.db.sql("""SELECT name FROM `tabSales Invoice`
                                            WHERE docstatus=1 AND outstanding_amount = 0.0
                                            and name=%s""",(inv['InvoiceNumber']))

        exists_so = frappe.db.sql("""SELECT Count(*) FROM `tabSales Order` WHERE name=%s""",(inv['InvoiceNumber']))
        print ">>>>>>>>>>>", inv_name
        if inv_name != () and exists_so[0][0] != 0:

            # created_at = parser.parse(inv["Date"])
            created_at = inv["Date"]

            # remove_imported_data(inv['InvoiceNumber'])
            remove_imported_data(inv['Reference'])


            pi = make_invoice(inv['Reference'], created_at, inv)
            # print inv
            frappe.db.commit()
            rename_doc("Sales Invoice", pi.name, inv['InvoiceNumber'], force=True)
            frappe.db.commit()


            if inv['AmountPaid']:
                payment_request = make_payment_request(dt="Sales Invoice", dn=inv['InvoiceNumber'], recipient_id="",
                                                       submit_doc=True, mute_email=True, use_dummy_message=True,
                                                       grand_total=float(inv['AmountPaid']),
                                                       posting_date=created_at.date(),
                                                       posting_time=str(created_at.time()),
                                                       inflow_file=inv['Reference'])

                payment_entry = frappe.get_doc(make_payment_entry(payment_request.name))
                payment_entry.posting_date = created_at.date()
                payment_entry.posting_time = str(created_at.time())
                payment_entry.set_posting_time = 1
                payment_entry.paid_amount = inv['AmountPaid']
                payment_entry.inflow_file = inv['Reference']
                payment_entry.submit()
Example #13
0
def change_item_code_from_template(item_code, doc):
	doc = frappe._dict(json.loads(doc))

	if frappe.db.exists('Item', {'item_code': item_code}):
		frappe.throw(_('Item with Item Code {0} already exists').format(item_code))
	else:
		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
Example #14
0
def execute():
    for cr in frappe.db.sql(
            "SELECT name, id FROM `tabJournal Voucher` WHERE voucher_type = 'Cash Receipt(CR)'"
            "AND docstatus = 1",
            as_dict=True):
        rename_doc('Journal Voucher',
                   cr.name,
                   'KJV-CR-{}'.format(cr.name.split('-')[0]),
                   force=True)
Example #15
0
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.reload_doc('assets', 'doctype', 'asset_value_adjustment')
Example #16
0
def execute():
    if frappe.db.exists("DocType", "Client Script"):
        return

    frappe.flags.ignore_route_conflict_validation = True
    rename_doc("DocType", "Custom Script", "Client Script")
    frappe.flags.ignore_route_conflict_validation = False

    frappe.reload_doctype("Client Script", force=True)
Example #17
0
def change_item_code_from_medication(item_code, doc):
	doc = frappe._dict(json.loads(doc))

	if frappe.db.exists('Item', {'item_code': item_code}):
		frappe.throw(_('Item with Item Code {0} already exists').format(item_code))
	else:
		rename_doc('Item', doc.item_code, item_code)
		frappe.db.set_value('Medication', doc.name, 'item_code', item_code)
	return
Example #18
0
def change_item_code_from_therapy(item_code, doc):
    doc = frappe._dict(json.loads(doc))

    if frappe.db.exists("Item", {"item_code": item_code}):
        frappe.throw(
            _("Item with Item Code {0} already exists").format(item_code))
    else:
        rename_doc("Item", doc.item, item_code, ignore_permissions=True)
        frappe.db.set_value("Therapy Type", doc.name, "item_code", item_code)
    return
Example #19
0
def change_item_code_from_template(item_code, doc):
    args = json.loads(doc)
    doc = frappe._dict(args)

    if (frappe.db.exists({"doctype": "Item", "item_code": item_code})):
        frappe.throw(_("Code {0} already exist").format(item_code))
    else:
        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
def change_test_code_from_template(lab_test_code, doc):
	doc = frappe._dict(json.loads(doc))

	if frappe.db.exists({ "doctype": "Item", "item_code": lab_test_code}):
		frappe.throw(_("Lab Test Item {0} already exist").format(lab_test_code))
	else:
		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.db.set_value("Lab Test Template", doc.name, "lab_test_name", lab_test_code)
		rename_doc("Lab Test Template", doc.name, lab_test_code, ignore_permissions=True)
	return lab_test_code
Example #21
0
def change_test_code_from_template(lab_test_code, doc):
	doc = frappe._dict(json.loads(doc))

	if frappe.db.exists({'doctype': 'Item', 'item_code': lab_test_code}):
		frappe.throw(_('Lab Test Item {0} already exist').format(lab_test_code))
	else:
		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.db.set_value('Lab Test Template', doc.name, 'lab_test_name', lab_test_code)
		rename_doc('Lab Test Template', doc.name, lab_test_code, ignore_permissions=True)
	return lab_test_code
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.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.reload_doc('assets', 'doctype', 'linked_location')

	if not frappe.db.table_exists('Crop Cycle'):
		frappe.reload_doc('agriculture', 'doctype', 'crop_cycle')

	# Rename the fields in related doctypes
	if 'linked_land_unit' in frappe.db.get_table_columns('Crop Cycle'):
		rename_field('Crop Cycle', 'linked_land_unit', 'linked_location')

	if 'land_unit' in frappe.db.get_table_columns('Linked Location'):
		rename_field('Linked Location', 'land_unit', 'location')
	
	if not frappe.db.exists("Location", "All Land Units"):
		frappe.get_doc({"doctype": "Location", "is_group": True, "location_name": "All Land Units"}).insert(ignore_permissions=True)

	if frappe.db.table_exists('Land Unit'):
		land_units = frappe.get_all('Land Unit', fields=['*'], order_by='lft')

		for land_unit in land_units:
			if not frappe.db.exists('Location', land_unit.get('land_unit_name')):
				frappe.get_doc({
					'doctype': 'Location',
					'location_name': land_unit.get('land_unit_name'),
					'parent_location': land_unit.get('parent_land_unit') or "All Land Units",
					'is_container': land_unit.get('is_container'),
					'is_group': land_unit.get('is_group'),
					'latitude': land_unit.get('latitude'),
					'longitude': land_unit.get('longitude'),
					'area': land_unit.get('area'),
					'location': land_unit.get('location'),
					'lft': land_unit.get('lft'),
					'rgt': land_unit.get('rgt')
				}).insert(ignore_permissions=True)

	# frappe.db.sql("""update `tabDesktop Icon` set label='Location', module_name='Location' where label='Land Unit'""")
	frappe.db.sql("""update `tabDesktop Icon` set link='List/Location' where link='List/Land Unit'""")

	# Delete the Land Unit and Linked Land Unit doctypes
	if frappe.db.table_exists('Land Unit'):
		frappe.delete_doc('DocType', 'Land Unit', force=1)

	if frappe.db.table_exists('Linked Land Unit'):
		frappe.delete_doc('DocType', 'Linked Land Unit', force=1)
Example #23
0
def execute():
    if frappe.db.table_exists(
            "Email Alert Recipient"
    ) and not frappe.db.table_exists("Notification Recipient"):
        rename_doc('DocType', 'Email Alert Recipient',
                   'Notification Recipient')
        frappe.reload_doc('email', 'doctype', 'notification_recipient')

    if frappe.db.table_exists(
            "Email Alert") and not frappe.db.table_exists("Notification"):
        rename_doc('DocType', 'Email Alert', 'Notification')
        frappe.reload_doc('email', 'doctype', 'notification')
def execute():
    if frappe.db.table_exists(
            "Email Alert Recipient"
    ) and not frappe.db.table_exists("Notification Recipient"):
        rename_doc("DocType", "Email Alert Recipient",
                   "Notification Recipient")
        frappe.reload_doc("email", "doctype", "notification_recipient")

    if frappe.db.table_exists(
            "Email Alert") and not frappe.db.table_exists("Notification"):
        rename_doc("DocType", "Email Alert", "Notification")
        frappe.reload_doc("email", "doctype", "notification")
Example #25
0
def execute():
    frappe.reload_doc("community", "doctype", "community_member")
    docs = frappe.get_all("Community Member")
    for doc in docs:
        member = frappe.get_doc("Community Member", doc.name)
        name = make_autoname("hash", "Community Member")
        rename_doc("Community Member",
                   member.name,
                   name,
                   force=True,
                   merge=False,
                   ignore_permissions=True,
                   ignore_if_exists=False)
Example #26
0
def upload(select_doctype=None, rows=None):
	from frappe.utils.csvutils import read_csv_content_from_uploaded_file
	from frappe.model.rename_doc import rename_doc

	if not select_doctype:
		select_doctype = frappe.form_dict.select_doctype

	if not frappe.has_permission(select_doctype, "write"):
		raise frappe.PermissionError

	if not rows:
		rows = read_csv_content_from_uploaded_file()
	if not rows:
		frappe.throw(_("Please select a valid csv file with data"))

	max_rows = 500
	if len(rows) > max_rows:
		frappe.throw(_("Maximum {0} rows allowed").format(max_rows))

	rename_log = []
	for row in rows:
		# if row has some content
		if len(row) > 1 and row[0] and row[1]:
			try:
				if rename_doc(select_doctype, row[0], row[1]):
					rename_log.append(_("Successful: ") + row[0] + " -> " + row[1])
					frappe.db.commit()
				else:
					rename_log.append(_("Ignored: ") + row[0] + " -> " + row[1])
			except Exception, e:
				rename_log.append("<span style='color: RED'>" + \
					_("Failed: ") + row[0] + " -> " + row[1] + "</span>")
				rename_log.append("<span style='margin-left: 20px;'>" + repr(e) + "</span>")
Example #27
0
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.reload_doc('setup', 'doctype', 'supplier_group')
		frappe.reload_doc("accounts", "doctype", "pricing_rule")
		frappe.reload_doc("accounts", "doctype", "tax_rule")
		frappe.reload_doc("buying", "doctype", "buying_settings")
		frappe.reload_doc("buying", "doctype", "supplier")
		rename_field("Supplier Group", "supplier_type", "supplier_group_name")
		rename_field("Supplier", "supplier_type", "supplier_group")
		rename_field("Buying Settings", "supplier_type", "supplier_group")
		rename_field("Pricing Rule", "supplier_type", "supplier_group")
		rename_field("Tax Rule", "supplier_type", "supplier_group")

	build_tree()
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.reload_doc('setup', 'doctype', 'supplier_group')
		frappe.reload_doc("accounts", "doctype", "pricing_rule")
		frappe.reload_doc("accounts", "doctype", "tax_rule")
		frappe.reload_doc("buying", "doctype", "buying_settings")
		frappe.reload_doc("buying", "doctype", "supplier")
		rename_field("Supplier Group", "supplier_type", "supplier_group_name")
		rename_field("Supplier", "supplier_type", "supplier_group")
		rename_field("Buying Settings", "supplier_type", "supplier_group")
		rename_field("Pricing Rule", "supplier_type", "supplier_group")
		rename_field("Tax Rule", "supplier_type", "supplier_group")

	build_tree()
Example #29
0
	def test_item_merging(self):
		create_item("Test Item for Merging 1")
		create_item("Test Item for Merging 2")

		make_stock_entry(item_code="Test Item for Merging 1", target="_Test Warehouse - _TC",
			qty=1, rate=100)
		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)

		self.assertFalse(frappe.db.exists("Item", "Test Item for Merging 1"))

		self.assertTrue(frappe.db.get_value("Bin",
			{"item_code": "Test Item for Merging 2", "warehouse": "_Test Warehouse - _TC"}))

		self.assertTrue(frappe.db.get_value("Bin",
			{"item_code": "Test Item for Merging 2", "warehouse": "_Test Warehouse 1 - _TC"}))
Example #30
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")
		account = get_inventory_account("_Test Company", "Test Warehouse for Renaming 1 - _TC")
		self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": account}))

		# 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")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		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")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# 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")
def execute():
	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.reload_doc('manufacturing', 'doctype', 'work_order_item')

	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')
	frappe.reload_doc('stock', 'doctype', 'stock_entry')
	rename_field("Timesheet", "production_order", "work_order")
	rename_field("Stock Entry", "production_order", "work_order")

	frappe.rename_doc("Report", "Production Orders in Progress", "Work Orders in Progress", force=True)
	frappe.rename_doc("Report", "Completed Production Orders", "Completed Work Orders", force=True)
	frappe.rename_doc("Report", "Open Production Orders", "Open Work Orders", force=True)
	frappe.rename_doc("Report", "Issued Items Against Production Order", "Issued Items Against Work Order", force=True)
	frappe.rename_doc("Report", "Production Order Stock Report", "Work Order Stock Report", force=True)

	frappe.db.sql("""update `tabDesktop Icon` \
		set label='Work Order', module_name='Work Order' \
		where label='Production Order'""")
	frappe.db.sql("""update `tabDesktop Icon` \
		set link='List/Work Order' \
		where link='List/Production Order'""")
Example #32
0
	def test_warehouse_renaming(self):
		set_perpetual_inventory(1)
		create_warehouse("Test Warehouse for Renaming 1")
		account = get_inventory_account("_Test Company", "Test Warehouse for Renaming 1 - _TC")
		self.assertTrue(frappe.db.get_value("Warehouse", filters={"account": account}))

		# 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")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# Rename without abbr
		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")

		self.assertTrue(frappe.db.get_value("Warehouse",
			filters={"account": "Test Warehouse for Renaming 1 - _TC"}))

		# 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")
def execute():
    frappe.reload_doc('stock', 'doctype', 'item')
    language = frappe.get_single("System Settings").language

    if language and language.startswith('en'): return

    frappe.local.lang = language

    all_domains = frappe.get_hooks("domains")

    for domain in all_domains:
        translated_domain = _(domain, lang=language)
        if frappe.db.exists("Domain", translated_domain):
            #if domain already exists merged translated_domain and domain
            merge = False
            if frappe.db.exists("Domain", domain):
                merge = True

            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)
            domain.setup_domain()

            if int(
                    frappe.db.get_single_value('System Settings',
                                               'setup_complete')):
                domain.setup_sidebar_items()
                domain.setup_desktop_icons()
                domain.set_default_portal_role()
    except frappe.LinkValidationError:
        pass
Example #34
0
def execute():
    for dt in doc_rename_map:
        if frappe.db.exists('DocType', dt):
            rename_doc('DocType', dt, doc_rename_map[dt], force=True)

    for dn in field_rename_map:
        if frappe.db.exists('DocType', dn):
            frappe.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))

    for dt, field_list in field_rename_map.items():
        if frappe.db.exists('DocType', dt):
            for field in field_list:
                if frappe.db.has_column(dt, field[0]):
                    rename_field(dt, field[0], field[1])

    if frappe.db.exists('DocType', 'Practitioner Service Unit Schedule'):
        if frappe.db.has_column('Practitioner Service Unit Schedule',
                                'parentfield'):
            frappe.db.sql("""
				update `tabPractitioner Service Unit Schedule` set parentfield = 'practitioner_schedules'
				where parentfield = 'physician_schedules' and parenttype = 'Healthcare Practitioner'
			""")
Example #35
0
def rename_doc(doctype,
               old,
               new,
               debug=0,
               force=False,
               merge=False,
               ignore_permissions=False):
    from frappe.model.rename_doc import rename_doc
    return rename_doc(doctype,
                      old,
                      new,
                      force=force,
                      merge=merge,
                      ignore_permissions=ignore_permissions)
Example #36
0
def merge_content_silid(doc,
                        existing_video_list,
                        existing_article_list,
                        video=None,
                        arti=None):
    if doc.is_video == 1:
        if existing_video_list:
            for video_hit in existing_video_list:
                rename_doc("Video",
                           video_hit['name'],
                           video.name,
                           merge=True,
                           ignore_permissions=True)
                frappe.db.commit()
    else:
        if existing_article_list:
            for article_hit in existing_article_list:
                rename_doc("Article",
                           article_hit['name'],
                           arti.name,
                           merge=True,
                           ignore_permissions=True)
                frappe.db.commit()
def execute():
	if frappe.db.exists("DocType","Google Maps") and not frappe.db.exists("DocType","Google Maps Settings"):
		rename_doc('DocType', 'Google Maps', 'Google Maps Settings')
		frappe.reload_doc('integrations', 'doctype', 'google_maps_settings')
Example #38
0
def rename_doc(doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False):
	from frappe.model.rename_doc import rename_doc
	return rename_doc(doctype, old, new, force=force, merge=merge, ignore_permissions=ignore_permissions)
Example #39
0
def rename_doc(*args, **kwargs):
	"""Rename a document. Calls `frappe.model.rename_doc.rename_doc`"""
	from frappe.model.rename_doc import rename_doc
	return rename_doc(*args, **kwargs)
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.reload_doc('assets', 'doctype', 'asset_value_adjustment')
def execute():
	if frappe.db.table_exists("Standard Reply") and not frappe.db.table_exists("Email Template"):
		rename_doc('DocType', 'Standard Reply', 'Email Template')
		frappe.reload_doc('email', 'doctype', 'email_template')
Example #42
0
def rename_doc(doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False):
	"""Rename a document. Calls `frappe.model.rename_doc.rename_doc`"""
	from frappe.model.rename_doc import rename_doc
	return rename_doc(doctype, old, new, force=force, merge=merge, ignore_permissions=ignore_permissions)
def execute():
	rename_doc('DocType', 'Health Insurance', 'Employee Health Insurance', force=True)
	frappe.reload_doc('hr', 'doctype', 'employee_health_insurance')