mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-14 02:31:21 +00:00
test: opening purchase invoice with rounding adjustment
(cherry picked from commit b7edc6dea9)
# Conflicts:
# erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
This commit is contained in:
@@ -2347,6 +2347,7 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
|||||||
|
|
||||||
frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)
|
frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def test_last_purchase_rate(self):
|
def test_last_purchase_rate(self):
|
||||||
item = create_item("_Test Item For Last Purchase Rate from PI", is_stock_item=1)
|
item = create_item("_Test Item For Last Purchase Rate from PI", is_stock_item=1)
|
||||||
pi1 = make_purchase_invoice(item_code=item.item_code, qty=10, rate=100)
|
pi1 = make_purchase_invoice(item_code=item.item_code, qty=10, rate=100)
|
||||||
@@ -2364,6 +2365,66 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
|||||||
pi1.cancel()
|
pi1.cancel()
|
||||||
item.reload()
|
item.reload()
|
||||||
self.assertEqual(item.last_purchase_rate, 0)
|
self.assertEqual(item.last_purchase_rate, 0)
|
||||||
|
=======
|
||||||
|
def test_opening_invoice_rounding_adjustment_validation(self):
|
||||||
|
pi = make_purchase_invoice(do_not_save=1)
|
||||||
|
pi.items[0].rate = 99.98
|
||||||
|
pi.items[0].qty = 1
|
||||||
|
pi.items[0].expense_account = "Temporary Opening - _TC"
|
||||||
|
pi.is_opening = "Yes"
|
||||||
|
pi.save()
|
||||||
|
self.assertRaises(frappe.ValidationError, pi.submit)
|
||||||
|
|
||||||
|
def _create_opening_roundoff_account(self, company_name):
|
||||||
|
liability_root = frappe.db.get_all(
|
||||||
|
"Account",
|
||||||
|
filters={"company": company_name, "root_type": "Liability", "disabled": 0},
|
||||||
|
order_by="lft",
|
||||||
|
limit=1,
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
# setup round off account
|
||||||
|
if acc := frappe.db.exists(
|
||||||
|
"Account",
|
||||||
|
{
|
||||||
|
"account_name": "Round Off for Opening",
|
||||||
|
"account_type": "Round Off for Opening",
|
||||||
|
"company": company_name,
|
||||||
|
},
|
||||||
|
):
|
||||||
|
frappe.db.set_value("Company", company_name, "round_off_for_opening", acc)
|
||||||
|
else:
|
||||||
|
acc = frappe.new_doc("Account")
|
||||||
|
acc.company = company_name
|
||||||
|
acc.parent_account = liability_root.name
|
||||||
|
acc.account_name = "Round Off for Opening"
|
||||||
|
acc.account_type = "Round Off for Opening"
|
||||||
|
acc.save()
|
||||||
|
frappe.db.set_value("Company", company_name, "round_off_for_opening", acc.name)
|
||||||
|
|
||||||
|
def test_ledger_entries_of_opening_invoice_with_rounding_adjustment(self):
|
||||||
|
pi = make_purchase_invoice(do_not_save=1)
|
||||||
|
pi.items[0].rate = 99.98
|
||||||
|
pi.items[0].qty = 1
|
||||||
|
pi.items[0].expense_account = "Temporary Opening - _TC"
|
||||||
|
pi.is_opening = "Yes"
|
||||||
|
pi.save()
|
||||||
|
self._create_opening_roundoff_account(pi.company)
|
||||||
|
pi.submit()
|
||||||
|
actual = frappe.db.get_all(
|
||||||
|
"GL Entry",
|
||||||
|
filters={"voucher_no": pi.name, "is_opening": "Yes", "is_cancelled": False},
|
||||||
|
fields=["account", "debit", "credit", "is_opening"],
|
||||||
|
order_by="account,debit",
|
||||||
|
)
|
||||||
|
expected = [
|
||||||
|
{"account": "Creditors - _TC", "debit": 0.0, "credit": 100.0, "is_opening": "Yes"},
|
||||||
|
{"account": "Round Off for Opening - _TC", "debit": 0.02, "credit": 0.0, "is_opening": "Yes"},
|
||||||
|
{"account": "Temporary Opening - _TC", "debit": 99.98, "credit": 0.0, "is_opening": "Yes"},
|
||||||
|
]
|
||||||
|
self.assertEqual(len(actual), 3)
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
>>>>>>> b7edc6dea9 (test: opening purchase invoice with rounding adjustment)
|
||||||
|
|
||||||
|
|
||||||
def set_advance_flag(company, flag, default_account):
|
def set_advance_flag(company, flag, default_account):
|
||||||
|
|||||||
Reference in New Issue
Block a user