def execute():
	if not frappe.db.exists("DocType", "Compliance Item"):
		return

	compliance_items = frappe.get_all("Compliance Item", fields=["*"])

	frappe.reload_doc("stock", "doctype", "item")
	sync_customizations("bloomstack_core")

	fields = ["requires_lab_tests", "enable_cultivation_tax",
		"strain_type", "item_category", "enable_metrc",
		"metrc_id", "metrc_item_category", "metrc_unit_value",
		"metrc_uom", "metrc_unit_uom", "bloomtrace_id"]

	for item in compliance_items:
		if not item.item_code:
			continue

		frappe.db.set_value("Item", item.item_code, "is_compliance_item", True, update_modified=False)

		for field in fields:
			if item.get(field):
				frappe.db.set_value("Item", item.item_code, field, item.get(field), update_modified=False)

	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-enable_metrc")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-sb_item_details")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-metrc_id")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-metrc_item_category")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-metrc_unit_value")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-cb_item_details")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-metrc_uom")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-metrc_unit_uom")
	frappe.delete_doc_if_exists("Custom Field", "Compliance Item-bloomtrace_id")
예제 #2
0
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:

	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)'''
	clear_global_cache()

	# run patches
	frappe.modules.patch_handler.run_all()
	# sync
	frappe.model.sync.sync_all(verbose=verbose)
	frappe.translate.clear_cache()
	sync_fixtures()
	sync_customizations()
	sync_desktop_icons()
	sync_languages()

	frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

	# syncs statics
	render.clear_cache()

	frappe.db.commit()

	if not frappe.conf.get('global_help_setup'):
		# sync help if not set as global
		frappe.utils.help.sync()

	clear_notifications()

	frappe.publish_realtime("version-update")
예제 #3
0
def migrate(verbose=True, rebuild_website=False, skip_failing=False):
	'''Migrate all apps to the latest version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''

	touched_tables_file = frappe.get_site_path('touched_tables.json')
	if os.path.exists(touched_tables_file):
		os.remove(touched_tables_file)

	try:
		frappe.flags.touched_tables = set()
		frappe.flags.in_migrate = True

		clear_global_cache()

		#run before_migrate hooks
		for app in frappe.get_installed_apps():
			for fn in frappe.get_hooks('before_migrate', app_name=app):
				frappe.get_attr(fn)()

		# run patches
		frappe.modules.patch_handler.run_all(skip_failing)
		# sync
		frappe.model.sync.sync_all(verbose=verbose)
		frappe.translate.clear_cache()
		sync_jobs()
		sync_fixtures()
		sync_customizations()
		sync_languages()

		frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

		# syncs statics
		render.clear_cache()

		# add static pages to global search
		global_search.update_global_search_for_all_web_pages()

		#run after_migrate hooks
		for app in frappe.get_installed_apps():
			for fn in frappe.get_hooks('after_migrate', app_name=app):
				frappe.get_attr(fn)()

		frappe.db.commit()

		clear_notifications()

		frappe.publish_realtime("version-update")
		frappe.flags.in_migrate = False
	finally:
		with open(touched_tables_file, 'w') as f:
			json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4)
		frappe.flags.touched_tables.clear()
예제 #4
0
def install_app(name, verbose=False, set_as_patched=True):
    frappe.flags.in_install = name
    frappe.flags.ignore_in_install = False

    frappe.clear_cache()
    app_hooks = frappe.get_hooks(app_name=name)
    installed_apps = frappe.get_installed_apps()

    # install pre-requisites
    if app_hooks.required_apps:
        for app in app_hooks.required_apps:
            install_app(app, verbose=verbose)

    frappe.flags.in_install = name
    frappe.clear_cache()

    if name not in frappe.get_all_apps():
        raise Exception("App not in apps.txt")

    if name in installed_apps:
        frappe.msgprint(_("App {0} already installed").format(name))
        return

    print("\nInstalling {0}...".format(name))

    if name != "frappe":
        frappe.only_for("System Manager")

    for before_install in app_hooks.before_install or []:
        out = frappe.get_attr(before_install)()
        if out == False:
            return

    if name != "frappe":
        add_module_defs(name)

    sync_for(name,
             force=True,
             sync_everything=True,
             verbose=verbose,
             reset_permissions=True)

    add_to_installed_apps(name)

    frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

    if set_as_patched:
        set_all_patches_as_completed(name)

    for after_install in app_hooks.after_install or []:
        frappe.get_attr(after_install)()

    sync_jobs()
    sync_fixtures(name)
    sync_customizations(name)

    for after_sync in app_hooks.after_sync or []:
        frappe.get_attr(after_sync)()  #

    frappe.flags.in_install = False
