test: seed current-dated USD<->INR exchange rate in bootstrap

Tests that create USD documents dated today() (e.g. Sales Order in
test_advance_payment_ledger_entry, USD BOM in test_routing) rely on
get_exchange_rate() finding a USD->INR Currency Exchange record. The
only seeded records are dated 2016, so the lookup misses and falls back
to an external API that is blocked in CI, returning 0. That surfaces as
"Exchange Rate is mandatory" on Sales Order validation and a
ZeroDivisionError in BOM.get_routing (hour_rate / conversion_rate).

Whether it passes depends on which shard incidentally committed the
2016 records first, making it an order-dependent flake that unrelated
PRs trip by shifting test distribution.

Seed today()-dated USD<->INR rates once in BootStrapTestData so the
lookup resolves deterministically without the external API. Rates
mirror the latest Currency Exchange test_records to keep cost
calculations unchanged.
This commit is contained in:
Nabin Hait
2026-07-09 18:26:14 +05:30
parent 8b3caeb578
commit d387155e16

View File

@@ -181,6 +181,7 @@ class BootStrapTestData:
self.make_location()
self.make_price_list()
self.make_item_price()
self.make_currency_exchange()
self.make_loyalty_program()
self.make_shareholder()
self.make_sales_taxes_template()
@@ -2533,6 +2534,38 @@ class BootStrapTestData:
]
self.make_records(["item_code", "price_list", "price_list_rate"], records)
def make_currency_exchange(self):
"""Seed current-dated USD<->INR rates so foreign-currency documents
transacted on ``today()`` resolve an exchange rate deterministically.
Without this, ``get_exchange_rate`` finds no in-window Currency Exchange
record and falls back to an external API that is unreachable in CI,
returning ``0`` and breaking tests that create USD documents. The rates
mirror the latest values in the Currency Exchange ``test_records`` so
cost calculations stay unchanged regardless of which record is picked.
"""
records = [
{
"doctype": "Currency Exchange",
"date": today(),
"from_currency": "USD",
"to_currency": "INR",
"exchange_rate": 62.9,
"for_buying": 1,
"for_selling": 1,
},
{
"doctype": "Currency Exchange",
"date": today(),
"from_currency": "INR",
"to_currency": "USD",
"exchange_rate": 0.0167,
"for_buying": 1,
"for_selling": 1,
},
]
self.make_records(["from_currency", "to_currency", "date"], records)
def make_operation(self):
records = [
{"doctype": "Operation", "name": "_Test Operation 1", "workstation": "_Test Workstation 1"}