Exemplo n.º 1
0
def get_warehouse_account(warehouse, warehouse_account=None):
	account = warehouse.account
	if not account and warehouse.parent_warehouse:
		if warehouse_account:
			if warehouse_account.get(warehouse.parent_warehouse):
				account = warehouse_account.get(warehouse.parent_warehouse).account
			else:
				from frappe.utils.nestedset import rebuild_tree
				rebuild_tree("Warehouse", "parent_warehouse")
		else:
			account = frappe.db.sql("""
				select
					account from `tabWarehouse`
				where
					lft <= %s and rgt >= %s and company = %s
					and account is not null and ifnull(account, '') !=''
				order by lft desc limit 1""", (warehouse.lft, warehouse.rgt, warehouse.company), as_list=1)

			account = account[0][0] if account else None

	if not account and warehouse.company:
		account = get_company_default_inventory_account(warehouse.company)

	if not account and warehouse.company:
		frappe.throw(_("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}")
			.format(warehouse.name, warehouse.company))
	return account
Exemplo n.º 2
0
 def on_update(self):
     self.update_nsm_model()
     self.check_recursion()
     self.reschedule_dependent_tasks()
     self.update_project()
     self.unassign_todo()
     rebuild_tree("Task", "parent_task")
Exemplo n.º 3
0
def execute():
	from frappe.core.doctype.file.file import make_home_folder

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

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

	# make missing folders and set parent folder
	for file in frappe.get_all("File", filters={"is_folder": 0}):
		file = frappe.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 frappe.get_traceback()
			raise

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

	# reset file size
	for folder in frappe.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 = frappe.get_doc("File", folder[0])
		folder.save()
Exemplo n.º 4
0
	def after_rename(self, old, new, merge=False):
		if not merge:
			frappe.db.set_value("Account", new, "account_name",
				" - ".join(new.split(" - ")[:-1]))
		else:
			from frappe.utils.nestedset import rebuild_tree
			rebuild_tree("Account", "parent_account")
Exemplo n.º 5
0
def sync_generators(generators):
    global all_routes
    l = len(generators)
    if l:
        frappe.flags.in_sync_website = True
        for i, g in enumerate(generators):
            doc = frappe.get_doc(g[0], g[1])
            doc.update_sitemap()
            route = doc.get_route()
            if route in all_routes:
                all_routes.remove(route)
            update_progress_bar("Updating Generators", i, l)
            sys.stdout.flush()

        frappe.flags.in_sync_website = False
        rebuild_tree("Website Route", "parent_website_route")

        # HACK! update public_read, public_write
        for name in frappe.db.sql_list(
                """select name from `tabWebsite Route` where ifnull(parent_website_route, '')!=''
			order by lft"""):
            route = frappe.get_doc("Website Route", name)
            route.make_private_if_parent_is_private()
            route.db_update()

        print ""
Exemplo n.º 6
0
 def after_rename(self, old, new, merge=False):
     if not merge:
         frappe.db.set_value("Account", new, "account_name",
                             " - ".join(new.split(" - ")[:-1]))
     else:
         from frappe.utils.nestedset import rebuild_tree
         rebuild_tree("Account", "parent_account")
Exemplo n.º 7
0
def get_warehouse_account(warehouse, warehouse_account=None):
    account = warehouse.account
    if not account and warehouse.parent_warehouse:
        if warehouse_account:
            if warehouse_account.get(warehouse.parent_warehouse):
                account = warehouse_account.get(
                    warehouse.parent_warehouse).account
            else:
                from frappe.utils.nestedset import rebuild_tree
                rebuild_tree("Warehouse", "parent_warehouse")
        else:
            account = frappe.db.sql(
                """
				select
					account from `tabWarehouse`
				where
					lft <= %s and rgt >= %s and company = %s
					and account is not null and ifnull(account, '') !=''
				order by lft desc limit 1""",
                (warehouse.lft, warehouse.rgt, warehouse.company),
                as_list=1)

            account = account[0][0] if account else None

    if not account and warehouse.company:
        account = get_company_default_inventory_account(warehouse.company)

    if not account and warehouse.company and not warehouse.is_group:
        frappe.throw(
            _("Please set Account in Warehouse {0} or Default Inventory Account in Company {1}"
              ).format(warehouse.name, warehouse.company))
    return account