def execute():
    frappe.reload_doc('bloomstack_core', 'doctype',
                      frappe.scrub('Package Tag'))
    sync_customizations("bloomstack_core")

    doctypes = ["Batch", "Purchase Receipt Item", "Stock Entry Detail"]

    for doctype in doctypes:
        item_code_field = "item" if doctype == "Batch" else "item_code"

        packages = frappe.get_all(
            doctype,
            filters={"package_tag": ["!=", ""]},
            fields=["package_tag", item_code_field, "item_name"],
            distinct=1)

        for package in packages:
            package_doc = frappe.new_doc("Package Tag")
            package_doc.update({
                "package_tag": package.package_tag,
                "item_code": package.get(item_code_field),
                "item_name": package.item_name
            })

            try:
                package_doc.insert()
            except frappe.DuplicateEntryError:
                continue
예제 #6
0
def execute():
	sync_customizations("bloomstack_core")
	batches = frappe.get_all("Batch" , fields=["name", "item"])

	for batch in batches:
		item_group = frappe.db.get_value("Item", batch.item, "item_group")
		frappe.db.set_value("Batch", batch.name, "item_group", item_group, update_modified=False)
예제 #7
0
파일: migrate.py 프로젝트: frappe/frappe
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''

	touched_tables_file = frappe.get_site_path('touched_tables.json')
	if os.path.exists(touched_tables_file):
		os.remove(touched_tables_file)

	try:
		frappe.flags.touched_tables = set()
		frappe.flags.in_migrate = True
		clear_global_cache()

		#run before_migrate hooks
		for app in frappe.get_installed_apps():
			for fn in frappe.get_hooks('before_migrate', app_name=app):
				frappe.get_attr(fn)()

		# run patches
		frappe.modules.patch_handler.run_all()
		# sync
		frappe.model.sync.sync_all(verbose=verbose)
		frappe.translate.clear_cache()
		sync_fixtures()
		sync_customizations()
		sync_desktop_icons()
		sync_languages()

		frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

		# syncs statics
		render.clear_cache()

		# add static pages to global search
		router.sync_global_search()

		#run after_migrate hooks
		for app in frappe.get_installed_apps():
			for fn in frappe.get_hooks('after_migrate', app_name=app):
				frappe.get_attr(fn)()

		frappe.db.commit()

		clear_notifications()

		frappe.publish_realtime("version-update")
		frappe.flags.in_migrate = False
	finally:
		with open(touched_tables_file, 'w') as f:
			json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4)
		frappe.flags.touched_tables.clear()
def execute():
    sync_customizations("bloomstack_core")
    drivers = frappe.get_all("Driver", filters={"employee": ["!=", ""]}, fields=["name", "employee"])

    for driver in drivers:
        user_id = frappe.db.get_value("Employee", driver.employee, "user_id")
        if user_id:
            frappe.db.set_value("Driver", driver.name, "user_id", user_id, update_modified=False)
