Merge branch 'develop' into gross-profit-product-bundle
This commit is contained in:
commit
08188f2ac7
@ -13,59 +13,49 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
|
|||||||
|
|
||||||
class TestPeriodClosingVoucher(unittest.TestCase):
|
class TestPeriodClosingVoucher(unittest.TestCase):
|
||||||
def test_closing_entry(self):
|
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,
|
company = create_company()
|
||||||
"_Test Cost Center - _TC", posting_date=now(), submit=True)
|
cost_center = create_cost_center('Test Cost Center 1')
|
||||||
|
|
||||||
make_journal_entry("_Test Account Cost for Goods Sold - _TC",
|
jv1 = make_journal_entry(
|
||||||
"_Test Bank - _TC", 600, "_Test Cost Center - _TC", posting_date=now(), submit=True)
|
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("""
|
jv2 = make_journal_entry(
|
||||||
select t1.account,
|
amount=600,
|
||||||
sum(t1.debit) - sum(t1.credit) as balance,
|
account1="Cost of Goods Sold - TPC",
|
||||||
sum(t1.debit_in_account_currency) - sum(t1.credit_in_account_currency) \
|
account2="Cash - TPC",
|
||||||
as balance_in_account_currency
|
cost_center=cost_center,
|
||||||
from `tabGL Entry` t1, `tabAccount` t2
|
posting_date=now(),
|
||||||
where t1.account = t2.name and t2.root_type = 'Expense'
|
save=False
|
||||||
and t2.docstatus < 2 and t2.company = '_Test Company'
|
)
|
||||||
and t1.posting_date between %s and %s
|
jv2.company = company
|
||||||
group by t1.account
|
jv2.save()
|
||||||
having sum(t1.debit) > sum(t1.credit)
|
jv2.submit()
|
||||||
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
|
|
||||||
|
|
||||||
pcv = self.make_period_closing_voucher()
|
pcv = self.make_period_closing_voucher()
|
||||||
|
surplus_account = pcv.closing_account_head
|
||||||
|
|
||||||
# Check value for closing account
|
expected_gle = (
|
||||||
gle_amount_for_closing_account = frappe.db.sql("""select debit - credit
|
('Cost of Goods Sold - TPC', 0.0, 600.0),
|
||||||
from `tabGL Entry` where voucher_type='Period Closing Voucher' and voucher_no=%s
|
(surplus_account, 600.0, 400.0),
|
||||||
and account = '_Test Account Reserves and Surplus - _TC'""", pcv.name)
|
('Sales - TPC', 400.0, 0.0)
|
||||||
|
)
|
||||||
|
|
||||||
gle_amount_for_closing_account = flt(gle_amount_for_closing_account[0][0]) \
|
pcv_gle = frappe.db.sql("""
|
||||||
if gle_amount_for_closing_account else 0
|
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)
|
self.assertEqual(pcv_gle, expected_gle)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def test_cost_center_wise_posting(self):
|
def test_cost_center_wise_posting(self):
|
||||||
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
||||||
@ -93,31 +83,23 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
debit_to="Debtors - TPC"
|
debit_to="Debtors - TPC"
|
||||||
)
|
)
|
||||||
|
|
||||||
pcv = frappe.get_doc({
|
pcv = self.make_period_closing_voucher()
|
||||||
"transaction_date": today(),
|
surplus_account = pcv.closing_account_head
|
||||||
"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()
|
|
||||||
|
|
||||||
expected_gle = (
|
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),
|
(surplus_account, 0.0, 200.0, cost_center2),
|
||||||
('Sales - TPC', 400.0, 0.0, cost_center1),
|
('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("""
|
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))
|
""", (pcv.name))
|
||||||
|
|
||||||
self.assertTrue(pcv_gle, expected_gle)
|
self.assertEqual(pcv_gle, expected_gle)
|
||||||
|
|
||||||
def test_period_closing_with_finance_book_entries(self):
|
def test_period_closing_with_finance_book_entries(self):
|
||||||
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
||||||
@ -146,39 +128,35 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
jv.save()
|
jv.save()
|
||||||
jv.submit()
|
jv.submit()
|
||||||
|
|
||||||
pcv = frappe.get_doc({
|
pcv = self.make_period_closing_voucher()
|
||||||
"transaction_date": today(),
|
surplus_account = pcv.closing_account_head
|
||||||
"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()
|
|
||||||
|
|
||||||
expected_gle = (
|
expected_gle = (
|
||||||
(surplus_account, 0.0, 400.0, ''),
|
(surplus_account, 0.0, 400.0, None),
|
||||||
(surplus_account, 0.0, 400.0, jv.finance_book),
|
(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)
|
('Sales - TPC', 400.0, 0.0, jv.finance_book)
|
||||||
)
|
)
|
||||||
|
|
||||||
pcv_gle = frappe.db.sql("""
|
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))
|
""", (pcv.name))
|
||||||
|
|
||||||
self.assertTrue(pcv_gle, expected_gle)
|
self.assertEqual(pcv_gle, expected_gle)
|
||||||
|
|
||||||
def make_period_closing_voucher(self):
|
def make_period_closing_voucher(self):
|
||||||
|
surplus_account = create_account()
|
||||||
|
cost_center = create_cost_center("Test Cost Center 1")
|
||||||
pcv = frappe.get_doc({
|
pcv = frappe.get_doc({
|
||||||
"doctype": "Period Closing Voucher",
|
"doctype": "Period Closing Voucher",
|
||||||
"closing_account_head": "_Test Account Reserves and Surplus - _TC",
|
"transaction_date": today(),
|
||||||
"company": "_Test Company",
|
|
||||||
"fiscal_year": get_fiscal_year(today(), company="_Test Company")[0],
|
|
||||||
"posting_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"
|
"remarks": "test"
|
||||||
})
|
})
|
||||||
pcv.insert()
|
pcv.insert()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user