예제 #1
0
def execute():
	from dataent.core.doctype.file.file import make_home_folder

	if not dataent.db.exists("DocType", "File"):
		dataent.rename_doc("DocType", "File Data", "File")
		dataent.reload_doctype("File")

	if not dataent.db.exists("File", {"is_home_folder": 1}):
		make_home_folder()

	# make missing folders and set parent folder
	for file in dataent.get_all("File", filters={"is_folder": 0}):
		file = dataent.get_doc("File", file.name)
		file.flags.ignore_folder_validate = True
		file.flags.ignore_file_validate = True
		file.flags.ignore_duplicate_entry_error = True
		file.flags.ignore_links = True
		file.set_folder_name()
		try:
			file.save()
		except:
			print(dataent.get_traceback())
			raise

	from dataent.utils.nestedset import rebuild_tree
	rebuild_tree("File", "folder")

	# reset file size
	for folder in dataent.db.sql("""select name from tabFile f1 where is_folder = 1 and
		(select count(*) from tabFile f2 where f2.folder = f1.name and f2.is_folder = 1) = 0"""):
		folder = dataent.get_doc("File", folder[0])
		folder.save()
예제 #2
0
def execute():
	if not dataent.db.exists('DocType', 'Has Role'):
		dataent.rename_doc('DocType', 'Page Role', 'Has Role')
	reload_doc()
	set_ref_doctype_roles_to_report()
	copy_user_roles_to_has_roles()
	remove_doctypes()
예제 #3
0
파일: utils.py 프로젝트: dataent/epaas
def update_number_field(doctype_name, name, field_name, number_value, company):
	'''
		doctype_name = Name of the DocType
		name = Docname being referred
		field_name = Name of the field thats holding the 'number' attribute
		number_value = Numeric value entered in field_name

		Stores the number entered in the dialog to the DocType's field.

		Renames the document by adding the number as a prefix to the current name and updates
		all transaction where it was present.
	'''
	doc_title = dataent.db.get_value(doctype_name, name, dataent.scrub(doctype_name)+"_name")

	validate_field_number(doctype_name, name, number_value, company, field_name)

	dataent.db.set_value(doctype_name, name, field_name, number_value)

	if doc_title[0].isdigit():
		separator = " - " if " - " in doc_title else " "
		doc_title = doc_title.split(separator, 1)[1]

	dataent.db.set_value(doctype_name, name, dataent.scrub(doctype_name)+"_name", doc_title)

	new_name = get_autoname_with_number(number_value, doc_title, name, company)

	if name != new_name:
		dataent.rename_doc(doctype_name, name, new_name)
		return new_name
예제 #4
0
def execute():
	"""
		rename feedback request documents,
		update the feedback request and save the rating and communication
		reference in Feedback Request document
	"""

	dataent.reload_doc("core", "doctype", "feedback_request")
	feedback_requests = dataent.get_all("Feedback Request")
	for request in feedback_requests:
		communication, rating = dataent.db.get_value("Communication", { "feedback_request": request.get("name") },
			["name", "rating"]) or [None, 0]

		if communication:
			dataent.db.sql("""update `tabFeedback Request` set reference_communication='{communication}',
				rating={rating} where name='{feedback_request}'""".format(
					communication=communication,
					rating=rating or 0,
					feedback_request=request.get("name")
			))

		if "Feedback" not in request.get("name"):
			# rename the feedback request doc
			reference_name, creation = dataent.db.get_value("Feedback Request", request.get("name"), ["name", "creation"])
			oldname = request.get("name")
			newname = "Feedback for {doctype} {docname} on {datetime}".format(
				doctype="Feedback Request",
				docname=reference_name,
				datetime=creation
			)
			dataent.rename_doc("Feedback Request", oldname, newname, ignore_permissions=True)
			if communication: dataent.db.set_value("Communication", communication, "feedback_request", newname)