예제 #9
0
파일: installer.py 프로젝트: ESS-LLP/frappe
def install_app(name, verbose=False, set_as_patched=True):
	frappe.flags.in_install = name
	frappe.flags.ignore_in_install = False

	frappe.clear_cache()
	app_hooks = frappe.get_hooks(app_name=name)
	installed_apps = frappe.get_installed_apps()

	# install pre-requisites
	if app_hooks.required_apps:
		for app in app_hooks.required_apps:
			install_app(app)

	frappe.flags.in_install = name
	frappe.clear_cache()

	if name not in frappe.get_all_apps():
		raise Exception("App not in apps.txt")

	if name in installed_apps:
		frappe.msgprint(_("App {0} already installed").format(name))
		return

	print("\nInstalling {0}...".format(name))

	if name != "frappe":
		frappe.only_for("System Manager")

	for before_install in app_hooks.before_install or []:
		out = frappe.get_attr(before_install)()
		if out==False:
			return

	if name != "frappe":
		add_module_defs(name)

	sync_for(name, force=True, sync_everything=True, verbose=verbose, reset_permissions=True)

	sync_from_app(name)

	add_to_installed_apps(name)

	frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

	if set_as_patched:
		set_all_patches_as_completed(name)

	for after_install in app_hooks.after_install or []:
		frappe.get_attr(after_install)()

	sync_fixtures(name)
	sync_customizations(name)

	for after_sync in app_hooks.after_sync or []:
		frappe.get_attr(after_sync)() #

	frappe.flags.in_install = False
def execute():
    sync_customizations("bloomstack_core")
    timesheets = frappe.get_all("Timesheet Detail", fields=["name", "task"])

    for timesheet in timesheets:
        task_name = frappe.db.get_value("Task", timesheet.task, "subject")
        frappe.db.set_value("Timesheet Detail",
                            timesheet.name,
                            "task_name",
                            task_name,
                            update_modified=False)
예제 #11
0
def execute():
    sync_customizations("bloomstack_core")

    doctypes = ["Quotation", "Sales Order", "Sales Invoice", "Delivery Note"]

    for doctype in doctypes:
        frappe.db.sql("""
			UPDATE
				`tab{doctype}`
			SET
				order_type = new_order_type
		""".format(doctype=doctype))
예제 #12
0
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''
	frappe.flags.in_migrate = True
	clear_global_cache()

	#run before_migrate hooks
	for app in frappe.get_installed_apps():
		for fn in frappe.get_hooks('before_migrate', app_name=app):
			frappe.get_attr(fn)()

	# run patches
	frappe.modules.patch_handler.run_all()
	# sync
	frappe.model.sync.sync_all(verbose=verbose)
	frappe.translate.clear_cache()
	sync_fixtures()
	sync_customizations()
	sync_desktop_icons()
	sync_languages()

	frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

	# syncs statics
	render.clear_cache()

	# add static pages to global search
	router.sync_global_search()

	#run after_migrate hooks
	for app in frappe.get_installed_apps():
		for fn in frappe.get_hooks('after_migrate', app_name=app):
			frappe.get_attr(fn)()

	frappe.db.commit()

	if not frappe.conf.get('global_help_setup'):
		# sync help if not set as global
		frappe.utils.help.sync()

	clear_notifications()

	frappe.publish_realtime("version-update")
	frappe.flags.in_migrate = False
예제 #13
0
def execute():
	sync_customizations("bloomstack_core")

	leads = frappe.get_all("Lead", fields=["name", "creation"])
	for lead in leads:
		result = frappe.db.get_value("Customer", {"lead_name": lead.name}, ["creation", "opening_date"], as_dict=True)
		if result:
			frappe.db.set_value("Lead", lead.name, "account_opened_date", result.opening_date or result.creation)

	customers = frappe.get_all("Customer", filters={"lead_name": ("!=", "")}, fields=["opening_date", "lead_name"])
	for customer in customers:
		if customer.lead_name:
			frappe.db.set_value("Lead", customer.lead_name, "account_opened_date", customer.opening_date)
예제 #14
0
def execute():
    sync_customizations("bloomstack_core")

    frappe.db.sql("""
		UPDATE
			`tabSales Order`
		SET
			is_overdue = 1
		WHERE
			docstatus = 1
				AND delivery_date < CURDATE()
				AND status NOT IN ("On Hold", "Closed", "Completed")
				AND skip_delivery_note = 0
				AND per_delivered < 100
	""")
