コード例 #1
0
    def test_account_rename_sync(self):
        frappe.local.flags.pop("ignore_root_company_validation", None)

        acc = frappe.new_doc("Account")
        acc.account_name = "Test Rename Account"
        acc.parent_account = "Temporary Accounts - _TC3"
        acc.company = "_Test Company 3"
        acc.insert()

        # Rename account in parent company
        update_account_number(acc.name, "Test Rename Sync Account", "1234")

        # Check if renamed in children
        self.assertTrue(
            frappe.db.exists(
                "Account", {
                    'account_name': "Test Rename Sync Account",
                    "company": "_Test Company 4",
                    "account_number": "1234"
                }))
        self.assertTrue(
            frappe.db.exists(
                "Account", {
                    'account_name': "Test Rename Sync Account",
                    "company": "_Test Company 5",
                    "account_number": "1234"
                }))

        frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC3")
        frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC4")
        frappe.delete_doc("Account", "1234 - Test Rename Sync Account - _TC5")
コード例 #2
0
ファイル: test_account.py プロジェクト: havid0707/erpnext
	def test_rename_account(self):
		if not frappe.db.exists("Account", "1210 - Debtors - _TC"):
			acc = frappe.new_doc("Account")
			acc.account_name = "Debtors"
			acc.parent_account = "Accounts Receivable - _TC"
			acc.account_number = "1210"
			acc.company = "_Test Company"
			acc.insert()

		account_number, account_name = frappe.db.get_value("Account", "1210 - Debtors - _TC",
			["account_number", "account_name"])
		self.assertEqual(account_number, "1210")
		self.assertEqual(account_name, "Debtors")

		new_account_number = "1211-11-4 - 6 - "
		new_account_name = "Debtors 1 - Test - "

		update_account_number("1210 - Debtors - _TC", new_account_number, new_account_name)

		new_acc = frappe.db.get_value("Account", "1211-11-4 - 6 - - Debtors 1 - Test - - _TC",
			["account_name", "account_number"], as_dict=1)

		self.assertEqual(new_acc.account_name, "Debtors 1 - Test -")
		self.assertEqual(new_acc.account_number, "1211-11-4 - 6 -")

		frappe.delete_doc("Account", "1211-11-4 - 6 - Debtors 1 - Test - - _TC")
コード例 #3
0
    def test_rename_account(self):
        if not frappe.db.exists("Account", "1210 - Debtors - _TC"):
            acc = frappe.new_doc("Account")
            acc.account_name = "Debtors"
            acc.parent_account = "Accounts Receivable - _TC"
            acc.account_number = "1210"
            acc.company = "_Test Company"
            acc.insert()

        account_number, account_name = frappe.db.get_value(
            "Account", "1210 - Debtors - _TC",
            ["account_number", "account_name"])
        self.assertEqual(account_number, "1210")
        self.assertEqual(account_name, "Debtors")

        new_account_number = "1211-11-4 - 6 - "
        new_account_name = "Debtors 1 - Test - "

        update_account_number("1210 - Debtors - _TC", new_account_name,
                              new_account_number)

        new_acc = frappe.db.get_value(
            "Account",
            "1211-11-4 - 6 - - Debtors 1 - Test - - _TC",
            ["account_name", "account_number"],
            as_dict=1)

        self.assertEqual(new_acc.account_name, "Debtors 1 - Test -")
        self.assertEqual(new_acc.account_number, "1211-11-4 - 6 -")

        frappe.delete_doc("Account",
                          "1211-11-4 - 6 - Debtors 1 - Test - - _TC")
コード例 #4
0
def execute():
    frappe.reload_doc("setup", "doctype", "company")

    companies = frappe.get_all("Company")
    goods_in_transit = {}
    for name in companies:
        doc = frappe.new_doc("Account")
        doc.company = name.name
        doc.account_name = "Goods in Transit"
        doc.parent_account = get_account_autoname(None, "Current Assets", name)
        doc.root_type = "Asset"
        doc.is_group = 1
        doc.save()
        goods_in_transit[name.name] = doc.name

    accounts = frappe.get_all("Account",
                              {"account_name": "Letter of Credit Payable"})
    for name in accounts:
        doc = frappe.get_doc("Account", name)
        doc.parent_account = goods_in_transit[doc.company]
        doc.save()
        update_account_number(name.name, "Letters of Credit")

    for name in companies:
        doc = frappe.get_doc("Company", name)
        doc.set_default_accounts()
        doc.save()