예제 #5
0
    def test_rename(self):
        # delete communication linked to these 2 customers
        for name in ("_Test Customer 1", "_Test Customer 1 Renamed"):
            dataent.db.sql(
                """delete from `tabCommunication`
				where communication_type='Comment' and reference_doctype=%s and reference_name=%s""",
                ("Customer", name))

        # add comments
        comment = dataent.get_doc("Customer", "_Test Customer 1").add_comment(
            "Comment", "Test Comment for Rename")

        # rename
        dataent.rename_doc("Customer", "_Test Customer 1",
                           "_Test Customer 1 Renamed")

        # check if customer renamed
        self.assertTrue(
            dataent.db.exists("Customer", "_Test Customer 1 Renamed"))
        self.assertFalse(dataent.db.exists("Customer", "_Test Customer 1"))

        # test that comment gets linked to renamed doc
        self.assertEqual(
            dataent.db.get_value(
                "Communication", {
                    "communication_type": "Comment",
                    "reference_doctype": "Customer",
                    "reference_name": "_Test Customer 1 Renamed"
                }), comment.name)

        # rename back to original
        dataent.rename_doc("Customer", "_Test Customer 1 Renamed",
                           "_Test Customer 1")
예제 #6
0
def execute():
	# rename the School module as Education

	# rename the school module
	if dataent.db.exists('Module Def', 'Schools') and not dataent.db.exists('Module Def', 'Education'):
		dataent.rename_doc("Module Def", "Schools", "Education")

	# delete the school module
	if dataent.db.exists('Module Def', 'Schools') and dataent.db.exists('Module Def', 'Education'):
		dataent.db.sql("""delete from `tabModule Def` where module_name = 'Schools'""")


	# rename "School Settings" to the "Education Settings
	if dataent.db.exists('DocType', 'School Settings'):
		dataent.rename_doc("DocType", "School Settings", "Education Settings", force=True)
		dataent.reload_doc("education", "doctype", "education_settings")

	# delete the discussion web form if exists
	if dataent.db.exists('Web Form', 'Discussion'):
		dataent.db.sql("""delete from `tabWeb Form` where name = 'discussion'""")

	# rename the select option field from "School Bus" to "Institute's Bus"
	dataent.reload_doc("education", "doctype", "Program Enrollment")
	if "mode_of_transportation" in dataent.db.get_table_columns("Program Enrollment"):
		dataent.db.sql("""update `tabProgram Enrollment` set mode_of_transportation = "Institute's Bus"
			where mode_of_transportation = "School Bus" """)
예제 #7
0
def execute():
	dataent.rename_doc('Language', 'zh-cn', 'zh', force=True,
		merge=True if dataent.db.exists('Language', 'zh') else False)
	if dataent.db.get_value('Language', 'zh-tw') == 'zh-tw':
		dataent.rename_doc('Language', 'zh-tw', 'zh-TW', force=True)

	dataent.db.set_value('Language', 'zh', 'language_code', 'zh')
	dataent.db.set_value('Language', 'zh-TW', 'language_code', 'zh-TW')
예제 #8
0
def rename_and_reload_doctypes():
	if "tabVariant Attribute" in dataent.db.get_tables():
		dataent.rename_doc("DocType", "Variant Attribute", "Item Variant Attribute")

	dataent.reload_doctype("Item")
	dataent.reload_doc("Stock", "DocType", "Item Variant Attribute")
	dataent.reload_doc("Stock", "DocType", "Item Attribute Value")
	dataent.reload_doc("Stock", "DocType", "Item Attribute")
예제 #9
0
def change_item_code(item, item_code, doc_name):
    item_exist = dataent.db.exists({"doctype": "Item", "item_code": item_code})
    if (item_exist):
        dataent.throw(_("Code {0} already exist").format(item_code))
    else:
        dataent.rename_doc("Item", item, item_code, ignore_permissions=True)
        dataent.db.set_value("Healthcare Service Unit Type", doc_name,
                             "item_code", item_code)
예제 #10
0
def execute():
	hr = dataent.db.get_value("Module Def", "HR")
	if hr == "Hr":
		dataent.rename_doc("Module Def", "Hr", "HR")
		dataent.db.set_value("Module Def", "HR", "module_name", "HR")

	dataent.clear_cache()
	dataent.setup_module_map()
