test: balance sheet
This commit is contained in:
parent
0d3a77dce9
commit
73ecf51a27
@ -3,49 +3,135 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import today
|
from frappe.utils.data import today
|
||||||
|
|
||||||
from erpnext.accounts.report.balance_sheet.balance_sheet import execute
|
from erpnext.accounts.report.balance_sheet.balance_sheet import execute
|
||||||
|
|
||||||
|
COMPANY = "_Test Company 6"
|
||||||
|
COMPANY_SHORT_NAME = "_TC6"
|
||||||
|
|
||||||
|
test_dependencies = ["Company"]
|
||||||
|
|
||||||
|
|
||||||
class TestBalanceSheet(FrappeTestCase):
|
class TestBalanceSheet(FrappeTestCase):
|
||||||
def test_balance_sheet(self):
|
def test_balance_sheet(self):
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
frappe.db.sql(f"delete from `tabJournal Entry` where company='{COMPANY}'")
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import (
|
frappe.db.sql(f"delete from `tabGL Entry` where company='{COMPANY}'")
|
||||||
create_sales_invoice,
|
|
||||||
make_sales_invoice,
|
|
||||||
)
|
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
|
||||||
|
|
||||||
frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company 6'")
|
create_account("VAT Liabilities", f"Duties and Taxes - {COMPANY_SHORT_NAME}", COMPANY)
|
||||||
frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company 6'")
|
create_account("Advance VAT Paid", f"Duties and Taxes - {COMPANY_SHORT_NAME}", COMPANY)
|
||||||
frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 6'")
|
create_account("My Bank", f"Bank Accounts - {COMPANY_SHORT_NAME}", COMPANY)
|
||||||
|
|
||||||
pi = make_purchase_invoice(
|
# 1000 equity paid to bank account
|
||||||
company="_Test Company 6",
|
make_journal_entry(
|
||||||
warehouse="Finished Goods - _TC6",
|
[
|
||||||
expense_account="Cost of Goods Sold - _TC6",
|
dict(
|
||||||
cost_center="Main - _TC6",
|
account_name="My Bank",
|
||||||
qty=10,
|
debit_in_account_currency=1000,
|
||||||
rate=100,
|
credit_in_account_currency=0,
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
account_name="Capital Stock",
|
||||||
|
debit_in_account_currency=0,
|
||||||
|
credit_in_account_currency=1000,
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
si = create_sales_invoice(
|
|
||||||
company="_Test Company 6",
|
# 110 income paid to bank account (100 revenue + 10 VAT)
|
||||||
debit_to="Debtors - _TC6",
|
make_journal_entry(
|
||||||
income_account="Sales - _TC6",
|
[
|
||||||
cost_center="Main - _TC6",
|
dict(
|
||||||
qty=5,
|
account_name="My Bank",
|
||||||
rate=110,
|
debit_in_account_currency=110,
|
||||||
|
credit_in_account_currency=0,
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
account_name="Sales",
|
||||||
|
debit_in_account_currency=0,
|
||||||
|
credit_in_account_currency=100,
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
account_name="VAT Liabilities",
|
||||||
|
debit_in_account_currency=0,
|
||||||
|
credit_in_account_currency=10,
|
||||||
|
),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# offset VAT Liabilities with intra-year advance payment
|
||||||
|
make_journal_entry(
|
||||||
|
[
|
||||||
|
dict(
|
||||||
|
account_name="My Bank",
|
||||||
|
debit_in_account_currency=0,
|
||||||
|
credit_in_account_currency=10,
|
||||||
|
),
|
||||||
|
dict(
|
||||||
|
account_name="Advance VAT Paid",
|
||||||
|
debit_in_account_currency=10,
|
||||||
|
credit_in_account_currency=0,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
filters = frappe._dict(
|
filters = frappe._dict(
|
||||||
company="_Test Company 6",
|
company=COMPANY,
|
||||||
period_start_date=today(),
|
period_start_date=today(),
|
||||||
period_end_date=today(),
|
period_end_date=today(),
|
||||||
periodicity="Yearly",
|
periodicity="Yearly",
|
||||||
)
|
)
|
||||||
result = execute(filters)[1]
|
results = execute(filters)
|
||||||
for account_dict in result:
|
name_and_total = {
|
||||||
if account_dict.get("account") == "Current Liabilities - _TC6":
|
account_dict["account_name"]: account_dict["total"]
|
||||||
self.assertEqual(account_dict.total, 1000)
|
for account_dict in results[1]
|
||||||
if account_dict.get("account") == "Current Assets - _TC6":
|
if "total" in account_dict and "account_name" in account_dict
|
||||||
self.assertEqual(account_dict.total, 550)
|
}
|
||||||
|
|
||||||
|
self.assertNotIn("Sales", name_and_total)
|
||||||
|
|
||||||
|
self.assertIn("My Bank", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["My Bank"], 1100)
|
||||||
|
|
||||||
|
self.assertIn("VAT Liabilities", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["VAT Liabilities"], 10)
|
||||||
|
|
||||||
|
self.assertIn("Advance VAT Paid", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["Advance VAT Paid"], -10)
|
||||||
|
|
||||||
|
self.assertIn("Duties and Taxes", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["Duties and Taxes"], 0)
|
||||||
|
|
||||||
|
self.assertIn("Application of Funds (Assets)", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["Application of Funds (Assets)"], 1100)
|
||||||
|
|
||||||
|
self.assertIn("Equity", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["Equity"], 1000)
|
||||||
|
|
||||||
|
self.assertIn("'Provisional Profit / Loss (Credit)'", name_and_total)
|
||||||
|
self.assertEqual(name_and_total["'Provisional Profit / Loss (Credit)'"], 100)
|
||||||
|
|
||||||
|
|
||||||
|
def make_journal_entry(rows):
|
||||||
|
jv = frappe.new_doc("Journal Entry")
|
||||||
|
jv.posting_date = today()
|
||||||
|
jv.company = COMPANY
|
||||||
|
jv.user_remark = "test"
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
row["account"] = row.pop("account_name") + " - " + COMPANY_SHORT_NAME
|
||||||
|
jv.append("accounts", row)
|
||||||
|
|
||||||
|
jv.insert()
|
||||||
|
jv.submit()
|
||||||
|
|
||||||
|
|
||||||
|
def create_account(account_name: str, parent_account: str, company: str):
|
||||||
|
if frappe.db.exists("Account", {"account_name": account_name, "company": company}):
|
||||||
|
return
|
||||||
|
|
||||||
|
acc = frappe.new_doc("Account")
|
||||||
|
acc.account_name = account_name
|
||||||
|
acc.company = COMPANY
|
||||||
|
acc.parent_account = parent_account
|
||||||
|
acc.insert()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user