コード例 #5
0
ファイル: test_account.py プロジェクト: ankush/erpnext
	def test_child_company_account_rename_sync(self):
		frappe.local.flags.pop("ignore_root_company_validation", None)

		acc = frappe.new_doc("Account")
		acc.account_name = "Test Group Account"
		acc.parent_account = "Temporary Accounts - _TC3"
		acc.is_group = 1
		acc.company = "_Test Company 3"
		acc.insert()

		self.assertTrue(
			frappe.db.exists(
				"Account", {"account_name": "Test Group Account", "company": "_Test Company 4"}
			)
		)
		self.assertTrue(
			frappe.db.exists(
				"Account", {"account_name": "Test Group Account", "company": "_Test Company 5"}
			)
		)

		# Try renaming child company account
		acc_tc_5 = frappe.db.get_value(
			"Account", {"account_name": "Test Group Account", "company": "_Test Company 5"}
		)
		self.assertRaises(
			frappe.ValidationError, update_account_number, acc_tc_5, "Test Modified Account"
		)

		# Rename child company account with allow_account_creation_against_child_company enabled
		frappe.db.set_value(
			"Company", "_Test Company 5", "allow_account_creation_against_child_company", 1
		)

		update_account_number(acc_tc_5, "Test Modified Account")
		self.assertTrue(
			frappe.db.exists(
				"Account", {"name": "Test Modified Account - _TC5", "company": "_Test Company 5"}
			)
		)

		frappe.db.set_value(
			"Company", "_Test Company 5", "allow_account_creation_against_child_company", 0
		)

		to_delete = [
			"Test Group Account - _TC3",
			"Test Group Account - _TC4",
			"Test Modified Account - _TC5",
		]
		for doc in to_delete:
			frappe.delete_doc("Account", doc)
コード例 #6
0
def create_account(account_name,
                   parent_number,
                   account_number,
                   is_group,
                   account_currency,
                   account_type,
                   root_type=None,
                   company_name=None):
    print('Create account start')
    if company_name is None:
        company_name = frappe.get_doc("Global Defaults").default_company

    if frappe.db.exists('Account', {'account_number': account_number}):
        update_account_number(
            frappe.db.get_list('Account',
                               filters={'account_number':
                                        account_number})[0].name, account_name,
            account_number)
        print('account ' + account_number + ' name updated')
        this_account = frappe.get_doc('Account',
                                      {'account_number': account_number})
        print('this_account group = ' + str(this_account.is_group))
        if int(is_group) == 1 and int(this_account.is_group) != int(is_group):
            print("This non-group account need to changed to group")
            this_account.account_type = ''
            this_account.is_group = 1
            this_account.save()
            print("Account changed to group")
    else:
        new_account = frappe.new_doc("Account")
        new_account.account_name = account_name
        new_account.company = company_name
        if parent_number == '':
            new_account.flags.ignore_mandatory = True
            new_account.parent_account = None
        else:
            new_account.parent_account = frappe.db.get_list(
                'Account', filters={'account_number': parent_number})[0].name
        new_account.account_number = account_number
        new_account.is_group = is_group
        new_account.account_currency = account_currency
        new_account.account_type = account_type
        if root_type is not None:
            new_account.root_type = root_type
        new_account.insert()
        print('new account inserted')
    print('Create account end')
    print('===================')
    print('===================')
コード例 #7
0
def rename_account(company, old_name, new_account_name, new_account_number):
    update_account_number(old_name, new_account_name, new_account_number)
    disable_submitted(company)
コード例 #8
0
def generate_account_number(doctype, parent, company, is_root=False):
    from erpnext.accounts.report.financial_statements import sort_root_accounts

    fieldname = frappe.db.escape(doctype.lower().replace(' ', '_'))
    doctype = frappe.db.escape(doctype)

    # root
    if is_root:
        fields = ", root_type, report_type, account_currency" if doctype == "Account" else ""
        acc = frappe.db.sql(""" select
			name as value, is_group as expandable {fields}
			from `tab{doctype}`
			where ifnull(`parent_{fieldname}`,'') = ''
			and `company` = %s	and docstatus<2
			order by name""".format(fields=fields, fieldname=fieldname,
                           doctype=doctype),
                            company,
                            as_dict=1)

        if parent == "Accounts":
            sort_root_accounts(acc)
    else:
        # other
        fields = ", account_currency" if doctype == "Account" else ""
        acc = frappe.db.sql("""select
			name as value, is_group as expandable, parent_{fieldname} as parent {fields}
			from `tab{doctype}`
			where ifnull(`parent_{fieldname}`,'') = %s
			and docstatus<2
			order by name""".format(fields=fields, fieldname=fieldname,
                           doctype=doctype),
                            parent,
                            as_dict=1)