예제 #11
0
def execute():
    tables = dataent.db.sql_list("show tables")
    if "tabUser" not in tables:
        dataent.rename_doc("DocType", "Profile", "User", force=True)

    dataent.reload_doc("website", "doctype", "blogger")

    if "profile" in get_table_columns("Blogger"):
        rename_field("Blogger", "profile", "user")
예제 #12
0
	def test_merge_leaves(self):
		dataent.rename_doc("Item Group", "_Test Item Group B - 2", "_Test Item Group B - 1", merge=True)
		records_to_test = test_records[2:]
		del records_to_test[3]
		self.test_basic_tree(records=records_to_test)

		# insert Group B - 2back
		dataent.copy_doc(test_records[5]).insert()
		self.test_basic_tree()
예제 #13
0
파일: file.py 프로젝트: dataent/dataent
def setup_folder_path(filename, new_parent):
    file = dataent.get_doc("File", filename)
    file.folder = new_parent
    file.save()

    if file.is_folder:
        dataent.rename_doc("File",
                           file.name,
                           file.get_name_based_on_parent_folder(),
                           ignore_permissions=True)
예제 #14
0
def execute():
    if dataent.db.table_exists("Sales Taxes and Charges Master"):
        dataent.rename_doc("DocType", "Sales Taxes and Charges Master",
                           "Sales Taxes and Charges Template")
        dataent.delete_doc("DocType", "Sales Taxes and Charges Master")

    if dataent.db.table_exists("Purchase Taxes and Charges Master"):
        dataent.rename_doc("DocType", "Purchase Taxes and Charges Master",
                           "Purchase Taxes and Charges Template")
        dataent.delete_doc("DocType", "Purchase Taxes and Charges Master")
예제 #15
0
def link_customer_and_address(raw_billing_data,customer_status):

	if customer_status == 0:
		# create
		customer = dataent.new_doc("Customer")
		address = dataent.new_doc("Address")

	if customer_status == 1:
		# Edit
		customer_woo_com_email = raw_billing_data.get("email")
		customer = dataent.get_doc("Customer",{"woocommerce_email": customer_woo_com_email})
		old_name = customer.customer_name

	full_name = str(raw_billing_data.get("first_name"))+ " "+str(raw_billing_data.get("last_name"))
	customer.customer_name = full_name
	customer.woocommerce_email = str(raw_billing_data.get("email"))
	customer.save()
	dataent.db.commit()

	if customer_status == 1:
		dataent.rename_doc("Customer", old_name, full_name)
		address = dataent.get_doc("Address",{"woocommerce_email":customer_woo_com_email})
		customer = dataent.get_doc("Customer",{"woocommerce_email": customer_woo_com_email})

	address.address_line1 = raw_billing_data.get("address_1", "Not Provided")
	address.address_line2 = raw_billing_data.get("address_2", "Not Provided")
	address.city = raw_billing_data.get("city", "Not Provided")
	address.woocommerce_email = str(raw_billing_data.get("email"))
	address.address_type = "Shipping"
	address.country = dataent.get_value("Country", filters={"code":raw_billing_data.get("country", "IN").lower()})
	address.state =  raw_billing_data.get("state")
	address.pincode =  str(raw_billing_data.get("postcode"))
	address.phone = str(raw_billing_data.get("phone"))
	address.email_id = str(raw_billing_data.get("email"))

	address.append("links", {
		"link_doctype": "Customer",
		"link_name": customer.customer_name
	})

	address.save()
	dataent.db.commit()

	if customer_status == 1:

		address = dataent.get_doc("Address",{"woocommerce_email":customer_woo_com_email})
		old_address_title = address.name
		new_address_title = customer.customer_name+"-billing"
		address.address_title = customer.customer_name
		address.save()

		dataent.rename_doc("Address",old_address_title,new_address_title)

	dataent.db.commit()