Exemplo n.º 8
0
def set_parent_to_warehouse_account(company):
	frappe.db.sql(""" update tabAccount set parent_account = %s
		where is_group = 0 and account_type = "Warehouse"
		and (warehouse is not null or warehouse != '') and company = %s
		""",("{0} - {1}".format(_("All Warehouses"), company.abbr), company.name))

	rebuild_tree("Account", "parent_account")
def set_parent_to_warehouse(warehouse_group, company=None):
    frappe.db.sql(
        """ update tabWarehouse set parent_warehouse = %s, is_group = 0
		where (is_group = 0 or is_group is null or is_group = '') and ifnull(company, '') = %s
		""", (warehouse_group, company.name if company else ""))

    rebuild_tree("Warehouse", "parent_warehouse")
Exemplo n.º 10
0
def execute():
    from frappe.core.doctype.file.file import make_home_folder

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

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

    # make missing folders and set parent folder
    for file in frappe.get_all("File", filters={"is_folder": 0}):
        file = frappe.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(frappe.get_traceback())
            raise

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

    # reset file size
    for folder in frappe.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 = frappe.get_doc("File", folder[0])
        folder.save()
Exemplo n.º 11
0
    def set_parent(self):
        rebuild_tree('Quality Procedure', 'parent_quality_procedure')

        for process in self.processes:
            # Set parent for only those children who don't have a parent
            parent_quality_procedure = frappe.db.get_value(
                "Quality Procedure", process.procedure,
                "parent_quality_procedure")
            if not parent_quality_procedure and process.procedure:
                frappe.db.set_value(self.doctype, process.procedure,
                                    "parent_quality_procedure", self.name)
def make_administrative_areas(country_list):
	file_country_mapping = {}
	data_files = os.listdir('../apps/address_data/address_data/address_data/data')
	for filename in data_files:
		with open('../apps/address_data/address_data/address_data/data/' + filename, 'r') as f:
			administrative_areas_data = json.loads(f.read())
			for con in administrative_areas_data.keys():
				file_country_mapping[con] = filename
	
	world_record = {
		"doctype": "Administrative Area",
		"title": "World",
		"administrative_area_type": "world",
		"is_group": 1,
		"parent": "",
		"parent_unique_name": "",
		"self_unique_name": "World"
	}
	make_fixture_record(world_record)

	for country in json.loads(country_list):
		with open("../apps/address_data/address_data/address_data/data/" + file_country_mapping[country]) as f:
			administrative_areas = json.loads(f.read())[country]
		
		country_record = {
			"doctype": "Administrative Area",
			"title": country.title(),
			"administrative_area_type": "country",
			"is_group": 1,
			"parent": "",
			"parent_administrative_area": "World",
			"parent_unique_name": "",
			"self_unique_name": country.title()
		}
		make_fixture_record(country_record)

		for record in administrative_areas:
			record.update({
				"parent_unique_name": "".join(record['parent']),
				"self_unique_name": "".join(record['parent']) + "" + record['title']
			})

		for record in administrative_areas:
			record.update({
				"doctype": "Administrative Area",
				"parent_administrative_area": get_parent_name(country, record, administrative_areas),
				"is_group": 1
			})

			make_fixture_record(record)

		# use rebuild_tree function from nestedset to calculate lft, rgt for all nodes
		rebuild_tree("Administrative Area", "parent_administrative_area")