#auto account number
    root_seed = 0
    child_seed = 0
    leaf_seed = 0
    last_acct_num = 0

    for each in acc:
        parent_account = frappe.db.get_value("Account", each.get("value"),
                                             "parent_account")
        parent_acct_num = frappe.db.get_value("Account", parent_account,
                                              "account_number")
        account_number = frappe.db.get_value("Account", each.get("value"),
                                             "account_number")
        #account_number = frappe.db.get_value("Account", each.get("value"), "account_number")

        #root
        if ((parent_account == None) and (each.get("expandable") == 1)):
            if (account_number == None or account_number == ''):
                account_name = frappe.db.get_value("Account",
                                                   each.get("value"),
                                                   "account_name")
                if (account_name == 'Application of Funds (Assets)'):
                    root_seed = 1
                elif (account_name == 'Source of Funds (Liabilities)'):
                    root_seed = 2
                elif (account_name == 'Equity'):
                    root_seed = 3
                elif (account_name == 'Income'):
                    root_seed = 4
                elif (account_name == 'Expenses'):
                    root_seed = 5

                #frappe.db.set_value('Account',each.get("value"),'account_number',root_seed)
                update_account_number(each.get("value"), root_seed)
        #child
        if ((parent_account != None) and (each.get("expandable") == 1)):
            last_acct_num = frappe.get_all('Account',
                                           fields=['account_number'],
                                           filters={
                                               'parent_account':
                                               parent_account,
                                               'is_group': 1
                                           },
                                           order_by='account_number desc',
                                           limit=1)[0]['account_number']

            if (account_number == None or account_number == ''):
                if (last_acct_num != None and last_acct_num != ''):
                    child_seed = (int(last_acct_num) % 10) + 1

                else:
                    child_seed = 1
                new_account_number = str(parent_acct_num) + str(child_seed)

                account_with_same_number = frappe.db.get_value(
                    "Account", {
                        "account_number": new_account_number,
                        "company": company,
                        "name": ["!=", each.get("value")]
                    })
                if account_with_same_number:
                    child_seed = child_seed + 1
                    new_account_number = str(parent_acct_num) + str(child_seed)

                #frappe.db.set_value('Account',each.get("value"),'account_number',new_account_number)
                update_account_number(each.get("value"), new_account_number)

        #leaf
        if ((parent_account != None) and (each.get("expandable") == 0)):
            last_acct_num = frappe.get_all('Account',
                                           fields=['account_number'],
                                           filters={
                                               'parent_account':
                                               parent_account,
                                               'is_group': 0
                                           },
                                           order_by='account_number desc',
                                           limit=1)[0]['account_number']
            leaf_node_count = frappe.db.count('Account',
                                              filters={
                                                  'parent_account':
                                                  parent_account,
                                                  'is_group': 0
                                              })
            if (account_number == None or account_number == ''):
                if (last_acct_num != None and last_acct_num != ''):
                    if (leaf_node_count > 9):
                        str_num = str(last_acct_num)
                        if (str_num.endswith('0',
                                             len(str_num) - 2,
                                             len(str_num) - 1)):
                            leaf_seed = (int(last_acct_num) % 10) + 1
                            new_account_number = str(parent_acct_num) + str(
                                "{0:0>2}".format(leaf_seed))
                        else:
                            leaf_seed = (int(last_acct_num) % 100) + 1
                            new_account_number = str(parent_acct_num) + str(
                                leaf_seed)
                    else:
                        leaf_seed = (int(last_acct_num) % 10) + 1
                        new_account_number = str(parent_acct_num) + str(
                            "{0:0>2}".format(leaf_seed))
                else:
                    leaf_seed = 1
                    new_account_number = str(parent_acct_num) + str(
                        "{0:0>2}".format(leaf_seed))

                account_with_same_number = frappe.db.get_value(
                    "Account", {
                        "account_number": new_account_number,
                        "company": company,
                        "name": ["!=", each.get("value")]
                    })
                if account_with_same_number:
                    leaf_seed = leaf_seed + 1
                    new_account_number = str(parent_acct_num) + str(
                        "{0:0>2}".format(leaf_seed))

                #frappe.db.set_value('Account',each.get("value"),'account_number',new_account_number)
                update_account_number(each.get("value"), new_account_number)

    #auto account number
    return acc