def import_data(dt, submit=False, overwrite=False): if not isinstance(dt, (tuple, list)): dt = [dt] for doctype in dt: # print "Importing", doctype.replace("_", " "), "..." import_doc(os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv"), submit=submit, overwrite=overwrite)
def import_doc(path, ignore_links=False, ignore_insert=False, insert=False): """Import a file using Data Import Tool.""" from frappe.core.page.data_import_tool import data_import_tool data_import_tool.import_doc(path, ignore_links=ignore_links, ignore_insert=ignore_insert, insert=insert)
def sync_fixtures(): for app in frappe.get_installed_apps(): if os.path.exists(frappe.get_app_path(app, "fixtures")): for fname in os.listdir(frappe.get_app_path(app, "fixtures")): if fname.endswith(".json") or fname.endswith(".csv"): import_doc(frappe.get_app_path(app, "fixtures", fname), ignore_links=True, overwrite=True)
def enable_shopping_cart(): # import path = os.path.join(os.path.dirname(__file__), "demo_docs", "Shopping Cart Settings.json") import_doc(path) # enable settings = frappe.get_doc("Shopping Cart Settings") settings.enabled = 1 settings.save()
def enable_shopping_cart(): # import path = os.path.join(os.path.dirname(__file__), "demo_docs", "Shopping Cart Settings.json") import_doc(path) # enable settings = frappe.get_doc("Shopping Cart Settings") settings.enabled = 1 settings.save()
def import_doc(context, path, force=False): "Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported" from frappe.core.page.data_import_tool import data_import_tool for site in context.sites: try: frappe.init(site=site) frappe.connect() data_import_tool.import_doc(path, overwrite=context.force) finally: frappe.destroy()
def import_doc(context, path, force=False): "Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported" from frappe.core.page.data_import_tool import data_import_tool for site in context.sites: try: frappe.init(site=site) frappe.connect() data_import_tool.import_doc(path, overwrite=context.force) finally: frappe.destroy()
def import_data(dt, submit=False, overwrite=False): if not isinstance(dt, (tuple, list)): dt = [dt] for doctype in dt: # print "Importing", doctype.replace("_", " "), "..." import_doc(os.path.join(os.path.dirname(__file__), "demo_docs", doctype + ".csv"), submit=submit, overwrite=overwrite)
def sync_fixtures(app=None): if app: apps = [app] else: apps = frappe.get_installed_apps() for app in apps: if os.path.exists(frappe.get_app_path(app, "fixtures")): for fname in os.listdir(frappe.get_app_path(app, "fixtures")): if fname.endswith(".json") or fname.endswith(".csv"): import_doc(frappe.get_app_path(app, "fixtures", fname), ignore_links=True, overwrite=True) frappe.db.commit()
def import_doc(context, path, force=False): "Import (insert/update) doclist. If the argument is a directory, all files ending with .json are imported" from frappe.core.page.data_import_tool import data_import_tool if not os.path.exists(path): path = os.path.join('..', path) if not os.path.exists(path): print('Invalid path {0}'.format(path)) sys.exit(1) for site in context.sites: try: frappe.init(site=site) frappe.connect() data_import_tool.import_doc(path, overwrite=context.force) finally: frappe.destroy()
def sync_fixtures(app=None): """Import, overwrite fixtures from `[app]/fixtures`""" if app: apps = [app] else: apps = frappe.get_installed_apps() for app in apps: if os.path.exists(frappe.get_app_path(app, "fixtures")): fixture_files = sorted( os.listdir(frappe.get_app_path(app, "fixtures"))) for fname in fixture_files: if fname.endswith(".json") or fname.endswith(".csv"): import_doc(frappe.get_app_path(app, "fixtures", fname), ignore_links=True, overwrite=True) import_custom_scripts(app) frappe.db.commit()
def import_doc(path, ignore_links=False, ignore_insert=False, insert=False): from frappe.core.page.data_import_tool import data_import_tool data_import_tool.import_doc(path, ignore_links=ignore_links, ignore_insert=ignore_insert, insert=insert)
def import_doc(path, force=False): from frappe.core.page.data_import_tool import data_import_tool frappe.connect() data_import_tool.import_doc(path, overwrite=force) frappe.destroy()
def import_data(dt, submit=False, overwrite=False): if not isinstance(dt, (tuple, list)): dt = [dt] for doctype in dt: import_doc(get_json_path(doctype), submit=submit, overwrite=overwrite)
def setup(): """ - Imports Custom_Field.csv - Import all the scripts in custom_scripts """ data_path = frappe.get_app_path("consoleerp_erpnext_client", "customizations", "territory_branch") # naming series data naming_series_data = { "Quotation": ["QTN-.consoleerp_territory_abbr.-"], "Sales Order": ["SO-.consoleerp_territory_abbr.-"], "Delivery Note": [ "DN-.consoleerp_territory_abbr.-", "DN-RET-.consoleerp_territory_abbr.-" ], "Sales Invoice": [ "SINV-.consoleerp_territory_abbr.-", "SINV-RET-.consoleerp_territory_abbr.-" ], "Material Request": ["MREQ-.consoleerp_territory_abbr.-"], "Request for Quotation": ["RFQ-.consoleerp_territory_abbr.-"], "Supplier Quotation": ["SQTN-.consoleerp_territory_abbr.-"], "Purchase Order": ["PO-.consoleerp_territory_abbr.-"], "Purchase Receipt": [ "PREC-.consoleerp_territory_abbr.-", "PREC-RET-.consoleerp_territory_abbr.-" ], "Purchase Invoice": [ "PINV-.consoleerp_territory_abbr.-", "PINV-RET-.consoleerp_territory_abbr.-" ], "Stock Entry": ["STE-.consoleerp_territory_abbr.-"], "Warehouse Transfer": ["WT-.consoleerp_territory_abbr.-"], "Payment Request": ["PR-.consoleerp_territory_abbr.-"], "Payment Entry": ["PE-.consoleerp_territory_abbr.-"] } if os.path.exists(data_path): # import Custom_Field.csv import_doc(data_path + os.path.sep + "Custom_Field.csv", ignore_links=True, overwrite=True) """ # import custom scripts------------------------------- for fname in os.listdir(data_path + os.path.sep + "custom_scripts"): if fname.endswith(".js"): with open(data_path + os.path.sep + "custom_scripts" + os.path.sep + fname) as f: doctype = fname.rsplit(".", 1)[0] script = f.read() if frappe.db.exists("Custom Script", {"dt" : doctype}): custom_script = frappe.get_doc("Custom Script", {"dt" : doctype}) custom_script.script = "%s\n\n// Custom Script from Console ERP ERPNext Client\n%s" % (custom_script.script, script) custom_script.save() else: frappe.get_doc({ "doctype" : "Custom Script", "dt" : doctype, "script_type" : "Client", "script" : script }).insert() """ # -------------------------------------------------------------------------- # import naming series for doctype in naming_series_data: # update in property setter prop_dict = { 'options': "\n".join(naming_series_data[doctype]), 'default': naming_series_data[doctype][0] } print doctype for prop in prop_dict: ps_exists = frappe.db.get_value( "Property Setter", { "field_name": 'naming_series', 'doc_type': doctype, 'property': prop }) if ps_exists: ps = frappe.get_doc('Property Setter', ps_exists) ps.value = prop_dict[prop] ps.save() else: ps = frappe.get_doc({ 'doctype': 'Property Setter', 'doctype_or_field': 'DocField', 'doc_type': doctype, 'field_name': 'naming_series', 'property': prop, 'value': prop_dict[prop], 'property_type': 'Text', '__islocal': 1 }) ps.save() return "1"