Exemplo n.º 13
0
def create_charts(company, chart_template=None, existing_company=None, custom_chart=None, from_coa_importer=None):
	chart = custom_chart or get_chart(chart_template, existing_company)
	if chart:
		accounts = []

		def _import_accounts(children, parent, root_type, root_account=False):
			for account_name, child in iteritems(children):
				if root_account:
					root_type = child.get("root_type")

				if account_name not in ["account_name", "account_number", "account_type",
					"root_type", "is_group", "tax_rate"]:

					account_number = cstr(child.get("account_number")).strip()
					account_name, account_name_in_db = add_suffix_if_duplicate(account_name,
						account_number, accounts)

					is_group = identify_is_group(child)
					report_type = "Balance Sheet" if root_type in ["Asset", "Liability", "Equity"] \
						else "Profit and Loss"

					account = frappe.get_doc({
						"doctype": "Account",
						"account_name": child.get('account_name') if from_coa_importer else account_name,
						"company": company,
						"parent_account": parent,
						"is_group": is_group,
						"root_type": root_type,
						"report_type": report_type,
						"account_number": account_number,
						"account_type": child.get("account_type"),
						"account_currency": child.get('account_currency') or frappe.db.get_value('Company',  company,  "default_currency"),
						"tax_rate": child.get("tax_rate")
					})

					if root_account or frappe.local.flags.allow_unverified_charts:
						account.flags.ignore_mandatory = True

					account.flags.ignore_permissions = True

					account.insert()

					accounts.append(account_name_in_db)

					_import_accounts(child, account.name, root_type)

		# Rebuild NestedSet HSM tree for Account Doctype
		# after all accounts are already inserted.
		frappe.local.flags.ignore_update_nsm = True
		_import_accounts(chart, None, None, root_account=True)
		rebuild_tree("Account", "parent_account")
		frappe.local.flags.ignore_update_nsm = False
Exemplo n.º 14
0
def create_charts(company, chart_template=None, existing_company=None):
	chart = get_chart(chart_template, existing_company)
	if chart:
		accounts = []

		def _import_accounts(children, parent, root_type, root_account=False):
			for account_name, child in iteritems(children):
				if root_account:
					root_type = child.get("root_type")

				if account_name not in ["account_number", "account_type",
					"root_type", "is_group", "tax_rate"]:

					account_number = cstr(child.get("account_number")).strip()
					account_name, account_name_in_db = add_suffix_if_duplicate(account_name,
						account_number, accounts)

					is_group = identify_is_group(child)
					report_type = "Balance Sheet" if root_type in ["Asset", "Liability", "Equity"] \
						else "Profit and Loss"

					account = frappe.get_doc({
						"doctype": "Account",
						"account_name": account_name,
						"company": company,
						"parent_account": parent,
						"is_group": is_group,
						"root_type": root_type,
						"report_type": report_type,
						"account_number": account_number,
						"account_type": child.get("account_type"),
						"account_currency": frappe.db.get_value('Company',  company,  "default_currency"),
						"tax_rate": child.get("tax_rate")
					})

					if root_account or frappe.local.flags.allow_unverified_charts:
						account.flags.ignore_mandatory = True

					account.flags.ignore_permissions = True

					account.insert()

					accounts.append(account_name_in_db)

					_import_accounts(child, account.name, root_type)

		# Rebuild NestedSet HSM tree for Account Doctype
		# after all accounts are already inserted.
		frappe.local.flags.ignore_on_update = True
		_import_accounts(chart, None, None, root_account=True)
		rebuild_tree("Account", "parent_account")
		frappe.local.flags.ignore_on_update = False
def build_tree():
	frappe.db.sql("""update `tabSupplier Group` set parent_supplier_group = '{0}'
		where is_group = 0""".format(_('All Supplier Groups')))

	if not frappe.db.exists("Supplier Group", _('All Supplier Groups')):
		frappe.get_doc({
			'doctype': 'Supplier Group',
			'supplier_group_name': _('All Supplier Groups'),
			'is_group': 1,
			'parent_supplier_group': ''
		}).insert(ignore_permissions=True)

	rebuild_tree("Supplier Group", "parent_supplier_group")
