test: rounding adjustment validation and posting

This commit is contained in:
ruthra kumar
2024-08-30 17:55:02 +05:30
parent 96e3c2ad10
commit 5021c7ca2c

View File

@@ -3884,6 +3884,56 @@ class TestSalesInvoice(FrappeTestCase):
self.assertEqual(len(res), 1)
self.assertEqual(res[0][0], pos_return.return_against)
def test_validation_on_opening_invoice_with_rounding(self):
si = create_sales_invoice(qty=1, rate=99.98, do_not_submit=True)
si.is_opening = "Yes"
si.items[0].income_account = "Temporary Opening - _TC"
si.save()
self.assertRaises(frappe.ValidationError, si.submit)
def test_opening_invoice_with_rounding_adjustment(self):
si = create_sales_invoice(qty=1, rate=99.98, do_not_submit=True)
si.is_opening = "Yes"
si.items[0].income_account = "Temporary Opening - _TC"
si.save()
liability_root = frappe.db.get_all(
"Account",
filters={"company": si.company, "root_type": "Liability", "disabled": 0},
order_by="lft",
limit=1,
)[0]
# setup round off account
company = frappe.get_doc("Company", si.company)
if acc := frappe.db.exists(
"Account",
{
"account_name": "Round Off for Opening",
"account_type": "Round Off for Opening",
"company": si.company,
},
):
company.round_off_for_opening = acc
else:
acc = frappe.new_doc("Account")
acc.company = si.company
acc.parent_account = liability_root.name
acc.account_name = "Round Off for Opening"
acc.account_type = "Round Off for Opening"
acc.save()
company.round_off_for_opening = acc.name
company.save()
si.reload()
si.submit()
res = frappe.db.get_all(
"GL Entry",
filters={"voucher_no": si.name, "is_opening": "Yes"},
fields=["account", "debit", "credit", "is_opening"],
)
self.assertEqual(len(res), 3)
def set_advance_flag(company, flag, default_account):
frappe.db.set_value(