def execute():
    if dataent.db.table_exists(
            "Offer Letter") and not dataent.db.table_exists("Job Offer"):
        dataent.rename_doc("DocType", "Offer Letter", "Job Offer", force=True)
        dataent.rename_doc("DocType",
                           "Offer Letter Term",
                           "Job Offer Term",
                           force=True)
        dataent.reload_doc("hr", "doctype", "job_offer")
        dataent.reload_doc("hr", "doctype", "job_offer_term")
        dataent.delete_doc("Print Format", "Offer Letter")
예제 #17
0
def execute():
    if dataent.db.table_exists(
            "Time Sheet") and not dataent.db.table_exists("Timesheet"):
        dataent.rename_doc("DocType", "Time Sheet", "Timesheet")
        dataent.rename_doc("DocType", "Time Sheet Detail", "Timesheet Detail")

        for doctype in ['Time Sheet', 'Time Sheet Detail']:
            dataent.delete_doc('DocType', doctype)

        report = "Daily Time Sheet Summary"
        if dataent.db.exists("Report", report):
            dataent.delete_doc('Report', report)
예제 #18
0
def execute():
    if not 'tabError Log' in dataent.db.get_tables():
        dataent.rename_doc('DocType', 'Scheduler Log', 'Error Log')
        dataent.db.sql(
            """delete from `tabError Log` where datediff(curdate(), creation) > 30"""
        )
        dataent.db.commit()
        dataent.db.sql(
            'alter table `tabError Log` change column name name varchar(140)')
        dataent.db.sql(
            'alter table `tabError Log` change column parent parent varchar(140)'
        )
        dataent.db.sql('alter table `tabError Log` engine=MyISAM')
def execute():
    dataent.reload_doc("non_profit", "doctype", "member")
    old_named_members = dataent.get_all(
        "Member", filters={"name": ("not like", "MEM-%")})
    correctly_named_members = dataent.get_all(
        "Member", filters={"name": ("like", "MEM-%")})
    current_index = len(correctly_named_members)

    for member in old_named_members:
        current_index += 1
        dataent.rename_doc("Member", member["name"],
                           "MEM-" + str(current_index).zfill(5))

    dataent.db.sql("""update `tabMember` set naming_series = 'MEM-'""")
예제 #20
0
def change_test_code_from_template(lab_test_code, doc):
	args = json.loads(doc)
	doc = dataent._dict(args)

	item_exist = dataent.db.exists({
		"doctype": "Item",
		"item_code": lab_test_code})
	if(item_exist):
		dataent.throw(_("Code {0} already exist").format(lab_test_code))
	else:
		dataent.rename_doc("Item", doc.name, lab_test_code, ignore_permissions = True)
		dataent.db.set_value("Lab Test Template",doc.name,"lab_test_code",lab_test_code)
		dataent.rename_doc("Lab Test Template", doc.name, lab_test_code, ignore_permissions = True)
	return lab_test_code
예제 #21
0
def change_item_code_from_template(item_code, doc):
    args = json.loads(doc)
    doc = dataent._dict(args)

    if (dataent.db.exists({"doctype": "Item", "item_code": item_code})):
        dataent.throw(_("Code {0} already exist").format(item_code))
    else:
        dataent.rename_doc("Item",
                           doc.item_code,
                           item_code,
                           ignore_permissions=True)
        dataent.db.set_value("Clinical Procedure Template", doc.name,
                             "item_code", item_code)
    return
예제 #22
0
def execute():
    rename_doc('DocType', 'Production Order', 'Work Order', force=True)
    dataent.reload_doc('manufacturing', 'doctype', 'work_order')

    rename_doc('DocType',
               'Production Order Item',
               'Work Order Item',
               force=True)
    dataent.reload_doc('manufacturing', 'doctype', 'work_order_item')

    rename_doc('DocType',
               'Production Order Operation',
               'Work Order Operation',
               force=True)
    dataent.reload_doc('manufacturing', 'doctype', 'work_order_operation')

    dataent.reload_doc('projects', 'doctype', 'timesheet')
    dataent.reload_doc('stock', 'doctype', 'stock_entry')
    rename_field("Timesheet", "production_order", "work_order")
    rename_field("Stock Entry", "production_order", "work_order")

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

    dataent.db.sql("""update `tabDesktop Icon` \
		set label='Work Order', module_name='Work Order' \
		where label='Production Order'""")
    dataent.db.sql("""update `tabDesktop Icon` \
		set link='List/Work Order' \
		where link='List/Production Order'""")