Exemplo n.º 16
0
def build_tree():
	frappe.db.sql("""update `tabSupplier Group` set parent_supplier_group = '{0}'
		where is_group = 0""".format(_('All Supplier Groups')))

	if not frappe.db.exists("Supplier Group", _('All Supplier Groups')):
		frappe.get_doc({
			'doctype': 'Supplier Group',
			'supplier_group_name': _('All Supplier Groups'),
			'is_group': 1,
			'parent_supplier_group': ''
		}).insert(ignore_permissions=True)

	rebuild_tree("Supplier Group", "parent_supplier_group")
Exemplo n.º 17
0
def execute():
	""" assign lft and rgt appropriately """
	frappe.reload_doc("hr", "doctype", "department")
	if not frappe.db.exists("Department", _('All Departments')):
		frappe.get_doc({
			'doctype': 'Department',
			'department_name': _('All Departments'),
			'is_group': 1
		}).insert(ignore_permissions=True, ignore_mandatory=True)

	frappe.db.sql("""update `tabDepartment` set parent_department = '{0}'
		where is_group = 0""".format(_('All Departments')))

	rebuild_tree("Department", "parent_department")
Exemplo n.º 18
0
def execute():
    """ assign lft and rgt appropriately """
    frappe.reload_doc("hr", "doctype", "department")
    if not frappe.db.exists("Department", _('All Departments')):
        frappe.get_doc({
            'doctype': 'Department',
            'department_name': _('All Departments'),
            'is_group': 1
        }).insert(ignore_permissions=True, ignore_mandatory=True)

    frappe.db.sql("""update `tabDepartment` set parent_department = '{0}'
		where is_group = 0""".format(_('All Departments')))

    rebuild_tree("Department", "parent_department")
Exemplo n.º 19
0
    def on_update(self):
        NestedSet.on_update(self)
        if not frappe.db.sql(
                """select name from tabAccount
				where company=%s and docstatus<2 limit 1""",
                self.name,
        ):
            if not frappe.local.flags.ignore_chart_of_accounts:
                frappe.flags.country_change = True
                self.create_default_accounts()
                self.create_default_warehouses()

        if not frappe.db.get_value("Cost Center", {
                "is_group": 0,
                "company": self.name
        }):
            self.create_default_cost_center()

        if frappe.flags.country_change:
            install_country_fixtures(self.name, self.country)
            self.create_default_tax_template()

        if not frappe.db.get_value("Department", {"company": self.name}):
            from erpnext.setup.setup_wizard.operations.install_fixtures import install_post_company_fixtures

            install_post_company_fixtures(
                frappe._dict({"company_name": self.name}))

        if not frappe.local.flags.ignore_chart_of_accounts:
            self.set_default_accounts()
            if self.default_cash_account:
                self.set_mode_of_payment_account()

        if self.default_currency:
            frappe.db.set_value("Currency", self.default_currency, "enabled",
                                1)

        if (hasattr(frappe.local, "enable_perpetual_inventory")
                and self.name in frappe.local.enable_perpetual_inventory):
            frappe.local.enable_perpetual_inventory[
                self.name] = self.enable_perpetual_inventory

        if frappe.flags.parent_company_changed:
            from frappe.utils.nestedset import rebuild_tree

            rebuild_tree("Company", "parent_company")

        frappe.clear_cache()
Exemplo n.º 20
0
def rebuild_website_template():
	# TODO
	frappe.flags.in_rebuild_config = True
		
	frappe.db.sql("""delete from `tabWebsite Template`""")
	for app in frappe.get_installed_apps():
		if app=="webnotes": app="frappe"
		build_website_template(app)
		
	cleanup_sitemap()
	
	frappe.flags.in_rebuild_config = False
	
	# enable nested set and rebuild
	rebuild_tree("Website Route", "parent_website_route")
	
	frappe.db.commit()