예제 #15
0
파일: migrate.py 프로젝트: ESS-LLP/frappe
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''
	frappe.flags.in_migrate = True
	clear_global_cache()

	#run before_migrate hooks
	for app in frappe.get_installed_apps():
		for fn in frappe.get_hooks('before_migrate', app_name=app):
			frappe.get_attr(fn)()

	# run patches
	frappe.modules.patch_handler.run_all()
	# sync
	frappe.model.sync.sync_all(verbose=verbose)
	frappe.translate.clear_cache()
	sync_fixtures()
	sync_customizations()
	sync_desktop_icons()
	sync_languages()

	frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

	# syncs statics
	render.clear_cache()

	# add static pages to global search
	router.sync_global_search()

	#run after_migrate hooks
	for app in frappe.get_installed_apps():
		for fn in frappe.get_hooks('after_migrate', app_name=app):
			frappe.get_attr(fn)()

	frappe.db.commit()

	clear_notifications()

	frappe.publish_realtime("version-update")
	frappe.flags.in_migrate = False
예제 #16
0
def migrate(verbose=True, rebuild_website=False):
	'''Migrate all apps to the latest version, will:

	- run patches
	- sync doctypes (schema)
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)'''
	frappe.flags.in_migrate = True
	clear_global_cache()

	# run patches
	frappe.modules.patch_handler.run_all()
	# sync
	frappe.model.sync.sync_all(verbose=verbose)
	frappe.translate.clear_cache()
	sync_fixtures()
	sync_customizations()
	sync_desktop_icons()
	sync_languages()

	frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

	# syncs statics
	render.clear_cache()

	# add static pages to global search
	router.sync_global_search()

	frappe.db.commit()

	if not frappe.conf.get('global_help_setup'):
		# sync help if not set as global
		frappe.utils.help.sync()

	clear_notifications()

	frappe.publish_realtime("version-update")
	frappe.flags.in_migrate = False
예제 #17
0
def execute():
    frappe.reload_doc('bloomstack_core',
                      'doctype',
                      'compliance_license_detail',
                      force=True)
    frappe.reload_doc('selling', 'doctype', 'customer', force=True)
    frappe.reload_doc('setup', 'doctype', 'company', force=True)
    frappe.reload_doc('buying', 'doctype', 'supplier', force=True)
    sync_customizations("bloomstack_core")

    customers = frappe.get_all("Customer", filters={"license": ["!=", ""]})
    for customer in customers:
        customer_doc = frappe.get_doc("Customer", customer.name)
        customer_doc.append("licenses", {
            "license": customer_doc.license,
            "is_default": 1
        })
        customer_doc.save()

    suppliers = frappe.get_all("Supplier", filters={"license": ["!=", ""]})
    for supplier in suppliers:
        supplier_doc = frappe.get_doc("Supplier", supplier.name)
        supplier_doc.append("licenses", {
            "license": supplier_doc.license,
            "is_default": 1
        })
        supplier_doc.save()

    companies = frappe.get_all("Company", filters={"license": ["!=", ""]})
    for company in companies:
        company_doc = frappe.get_doc("Company", company.name)
        company_doc.append("licenses", {
            "license": company_doc.license,
            "is_default": 1
        })
        company_doc.save()