예제 #23
0
def execute():
	if dataent.db.exists("DocType", "Examination"):
		dataent.rename_doc("DocType", "Examination", "Assessment")
		dataent.rename_doc("DocType", "Examination Result", "Assessment Result")

		# 'Schools' module changed to the 'Education'
		# dataent.reload_doc("schools", "doctype", "assessment")
		# dataent.reload_doc("schools", "doctype", "assessment_result")

		dataent.reload_doc("education", "doctype", "assessment")
		dataent.reload_doc("education", "doctype", "assessment_result")

		rename_field("Assessment", "exam_name", "assessment_name")
		rename_field("Assessment", "exam_code", "assessment_code")
	
		dataent.db.sql("delete from `tabPortal Menu Item` where route = '/examination'")
예제 #24
0
파일: client.py 프로젝트: dataent/dataent
def rename_doc(doctype, old_name, new_name, merge=False):
    '''Rename document

	:param doctype: DocType of the document to be renamed
	:param old_name: Current `name` of the document to be renamed
	:param new_name: New `name` to be set'''
    new_name = dataent.rename_doc(doctype, old_name, new_name, merge=merge)
    return new_name
예제 #25
0
def update_account_number(name, account_name, account_number=None):

    account = dataent.db.get_value("Account", name, "company", as_dict=True)
    if not account: return
    validate_account_number(name, account_number, account.company)
    if account_number:
        dataent.db.set_value("Account", name, "account_number",
                             account_number.strip())
    else:
        dataent.db.set_value("Account", name, "account_number", "")
    dataent.db.set_value("Account", name, "account_name", account_name.strip())

    new_name = get_account_autoname(account_number, account_name,
                                    account.company)
    if name != new_name:
        dataent.rename_doc("Account", name, new_name, force=1)
        return new_name
예제 #26
0
def execute():
    doctype = 'POS Profile'
    dataent.reload_doctype(doctype)

    for pos in dataent.get_all(doctype, filters={'disabled': 0}):
        doc = dataent.get_doc(doctype, pos.name)

        if not doc.user: continue

        try:
            pos_profile_name = doc.user + ' - ' + doc.company
            doc.flags.ignore_validate = True
            doc.flags.ignore_mandatory = True
            doc.save()

            dataent.rename_doc(doctype, doc.name, pos_profile_name, force=True)
        except dataent.LinkValidationError:
            dataent.db.set_value("POS Profile", doc.name, 'disabled', 1)
예제 #27
0
	def test_merge_groups(self):
		dataent.rename_doc("Item Group", "_Test Item Group B", "_Test Item Group C", merge=True)
		records_to_test = test_records[2:]
		del records_to_test[1]
		self.test_basic_tree(records=records_to_test)

		# insert Group B back
		dataent.copy_doc(test_records[3]).insert()
		self.test_basic_tree()

		# move its children back
		for name in dataent.db.sql_list("""select name from `tabItem Group`
			where parent_item_group='_Test Item Group C'"""):

			doc = dataent.get_doc("Item Group", name)
			doc.parent_item_group = "_Test Item Group B"
			doc.save()

		self.test_basic_tree()