def change_unit_type():
	frappe.conn.sql("update `tabUnit` set unit_type='Forum', public_write=1, public_read=1")
	# print "converted to forum"
	
	frappe.conn.auto_commit_on_many_writes = 1

	# remove Forum, Discussion
	for unit in frappe.conn.sql("""select name, parent_unit from `tabUnit` 
		where unit_title in ('Forum', 'Discussion') order by lft desc""", as_dict=True):
		# print "removing unit", unit

		frappe.conn.sql("""update `tabPost` set unit=%s where unit=%s""", (unit.parent_unit, unit.name))
		frappe.conn.sql("""delete from `tabUnit` where name=%s""", (unit.name,))
		
	rebuild_tree("Unit", "parent_unit")

	frappe.conn.auto_commit_on_many_writes = 0
def execute():
    frappe.local.lang = frappe.db.get_default("lang") or 'en'

    for doctype in [
            'department', 'leave_period', 'staffing_plan', 'job_opening'
    ]:
        frappe.reload_doc("hr", "doctype", doctype)
    frappe.reload_doc("Payroll", "doctype", 'payroll_entry')

    companies = frappe.db.get_all("Company", fields=["name", "abbr"])
    departments = frappe.db.get_all("Department")
    comp_dict = {}

    # create a blank list for each company
    for company in companies:
        comp_dict[company.name] = {}

    for department in departments:
        # skip root node
        if _(department.name) == _("All Departments"):
            continue

        # for each company, create a copy of the doc
        department_doc = frappe.get_doc("Department", department)
        for company in companies:
            copy_doc = frappe.copy_doc(department_doc)
            copy_doc.update({"company": company.name})
            try:
                copy_doc.insert()
            except frappe.DuplicateEntryError:
                pass
            # append list of new department for each company
            comp_dict[company.name][department.name] = copy_doc.name

    rebuild_tree('Department', 'parent_department')
    doctypes = [
        "Asset", "Employee", "Payroll Entry", "Staffing Plan", "Job Opening"
    ]

    for d in doctypes:
        update_records(d, comp_dict)

    update_instructors(comp_dict)

    frappe.local.lang = 'en'
Exemplo n.º 23
0
def rebuild_website_template():
    # TODO
    frappe.flags.in_rebuild_config = True

    frappe.db.sql("""delete from `tabWebsite Template`""")
    for app in frappe.get_installed_apps():
        if app == "webnotes":
            app = "frappe"
        build_website_template(app)

    cleanup_sitemap()

    frappe.flags.in_rebuild_config = False

    # enable nested set and rebuild
    rebuild_tree("Website Route", "parent_website_route")

    frappe.db.commit()
Exemplo n.º 24
0
def build_tree():
	frappe.db.sql(
		"""update `tabSupplier Group` set parent_supplier_group = '{0}'
		where is_group = 0""".format(
			_("All Supplier Groups")
		)
	)

	if not frappe.db.exists("Supplier Group", _("All Supplier Groups")):
		frappe.get_doc(
			{
				"doctype": "Supplier Group",
				"supplier_group_name": _("All Supplier Groups"),
				"is_group": 1,
				"parent_supplier_group": "",
			}
		).insert(ignore_permissions=True)

	rebuild_tree("Supplier Group", "parent_supplier_group")
def execute():
	if not frappe.db.get_value('Asset', {'docstatus': ('<', 2) }, 'name'): return
	frappe.reload_doc('assets', 'doctype', 'location')
	frappe.reload_doc('stock', 'doctype', 'warehouse')

	for d in frappe.get_all('Warehouse',
		fields = ['warehouse_name', 'is_group', 'parent_warehouse'], order_by="lft asc"):
		try:
			loc = frappe.new_doc('Location')
			loc.location_name = d.warehouse_name
			loc.is_group = d.is_group
			loc.flags.ignore_mandatory = True
			if d.parent_warehouse:
				loc.parent_location = get_parent_warehouse_name(d.parent_warehouse)

			loc.save(ignore_permissions=True)
		except frappe.DuplicateEntryError:
			continue

	rebuild_tree("Location", "parent_location")
