Merge branch 'develop' into gross-profit-product-bundle

This commit is contained in:
Saqib 2021-08-27 15:41:41 +05:30 committed by GitHub
commit 08188f2ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,59 +13,49 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
class TestPeriodClosingVoucher(unittest.TestCase):
def test_closing_entry(self):
year_start_date = get_fiscal_year(today(), company="_Test Company")[1]
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400,
"_Test Cost Center - _TC", posting_date=now(), submit=True)
company = create_company()
cost_center = create_cost_center('Test Cost Center 1')
make_journal_entry("_Test Account Cost for Goods Sold - _TC",
"_Test Bank - _TC", 600, "_Test Cost Center - _TC", posting_date=now(), submit=True)
jv1 = make_journal_entry(
amount=400,
account1="Cash - TPC",
account2="Sales - TPC",
cost_center=cost_center,
posting_date=now(),
save=False
)
jv1.company = company
jv1.save()
jv1.submit()
random_expense_account = frappe.db.sql("""
select t1.account,
sum(t1.debit) - sum(t1.credit) as balance,
sum(t1.debit_in_account_currency) - sum(t1.credit_in_account_currency) \
as balance_in_account_currency
from `tabGL Entry` t1, `tabAccount` t2
where t1.account = t2.name and t2.root_type = 'Expense'
and t2.docstatus < 2 and t2.company = '_Test Company'
and t1.posting_date between %s and %s
group by t1.account
having sum(t1.debit) > sum(t1.credit)
limit 1""", (year_start_date, today()), as_dict=True)
profit_or_loss = frappe.db.sql("""select sum(t1.debit) - sum(t1.credit) as balance
from `tabGL Entry` t1, `tabAccount` t2
where t1.account = t2.name and t2.report_type = 'Profit and Loss'
and t2.docstatus < 2 and t2.company = '_Test Company'
and t1.posting_date between %s and %s""", (year_start_date, today()))
profit_or_loss = flt(profit_or_loss[0][0]) if profit_or_loss else 0
jv2 = make_journal_entry(
amount=600,
account1="Cost of Goods Sold - TPC",
account2="Cash - TPC",
cost_center=cost_center,
posting_date=now(),
save=False
)
jv2.company = company
jv2.save()
jv2.submit()
pcv = self.make_period_closing_voucher()
surplus_account = pcv.closing_account_head
# Check value for closing account
gle_amount_for_closing_account = frappe.db.sql("""select debit - credit
from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s
and account = '_Test Account Reserves and Surplus - _TC'""", pcv.name)
expected_gle = (
('Cost of Goods Sold - TPC', 0.0, 600.0),
(surplus_account, 600.0, 400.0),
('Sales - TPC', 400.0, 0.0)
)
gle_amount_for_closing_account = flt(gle_amount_for_closing_account[0][0]) \
if gle_amount_for_closing_account else 0
pcv_gle = frappe.db.sql("""
select account, debit, credit from `tabGL Entry` where voucher_no=%s order by account
""", (pcv.name))
self.assertEqual(gle_amount_for_closing_account, profit_or_loss)
if random_expense_account:
# Check posted value for teh above random_expense_account
gle_for_random_expense_account = frappe.db.sql("""
select sum(debit - credit) as amount,
sum(debit_in_account_currency - credit_in_account_currency) as amount_in_account_currency
from `tabGL Entry`
where voucher_type='Period Closing Voucher' and voucher_no=%s and account =%s""",
(pcv.name, random_expense_account[0].account), as_dict=True)
self.assertEqual(gle_for_random_expense_account[0].amount, -1*random_expense_account[0].balance)
self.assertEqual(gle_for_random_expense_account[0].amount_in_account_currency,
-1*random_expense_account[0].balance_in_account_currency)
self.assertEqual(pcv_gle, expected_gle)
def test_cost_center_wise_posting(self):
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
@ -93,31 +83,23 @@ class TestPeriodClosingVoucher(unittest.TestCase):
debit_to="Debtors - TPC"
)
pcv = frappe.get_doc({
"transaction_date": today(),
"posting_date": today(),
"fiscal_year": get_fiscal_year(today())[0],
"company": "Test PCV Company",
"cost_center_wise_pnl": 1,
"closing_account_head": surplus_account,
"remarks": "Test",
"doctype": "Period Closing Voucher"
})
pcv.insert()
pcv.submit()
pcv = self.make_period_closing_voucher()
surplus_account = pcv.closing_account_head
expected_gle = (
('Sales - TPC', 200.0, 0.0, cost_center2),
(surplus_account, 0.0, 400.0, cost_center1),
(surplus_account, 0.0, 200.0, cost_center2),
('Sales - TPC', 400.0, 0.0, cost_center1),
(surplus_account, 0.0, 400.0, cost_center1)
('Sales - TPC', 200.0, 0.0, cost_center2),
)
pcv_gle = frappe.db.sql("""
select account, debit, credit, cost_center from `tabGL Entry` where voucher_no=%s
select account, debit, credit, cost_center
from `tabGL Entry` where voucher_no=%s
order by account, cost_center
""", (pcv.name))
self.assertTrue(pcv_gle, expected_gle)
self.assertEqual(pcv_gle, expected_gle)
def test_period_closing_with_finance_book_entries(self):
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
@ -146,39 +128,35 @@ class TestPeriodClosingVoucher(unittest.TestCase):
jv.save()
jv.submit()
pcv = frappe.get_doc({
"transaction_date": today(),
"posting_date": today(),
"fiscal_year": get_fiscal_year(today())[0],
"company": company,
"closing_account_head": surplus_account,
"remarks": "Test",
"doctype": "Period Closing Voucher"
})
pcv.insert()
pcv.submit()
pcv = self.make_period_closing_voucher()
surplus_account = pcv.closing_account_head
expected_gle = (
(surplus_account, 0.0, 400.0, ''),
(surplus_account, 0.0, 400.0, None),
(surplus_account, 0.0, 400.0, jv.finance_book),
('Sales - TPC', 400.0, 0.0, ''),
('Sales - TPC', 400.0, 0.0, None),
('Sales - TPC', 400.0, 0.0, jv.finance_book)
)
pcv_gle = frappe.db.sql("""
select account, debit, credit, finance_book from `tabGL Entry` where voucher_no=%s
select account, debit, credit, finance_book
from `tabGL Entry` where voucher_no=%s
order by account, finance_book
""", (pcv.name))
self.assertTrue(pcv_gle, expected_gle)
self.assertEqual(pcv_gle, expected_gle)
def make_period_closing_voucher(self):
surplus_account = create_account()
cost_center = create_cost_center("Test Cost Center 1")
pcv = frappe.get_doc({
"doctype": "Period Closing Voucher",
"closing_account_head": "_Test Account Reserves and Surplus - _TC",
"company": "_Test Company",
"fiscal_year": get_fiscal_year(today(), company="_Test Company")[0],
"transaction_date": today(),
"posting_date": today(),
"cost_center": "_Test Cost Center - _TC",
"company": "Test PCV Company",
"fiscal_year": get_fiscal_year(today(), company="Test PCV Company")[0],
"cost_center": cost_center,
"closing_account_head": surplus_account,
"remarks": "test"
})
pcv.insert()