mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-31 19:02:21 +02:00
fix: test case for zero deferred expense
(cherry picked from commit 7ef4dbcaf6)
This commit is contained in:
@@ -279,3 +279,78 @@ class TestDeferredRevenueAndExpense(FrappeTestCase, AccountsTestMixin):
|
|||||||
{"key": "aug_2021", "total": 0, "actual": 0},
|
{"key": "aug_2021", "total": 0, "actual": 0},
|
||||||
]
|
]
|
||||||
self.assertEqual(report.period_total, expected)
|
self.assertEqual(report.period_total, expected)
|
||||||
|
|
||||||
|
@change_settings("Accounts Settings", {"book_deferred_entries_based_on": "Months"})
|
||||||
|
def test_zero_amount(self):
|
||||||
|
self.create_item("_Test Office Desk", 0, self.warehouse, self.company)
|
||||||
|
item = frappe.get_doc("Item", self.item)
|
||||||
|
item.enable_deferred_expense = 1
|
||||||
|
item.item_defaults[0].deferred_expense_account = self.deferred_expense_account
|
||||||
|
item.no_of_months_exp = 12
|
||||||
|
item.save()
|
||||||
|
|
||||||
|
pi = make_purchase_invoice(
|
||||||
|
item=self.item,
|
||||||
|
company=self.company,
|
||||||
|
supplier=self.supplier,
|
||||||
|
is_return=False,
|
||||||
|
update_stock=False,
|
||||||
|
posting_date=frappe.utils.datetime.date(2023, 12, 30),
|
||||||
|
parent_cost_center=self.cost_center,
|
||||||
|
cost_center=self.cost_center,
|
||||||
|
do_not_save=True,
|
||||||
|
rate=3910,
|
||||||
|
price_list_rate=3910,
|
||||||
|
warehouse=self.warehouse,
|
||||||
|
qty=1,
|
||||||
|
)
|
||||||
|
pi.set_posting_time = True
|
||||||
|
pi.items[0].enable_deferred_expense = 1
|
||||||
|
pi.items[0].service_start_date = "2023-12-30"
|
||||||
|
pi.items[0].service_end_date = "2024-12-30"
|
||||||
|
pi.items[0].deferred_expense_account = self.deferred_expense_account
|
||||||
|
pi.items[0].expense_account = self.expense_account
|
||||||
|
pi.save()
|
||||||
|
pi.submit()
|
||||||
|
|
||||||
|
pda = frappe.get_doc(
|
||||||
|
dict(
|
||||||
|
doctype="Process Deferred Accounting",
|
||||||
|
posting_date=nowdate(),
|
||||||
|
start_date="2024-01-01",
|
||||||
|
end_date="2024-01-31",
|
||||||
|
type="Expense",
|
||||||
|
company=self.company,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pda.insert()
|
||||||
|
pda.submit()
|
||||||
|
|
||||||
|
# execute report
|
||||||
|
fiscal_year = frappe.get_doc("Fiscal Year", get_fiscal_year(date="2024-01-31"))
|
||||||
|
self.filters = frappe._dict(
|
||||||
|
{
|
||||||
|
"company": self.company,
|
||||||
|
"filter_based_on": "Date Range",
|
||||||
|
"period_start_date": "2024-01-01",
|
||||||
|
"period_end_date": "2024-01-31",
|
||||||
|
"from_fiscal_year": fiscal_year.year,
|
||||||
|
"to_fiscal_year": fiscal_year.year,
|
||||||
|
"periodicity": "Monthly",
|
||||||
|
"type": "Expense",
|
||||||
|
"with_upcoming_postings": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
report = Deferred_Revenue_and_Expense_Report(filters=self.filters)
|
||||||
|
report.run()
|
||||||
|
|
||||||
|
# fetch the invoice from deferred invoices list
|
||||||
|
inv = [d for d in report.deferred_invoices if d.name == pi.name]
|
||||||
|
# make sure the list isn't empty
|
||||||
|
self.assertTrue(inv)
|
||||||
|
# calculate the total deferred expense for the period
|
||||||
|
inv = inv[0].calculate_invoice_revenue_expense_for_period()
|
||||||
|
deferred_exp = sum([inv[idx].actual for idx in range(len(report.period_total))])
|
||||||
|
# make sure the total deferred expense is greater than 0
|
||||||
|
self.assertGreater(deferred_exp, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user