예제 #28
0
def execute():
    # rename doctypes
    tables = dataent.db.sql_list("show tables")
    for old_dt, new_dt in [["Journal Voucher Detail", "Journal Entry Account"],
                           ["Journal Voucher", "Journal Entry"],
                           [
                               "Budget Distribution Detail",
                               "Monthly Distribution Percentage"
                           ], ["Budget Distribution", "Monthly Distribution"]]:
        if "tab" + new_dt not in tables:
            dataent.rename_doc("DocType", old_dt, new_dt, force=True)

    # reload new child doctypes
    dataent.reload_doc("manufacturing", "doctype", "work_order_operation")
    dataent.reload_doc("manufacturing", "doctype", "workstation_working_hour")
    dataent.reload_doc("stock", "doctype", "item_variant")
    dataent.reload_doc("hr", "doctype", "salary_detail")
    dataent.reload_doc("accounts", "doctype", "party_account")
    dataent.reload_doc("accounts", "doctype", "fiscal_year_company")

    #rename table fieldnames
    for dn in rename_map:
        if not dataent.db.exists("DocType", dn):
            continue
        dataent.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))

    for dt, field_list in rename_map.items():
        if not dataent.db.exists("DocType", dt):
            continue
        for field in field_list:
            rename_field(dt, field[0], field[1])

    # update voucher type
    for old, new in [["Bank Voucher", "Bank Entry"],
                     ["Cash Voucher", "Cash Entry"],
                     ["Credit Card Voucher", "Credit Card Entry"],
                     ["Contra Voucher", "Contra Entry"],
                     ["Write Off Voucher", "Write Off Entry"],
                     ["Excise Voucher", "Excise Entry"]]:
        dataent.db.sql(
            "update `tabJournal Entry` set voucher_type=%s where voucher_type=%s",
            (new, old))
예제 #29
0
def execute():
    reload_doctypes_for_schools_icons()

    dataent.reload_doc('website', 'doctype', 'portal_settings')
    dataent.reload_doc('website', 'doctype', 'portal_menu_item')
    dataent.reload_doc('buying', 'doctype', 'request_for_quotation')

    if 'schools' in dataent.get_installed_apps():
        dataent.db.sql("""delete from `tabDesktop Icon`""")

        if not dataent.db.exists('Module Def',
                                 'Schools') and dataent.db.exists(
                                     'Module Def', 'Academics'):

            # 'Schools' module changed to the 'Education'
            # dataent.rename_doc("Module Def", "Academics", "Schools")

            dataent.rename_doc("Module Def", "Academics", "Education")

        remove_from_installed_apps("schools")
예제 #30
0
def execute():
	# 'Schools' module changed to the 'Education'


	dataent.rename_doc("DocType", "Evaluation Criteria", "Assessment Criteria", force=True)
	# dataent.reload_doc("schools", "doctype", "assessment_criteria")
	dataent.reload_doc("education", "doctype", "assessment_criteria")
	if 'evaluation_criteria' in dataent.db.get_table_columns('Assessment Criteria'):
		rename_field("Assessment Criteria", "evaluation_criteria", "assessment_criteria")

	dataent.rename_doc("DocType", "Assessment Evaluation Criteria", "Assessment Plan Criteria", force=True)
	# dataent.reload_doc("schools", "doctype", "assessment_plan_criteria")
	dataent.reload_doc("education", "doctype", "assessment_plan_criteria")
	if 'evaluation_criteria' in dataent.db.get_table_columns('Assessment Plan'):
		rename_field("Assessment Plan Criteria", "evaluation_criteria", "assessment_criteria")

	# dataent.reload_doc("schools", "doctype", "assessment_plan")
	dataent.reload_doc("education", "doctype", "assessment_plan")
	rename_field("Assessment Plan", "evaluation_criterias", "assessment_criteria")

	# dataent.reload_doc("schools", "doctype", "assessment_result_detail")
	dataent.reload_doc("education", "doctype", "assessment_result_detail")
	if 'evaluation_criteria' in dataent.db.get_table_columns('Assessment Result Detail'):
		rename_field("Assessment Result Detail", "evaluation_criteria", "assessment_criteria")

	dataent.rename_doc("DocType", "Course Evaluation Criteria", "Course Assessment Criteria", force=True)
	# dataent.reload_doc("schools", "doctype", "course_assessment_criteria")
	dataent.reload_doc("education", "doctype", "course_assessment_criteria")
	if 'evaluation_criteria' in dataent.db.get_table_columns('Course Assessment Criteria'):
		rename_field("Course Assessment Criteria", "evaluation_criteria", "assessment_criteria")

	# dataent.reload_doc("schools", "doctype", "course")
	dataent.reload_doc("education", "doctype", "course")
	if 'evaluation_criteria' in dataent.db.get_table_columns('Course'):
		rename_field("Course", "evaluation_criterias", "assessment_criteria")