Commit 0e7127e
feat(mcp): wire Factory.base_currency_code through variant details card (#753)
Closes #751.
Variant prices (``sales_price`` / ``purchase_price``) don't carry a
per-record currency on the wire — they're denominated in
``Factory.base_currency_code``. Pre-this-change the variant detail
card's ``_price_display`` fell back to USD, which was wrong for non-USD
tenants (EUR-base tenants saw ``$12.99`` instead of ``€12.99``; JPY-base
saw ``$1500.00`` instead of ``¥1,500``).
Wire path:
- New ``resolve_factory_base_currency(catalog) -> str | None`` helper
in ``tool_result_utils`` reads the cached ``CachedFactory`` singleton
(id=1, synthesized by the sync pipeline since ``GET /factory`` has no
``id`` on the wire). Best-effort: swallows cache exceptions / returns
``None`` on cold cache so card rendering stays robust.
- ``VariantDetailsResponse`` gains a ``base_currency_code: str | None``
field (response-dict wire path — same style as the existing
``currency`` field on ``SalesOrderResponse`` / ``PurchaseOrderResponse``,
no new kwarg threading through the builder signature).
- ``_get_variant_details_impl`` resolves the base currency once per batch
via ``asyncio.gather`` alongside parent/supplier enrichment, then
stamps it onto every ``VariantDetailsResponse``. Adds ``CachedFactory``
to the ``@cache_read`` decoration so the sync runs before the lookup.
- ``build_variant_details_ui`` reads ``variant["base_currency_code"]``
and passes it to ``_format_money``. Missing field falls back to USD
(cold cache / pre-#751 fixtures).
Deferred per the issue's "consider" criteria:
- Surfacing ``*_in_base_currency`` Metric alongside transaction-currency
Total: skipped. SO/PO cards are already information-dense, and the
issue suggests these add value only with ``conversion_rate`` +
``conversion_date`` captions for audit-trail provenance — a richer
redesign deserves its own card iteration.
- ``_format_cost`` (bare-decimal per-row DataTable cell): kept as-is.
Adding Babel-aware formatting per row would clutter dense tables with
repeated symbols (``$437.50``, ``$5.10``, ``$92.00`` x N rows) and
duplicate information the column header already carries. Decision
recorded in the docstring; revisit only if multi-currency mixing
within a single table causes confusion.
Tests: 10 new cases across ``test_prefab_ui.py`` (EUR / JPY / fallback),
``test_tool_result_utils.py`` (5 cases — hit, dict-shape, miss, exception,
empty-string), and ``test_inventory.py`` (impl-level plumbing
verification + cold-cache tolerance).
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b5f149d commit 0e7127e
6 files changed
Lines changed: 333 additions & 12 deletions
File tree
- katana_mcp_server
- src/katana_mcp/tools
- foundation
- tests
- tools
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
1647 | 1649 | | |
1648 | 1650 | | |
1649 | 1651 | | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
1650 | 1664 | | |
1651 | 1665 | | |
1652 | 1666 | | |
| |||
1742 | 1756 | | |
1743 | 1757 | | |
1744 | 1758 | | |
| 1759 | + | |
1745 | 1760 | | |
1746 | 1761 | | |
1747 | 1762 | | |
| |||
1751 | 1766 | | |
1752 | 1767 | | |
1753 | 1768 | | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
1754 | 1775 | | |
1755 | 1776 | | |
1756 | 1777 | | |
| |||
1821 | 1842 | | |
1822 | 1843 | | |
1823 | 1844 | | |
| 1845 | + | |
1824 | 1846 | | |
1825 | 1847 | | |
1826 | 1848 | | |
| |||
2006 | 2028 | | |
2007 | 2029 | | |
2008 | 2030 | | |
| 2031 | + | |
2009 | 2032 | | |
2010 | 2033 | | |
2011 | 2034 | | |
| |||
2050 | 2073 | | |
2051 | 2074 | | |
2052 | 2075 | | |
2053 | | - | |
2054 | | - | |
2055 | | - | |
2056 | | - | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
2057 | 2085 | | |
2058 | 2086 | | |
2059 | 2087 | | |
| |||
2068 | 2096 | | |
2069 | 2097 | | |
2070 | 2098 | | |
2071 | | - | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
2072 | 2107 | | |
2073 | 2108 | | |
2074 | 2109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
824 | 824 | | |
825 | 825 | | |
826 | 826 | | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
827 | 835 | | |
828 | 836 | | |
| 837 | + | |
829 | 838 | | |
830 | 839 | | |
831 | 840 | | |
832 | 841 | | |
833 | 842 | | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
| 843 | + | |
840 | 844 | | |
841 | 845 | | |
842 | 846 | | |
| |||
1339 | 1343 | | |
1340 | 1344 | | |
1341 | 1345 | | |
1342 | | - | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1343 | 1361 | | |
1344 | 1362 | | |
1345 | 1363 | | |
| |||
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
52 | 95 | | |
53 | 96 | | |
54 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
290 | 350 | | |
291 | 351 | | |
292 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
1038 | 1120 | | |
1039 | 1121 | | |
1040 | 1122 | | |
| |||
0 commit comments