Exemplo n.º 26
0
    def test_basic_tree(self, records=None):
        rebuild_tree("Item Group", "parent_item_group")
        min_lft = 1
        max_rgt = frappe.db.sql("select max(rgt) from `tabItem Group`")[0][0]

        if not records:
            records = test_records[2:]

        for item_group in records:
            lft = frappe.db.get_value("Item Group",
                                      item_group["item_group_name"], ["lft"])
            rgt = frappe.db.get_value("Item Group",
                                      item_group["item_group_name"], ["rgt"])
            parent_item_group = frappe.db.get_value(
                "Item Group", item_group["item_group_name"],
                ["parent_item_group"])
            if parent_item_group:
                parent_lft, parent_rgt = frappe.db.get_value(
                    "Item Group", parent_item_group, ["lft", "rgt"])
            else:
                # root
                parent_lft = min_lft - 1
                parent_rgt = max_rgt + 1

            self.assertTrue(lft)
            self.assertTrue(rgt)
            self.assertTrue(lft < rgt)
            self.assertTrue(parent_lft < parent_rgt)
            self.assertTrue(lft > parent_lft)
            self.assertTrue(rgt < parent_rgt)
            self.assertTrue(lft >= min_lft)
            self.assertTrue(rgt <= max_rgt)

            no_of_children = self.get_no_of_children(
                item_group["item_group_name"])
            self.assertTrue(rgt == (lft + 1 + (2 * no_of_children)))

            no_of_children = self.get_no_of_children(parent_item_group)
            self.assertTrue(parent_rgt == (parent_lft + 1 +
                                           (2 * no_of_children)))
def execute():
    frappe.reload_doc('assets', 'doctype', 'location')
    frappe.reload_doc('stock', 'doctype', 'warehouse')

    for d in frappe.get_all(
            'Warehouse',
            fields=['warehouse_name', 'is_group', 'parent_warehouse'],
            order_by="lft asc"):
        try:
            loc = frappe.new_doc('Location')
            loc.location_name = d.warehouse_name
            loc.is_group = d.is_group
            loc.flags.ignore_mandatory = True
            if d.parent_warehouse:
                loc.parent_location = get_parent_warehouse_name(
                    d.parent_warehouse)

            loc.save(ignore_permissions=True)
        except frappe.DuplicateEntryError:
            continue

    rebuild_tree("Location", "parent_location")
Exemplo n.º 28
0
def execute():
    if not frappe.db.get_value("Asset", {"docstatus": ("<", 2)}, "name"):
        return
    frappe.reload_doc("assets", "doctype", "location")
    frappe.reload_doc("stock", "doctype", "warehouse")

    for d in frappe.get_all(
            "Warehouse",
            fields=["warehouse_name", "is_group", "parent_warehouse"],
            order_by="lft asc"):
        try:
            loc = frappe.new_doc("Location")
            loc.location_name = d.warehouse_name
            loc.is_group = d.is_group
            loc.flags.ignore_mandatory = True
            if d.parent_warehouse:
                loc.parent_location = get_parent_warehouse_name(
                    d.parent_warehouse)

            loc.save(ignore_permissions=True)
        except frappe.DuplicateEntryError:
            continue

    rebuild_tree("Location", "parent_location")
