refactor(test): simpler create_account helper method

This commit is contained in:
ruthra kumar
2024-05-28 08:44:19 +05:30
parent 7dce6e03c7
commit 475e0ddeee

View File

@@ -55,6 +55,7 @@ class TestAccountsController(FrappeTestCase):
40 series - Company default Cost center is unset 40 series - Company default Cost center is unset
50 series - Journals against Journals 50 series - Journals against Journals
60 series - Journals against Payment Entries 60 series - Journals against Payment Entries
70 series - Advances in Separate party account. Both Party and Advance account are in Foreign currency.
90 series - Dimension inheritence 90 series - Dimension inheritence
""" """
@@ -114,47 +115,64 @@ class TestAccountsController(FrappeTestCase):
self.supplier = make_supplier("_Test MC Supplier USD", "USD") self.supplier = make_supplier("_Test MC Supplier USD", "USD")
def create_account(self): def create_account(self):
account_name = "Debtors USD" accounts = [
if not frappe.db.get_value( frappe._dict(
"Account", filters={"account_name": account_name, "company": self.company} {
): "attribute_name": "debtors_usd",
acc = frappe.new_doc("Account") "name": "Debtors USD",
acc.account_name = account_name "account_type": "Receivable",
acc.parent_account = "Accounts Receivable - " + self.company_abbr "account_currency": "USD",
acc.company = self.company "parent_account": "Accounts Receivable - " + self.company_abbr,
acc.account_currency = "USD" }
acc.account_type = "Receivable" ),
acc.insert() frappe._dict(
else: {
name = frappe.db.get_value( "attribute_name": "creditors_usd",
"Account", "name": "Creditors USD",
filters={"account_name": account_name, "company": self.company}, "account_type": "Payable",
fieldname="name", "account_currency": "USD",
pluck=True, "parent_account": "Accounts Payable - " + self.company_abbr,
) }
acc = frappe.get_doc("Account", name) ),
self.debtors_usd = acc.name # Advance accounts under Asset and Liability header
frappe._dict(
{
"attribute_name": "debtors_advance_usd",
"name": "Advance Received USD",
"account_type": "Receivable",
"account_currency": "USD",
"parent_account": "Current Liabilities - " + self.company_abbr,
}
),
frappe._dict(
{
"attribute_name": "creditors_advance_usd",
"name": "Advance Paid USD",
"account_type": "Payable",
"account_currency": "USD",
"parent_account": "Current Assets - " + self.company_abbr,
}
),
]
account_name = "Creditors USD" for x in accounts:
if not frappe.db.get_value( if not frappe.db.get_value("Account", filters={"account_name": x.name, "company": self.company}):
"Account", filters={"account_name": account_name, "company": self.company} acc = frappe.new_doc("Account")
): acc.account_name = x.name
acc = frappe.new_doc("Account") acc.parent_account = x.parent_account
acc.account_name = account_name acc.company = self.company
acc.parent_account = "Accounts Payable - " + self.company_abbr acc.account_currency = x.account_currency
acc.company = self.company acc.account_type = x.account_type
acc.account_currency = "USD" acc.insert()
acc.account_type = "Payable" else:
acc.insert() name = frappe.db.get_value(
else: "Account",
name = frappe.db.get_value( filters={"account_name": x.name, "company": self.company},
"Account", fieldname="name",
filters={"account_name": account_name, "company": self.company}, pluck=True,
fieldname="name", )
pluck=True, acc = frappe.get_doc("Account", name)
) setattr(self, x.attribute_name, acc.name)
acc = frappe.get_doc("Account", name)
self.creditors_usd = acc.name
def create_sales_invoice( def create_sales_invoice(
self, self,