예제 #18
0
def migrate(verbose=True, skip_failing=False, skip_search_index=False):
    '''Migrate all apps to the current version, will:
	- run before migrate hooks
	- run patches
	- sync doctypes (schema)
	- sync dashboards
	- sync fixtures
	- sync desktop icons
	- sync web pages (from /www)
	- sync web pages (from /www)
	- run after migrate hooks
	'''

    service_status = check_connection(redis_services=["redis_cache"])
    if False in service_status.values():
        for service in service_status:
            if not service_status.get(service, True):
                print("{} service is not running.".format(service))
        print("""Cannot run bench migrate without the services running.
If you are running bench in development mode, make sure that bench is running:

$ bench start

Otherwise, check the server logs and ensure that all the required services are running."""
              )
        sys.exit(1)

    touched_tables_file = frappe.get_site_path('touched_tables.json')
    if os.path.exists(touched_tables_file):
        os.remove(touched_tables_file)

    try:
        frappe.flags.touched_tables = set()
        frappe.flags.in_migrate = True

        clear_global_cache()

        #run before_migrate hooks
        for app in frappe.get_installed_apps():
            for fn in frappe.get_hooks('before_migrate', app_name=app):
                frappe.get_attr(fn)()

        # run patches
        frappe.modules.patch_handler.run_all(skip_failing)

        # sync
        frappe.model.sync.sync_all(verbose=verbose)
        frappe.translate.clear_cache()
        sync_jobs()
        sync_fixtures()
        sync_dashboards()
        sync_customizations()
        sync_languages()

        frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

        # syncs statics
        render.clear_cache()

        # updating installed applications data
        frappe.get_single('Installed Applications').update_versions()

        #run after_migrate hooks
        for app in frappe.get_installed_apps():
            for fn in frappe.get_hooks('after_migrate', app_name=app):
                frappe.get_attr(fn)()

        # build web_routes index
        if not skip_search_index:
            # Run this last as it updates the current session
            print('Building search index for {}'.format(frappe.local.site))
            build_index_for_all_routes()

        frappe.db.commit()

        clear_notifications()

        frappe.publish_realtime("version-update")
        frappe.flags.in_migrate = False
    finally:
        with open(touched_tables_file, 'w') as f:
            json.dump(list(frappe.flags.touched_tables),
                      f,
                      sort_keys=True,
                      indent=4)
        frappe.flags.touched_tables.clear()
예제 #19
0
def execute():
    sync_customizations("bloomstack_core")

    compliance_info = frappe.get_all('Compliance Info', fields=['name'])
    if not compliance_info:
        return

    sales_orders = frappe.get_all("Sales Order", fields=["customer", "name"])
    sales_invoices = frappe.get_all("Sales Invoice",
                                    fields=["customer", "name"])
    delivery_notes = frappe.get_all("Sales Invoice",
                                    fields=["customer", "name"])
    quotations = frappe.get_all("Quotation",
                                fields=["party_name", "name", "quotation_to"])
    supplier_quotations = frappe.get_all("Supplier Quotation",
                                         fields=["supplier", "name"])
    purchase_orders = frappe.get_all("Purchase Order",
                                     fields=["supplier", "name"])
    purchase_invoices = frappe.get_all("Purchase Invoice",
                                       fields=["supplier", "name"])
    purchase_receipts = frappe.get_all("Purchase Receipt",
                                       fields=["supplier", "name"])

    for doc in sales_orders:
        license = get_default_license("Customer", doc.customer)
        if not license:
            continue
        frappe.db.set_value("Sales Order", doc.name, "license", license)

    for doc in sales_invoices:
        license = get_default_license("Customer", doc.customer)
        if not license:
            continue
        frappe.db.set_value("Sales Invoice", doc.name, "license", license)

    for doc in delivery_notes:
        license = get_default_license("Customer", doc.customer)
        if not license:
            continue
        frappe.db.set_value("Delivery Note", doc.name, "license", license)

    for doc in quotations:
        if doc.quotation_to == "Customer":
            license = get_default_license("Customer", doc.party_name)
            if not license:
                continue
            frappe.db.set_value("Quotation", doc.name, "license", license)

    for doc in supplier_quotations:
        license = get_default_license("Supplier", doc.supplier)
        if not license:
            continue
        frappe.db.set_value("Supplier Quotation", doc.name, "license", license)

    for doc in purchase_orders:
        license = get_default_license("Supplier", doc.supplier)
        if not license:
            continue
        frappe.db.set_value("Purchase Order", doc.name, "license", license)

    for doc in purchase_invoices:
        license = get_default_license("Supplier", doc.supplier)
        if not license:
            continue
        frappe.db.set_value("Purchase Invoice", doc.name, "license", license)

    for doc in purchase_receipts:
        license = get_default_license("Supplier", doc.supplier)
        if not license:
            continue
        frappe.db.set_value("Purchase Receipt", doc.name, "license", license)