Exemplo n.º 29
0
def install_post_company_fixtures(args=None):
    records = [
        # Department
        {
            "doctype": "Department",
            "department_name": _("All Departments"),
            "is_group": 1,
            "parent_department": "",
        },
        {
            "doctype": "Department",
            "department_name": _("Accounts"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Marketing"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Sales"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Purchase"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Operations"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Production"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Dispatch"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Customer Service"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Human Resources"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Management"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Quality Management"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Research & Development"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
        {
            "doctype": "Department",
            "department_name": _("Legal"),
            "parent_department": _("All Departments"),
            "company": args.company_name,
        },
    ]

    # Make root department with NSM updation
    make_records(records[:1])

    frappe.local.flags.ignore_update_nsm = True
    make_records(records[1:])
    frappe.local.flags.ignore_update_nsm = False
    rebuild_tree("Department", "parent_department")
Exemplo n.º 30
0
def execute():
	frappe.reload_doc("setup", "doctype", "company")
	rebuild_tree('Company', 'parent_company')
Exemplo n.º 31
0
def execute():
    """ assign lft and rgt appropriately """
    frappe.reload_doc("hr", "doctype", "employee")

    rebuild_tree("Employee", "reports_to")
Exemplo n.º 32
0
 def test_rebuild_tree(self):
     rebuild_tree("Item Group", "parent_item_group")
     self.test_basic_tree()
Exemplo n.º 33
0
def execute():
    """ assign lft and rgt appropriately """
    frappe.reload_doc("hr", "doctype", "employee")

    rebuild_tree("Employee", "reports_to")
Exemplo n.º 34
0
def install_post_company_fixtures(args=None):
    records = [
        # Department
        {
            'doctype': 'Department',
            'department_name': _('All Departments'),
            'is_group': 1,
            'parent_department': ''
        },
        {
            'doctype': 'Department',
            'department_name': _('Accounts'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Marketing'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Sales'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Purchase'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Operations'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Production'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Dispatch'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Customer Service'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Human Resources'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Management'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Quality Management'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Research & Development'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
        {
            'doctype': 'Department',
            'department_name': _('Legal'),
            'parent_department': _('All Departments'),
            'company': args.company_name
        },
    ]

    # Make root department with NSM updation
    make_records(records[:1])

    frappe.local.flags.ignore_update_nsm = True
    make_records(records[1:])
    frappe.local.flags.ignore_update_nsm = False
    rebuild_tree("Department", "parent_department")
Exemplo n.º 35
0
def execute():
    frappe.reload_doc("setup", "doctype", "company")
    rebuild_tree('Company', 'parent_company')
Exemplo n.º 36
0
def set_parent_to_warehouse(warehouse_group, company=None):
	frappe.db.sql(""" update tabWarehouse set parent_warehouse = %s, is_group = 0
		where (is_group = 0 or is_group is null or is_group = '') and ifnull(company, '') = %s
		""",(warehouse_group, company.name if company else ""))

	rebuild_tree("Warehouse", "parent_warehouse")
Exemplo n.º 37
0
def create_charts(company, abbr):
    chart = {
        _("Application of Funds (Assets)"): {
            _("Current Assets"): {
                _("Accounts Receivable"): {
                    _("Debtors"): {
                        "account_type": "Receivable"
                    }
                },
                _("Bank Accounts"): {
                    "is_group": 1
                },
                _("Cash In Hand"): {
                    _("Cash"): {
                        "account_type": "Cash"
                    }
                },
                _("Stock Assets"): {
                    _("Stock In Hand"): {
                        "account_type": "Stock"
                    }
                }
            },
            "root_type": "Asset"
        },
        _("Expenses"): {
            _("Direct Expenses"): {
                _("Stock Expenses"): {
                    _("Cost of Goods Sold"): {
                        "account_type": "Cost of Goods Sold"
                    }
                },
            },
            "root_type": "Expense"
        },
        _("Income"): {
            _("Direct Income"): {
                _("Sales"): {
                    "account_type": "Income Account"
                }
            },
            _("Indirect Income"): {
                "is_group": 1
            },
            "root_type": "Income"
        },
        _("Source of Funds (Liabilities)"): {
            _("Current Liabilities"): {
                _("Accounts Payable"): {
                    _("Creditors"): {
                        "account_type": "Payable"
                    },
                    _("Payroll Payable"): {},
                },
                _("Stock Liabilities"): {
                    _("Stock Received But Not Billed"): {
                        "account_type": "Stock Received But Not Billed"
                    },
                    _("Asset Received But Not Billed"): {
                        "account_type": "Asset Received But Not Billed"
                    }
                }
            },
            "root_type": "Liability"
        },
        _("Equity"): {
            _("Capital Stock"): {
                "account_type": "Equity"
            },
            "root_type": "Equity"
        }
    }

    def _import_accounts(children, parent, root_type, root_account=False):
        for account_name, child in iteritems(children):
            if root_account:
                root_type = child.get("root_type")

            if account_name not in ["account_type", "root_type", "is_group"]:
                is_group = identify_is_group(child)
                account_name_with_abbr = account_name + " - " + abbr

                account = frappe.get_doc({
                    "doctype":
                    "Account",
                    "account_name":
                    account_name_with_abbr,
                    "account_type":
                    child.get("account_type"),
                    "company":
                    company,
                    "parent_account":
                    parent,
                    "is_group":
                    is_group,
                    "root_type":
                    root_type
                })

                if root_account:
                    account.flags.ignore_mandatory = True

                account.flags.ignore_permissions = True

                account.insert()

                _import_accounts(child, account.name, root_type)

    # Rebuild NestedSet HSM tree for Account Doctype
    # after all accounts are already inserted.
    frappe.local.flags.ignore_on_update = True
    _import_accounts(chart, None, None, root_account=True)
    rebuild_tree("Account", "parent_account")
    frappe.local.flags.ignore_on_update = False
Exemplo n.º 38
0
 def test_rebuild_tree(self):
     rebuild_tree("Item Group", "parent_item_group")
     self.test_basic_tree()
Exemplo n.º 39
0
def get_chart(company, abbr):
    chart = {
        _("Application of Funds (Assests)"): {
            _("Current Assets"): {
                _("Accounts Receivable"): {
                    _("Debtors"): {}
                },
                _("Bank Accounts"): {
                    "is_group": 1
                },
                _("Cash In Hand"): {
                    _("Cash"): {}
                },
                _("Stock Assets"): {
                    _("Stock In Hand"): {}
                }
            },
            "account_type": "Asset"
        },
        _("Expenses"): {
            _("Direct Expenses"): {
                _("Stock Expenses"): {
                    _("Cost of Goods Sold"): {}
                },
            },
            "account_type": "Expense"
        },
        _("Income"): {
            _("Direct Income"): {
                _("Sales"): {}
            },
            _("Indirect Income"): {
                "is_group": 1
            },
            "account_type": "Income"
        },
        _("Source of Funds (Liabilities)"): {
            _("Capital Account"): {},
            _("Current Liabilities"): {
                _("Accounts Payable"): {
                    _("Creditors"): {},
                },
                _("Stock Liabilities"): {
                    _("Stock Received But Not Billed"): {},
                }
            },
            "account_type": "Liability"
        },
    }

    def import_accounts(chart, parent, root_type, root_account=False):
        for name, child in iteritems(chart):
            if (root_account):
                root_type = child.get('account_type')

            if name not in ["account_type", "is_group"]:
                is_group = identify_is_group(child)
                name_with_abbr = name + '-' + abbr
                account = frappe.get_doc({
                    'doctype': 'Account',
                    'parent_account': parent,
                    'company': company,
                    'account_type': root_type,
                    'name': name_with_abbr,
                    'account_name': name_with_abbr,
                    'is_group': is_group
                })
                account.insert()

                import_accounts(child, name_with_abbr, root_type, False)

    import_accounts(chart, None, None, True)
    rebuild_tree("Account", "parent_account")