fix(test): replace hardcoded reference to adv with dynamic one

This commit is contained in:
ruthra kumar 2023-08-05 14:11:57 +05:30
parent b65ee6c2db
commit 466734fb4b

View File

@ -347,18 +347,23 @@ class TestAccountsController(FrappeTestCase):
for exc_rate in [75.9, 83.1, 80.01]: for exc_rate in [75.9, 83.1, 80.01]:
with self.subTest(exc_rate=exc_rate): with self.subTest(exc_rate=exc_rate):
si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True) si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append( si.append(
"advances", "advances",
{ {
"doctype": "Sales Invoice Advance", "doctype": "Sales Invoice Advance",
"reference_type": adv.doctype, "reference_type": advances[0].reference_type,
"reference_name": adv.name, "reference_name": advances[0].reference_name,
"reference_row": advances[0].reference_row,
"advance_amount": 1, "advance_amount": 1,
"allocated_amount": 1, "allocated_amount": 1,
"ref_exchange_rate": 85, "ref_exchange_rate": advances[0].exchange_rate,
"remarks": "Test", "remarks": advances[0].remarks,
}, },
) )
si = si.save() si = si.save()
si = si.submit() si = si.submit()
@ -398,16 +403,19 @@ class TestAccountsController(FrappeTestCase):
si = self.create_sales_invoice( si = self.create_sales_invoice(
qty=2, conversion_rate=80, rate=rate_in_account_currency, do_not_submit=True qty=2, conversion_rate=80, rate=rate_in_account_currency, do_not_submit=True
) )
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append( si.append(
"advances", "advances",
{ {
"doctype": "Sales Invoice Advance", "doctype": "Sales Invoice Advance",
"reference_type": adv.doctype, "reference_type": advances[0].reference_type,
"reference_name": adv.name, "reference_name": advances[0].reference_name,
"advance_amount": 1, "advance_amount": 1,
"allocated_amount": 1, "allocated_amount": 1,
"ref_exchange_rate": 85, "ref_exchange_rate": advances[0].exchange_rate,
"remarks": "Test", "remarks": advances[0].remarks,
}, },
) )
si = si.save() si = si.save()
@ -470,16 +478,19 @@ class TestAccountsController(FrappeTestCase):
# invoice with advance(partial amount) # invoice with advance(partial amount)
si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1, do_not_submit=True) si = self.create_sales_invoice(qty=2, conversion_rate=80, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append( si.append(
"advances", "advances",
{ {
"doctype": "Sales Invoice Advance", "doctype": "Sales Invoice Advance",
"reference_type": adv.doctype, "reference_type": advances[0].reference_type,
"reference_name": adv.name, "reference_name": advances[0].reference_name,
"advance_amount": 1, "advance_amount": 1,
"allocated_amount": 1, "allocated_amount": 1,
"ref_exchange_rate": 85, "ref_exchange_rate": advances[0].exchange_rate,
"remarks": "Test", "remarks": advances[0].remarks,
}, },
) )
si = si.save() si = si.save()
@ -678,22 +689,26 @@ class TestAccountsController(FrappeTestCase):
adv.reload() adv.reload()
# Sales Invoices in different exchange rates # Sales Invoices in different exchange rates
for exc_rate in [75.9, 83.1, 80.01]: for exc_rate in [75.9, 83.1]:
with self.subTest(exc_rate=exc_rate): with self.subTest(exc_rate=exc_rate):
si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True) si = self.create_sales_invoice(qty=1, conversion_rate=exc_rate, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append( si.append(
"advances", "advances",
{ {
"doctype": "Sales Invoice Advance", "doctype": "Sales Invoice Advance",
"reference_type": adv.doctype, "reference_type": advances[0].reference_type,
"reference_name": adv.name, "reference_name": advances[0].reference_name,
"reference_row": adv.accounts[0].name, "reference_row": advances[0].reference_row,
"advance_amount": 1, "advance_amount": 1,
"allocated_amount": 1, "allocated_amount": 1,
"ref_exchange_rate": adv_exc_rate, "ref_exchange_rate": advances[0].exchange_rate,
"remarks": "Test", "remarks": advances[0].remarks,
}, },
) )
si = si.save() si = si.save()
si = si.submit() si = si.submit()
@ -741,19 +756,23 @@ class TestAccountsController(FrappeTestCase):
# invoice with advance(partial amount) # invoice with advance(partial amount)
si = self.create_sales_invoice(qty=3, conversion_rate=80, rate=1, do_not_submit=True) si = self.create_sales_invoice(qty=3, conversion_rate=80, rate=1, do_not_submit=True)
advances = si.get_advance_entries()
self.assertEqual(len(advances), 1)
self.assertEqual(advances[0].reference_name, adv.name)
si.append( si.append(
"advances", "advances",
{ {
"doctype": "Sales Invoice Advance", "doctype": "Sales Invoice Advance",
"reference_type": adv.doctype, "reference_type": advances[0].reference_type,
"reference_name": adv.name, "reference_name": advances[0].reference_name,
"reference_row": adv.accounts[0].name, "reference_row": advances[0].reference_row,
"advance_amount": 1, "advance_amount": 1,
"allocated_amount": 1, "allocated_amount": 1,
"ref_exchange_rate": adv_exc_rate, "ref_exchange_rate": advances[0].exchange_rate,
"remarks": "Test", "remarks": advances[0].remarks,
}, },
) )
si = si.save() si = si.save()
si = si.submit() si = si.submit()