Coverage for src/backend/InvenTree/plugin/base/integration/CurrencyExchangeMixin.py: 90%

10 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 17:47 +0000

1"""Plugin mixin class for supporting currency exchange data.""" 

2 

3from plugin import PluginMixinEnum 

4from plugin.helpers import MixinNotImplementedError 

5 

6 

7class CurrencyExchangeMixin: 

8 """Mixin class which provides support for currency exchange rates. 

9 

10 Nominally this plugin mixin would be used to interface with an external API, 

11 to periodically retrieve currency exchange rate information. 

12 

13 The plugin class *must* implement the update_exchange_rates method, 

14 which is called periodically by the background worker thread. 

15 """ 

16 

17 class MixinMeta: 

18 """Meta options for this mixin class.""" 

19 

20 MIXIN_NAME = 'CurrentExchange' 

21 

22 def __init__(self): 

23 """Register the mixin.""" 

24 super().__init__() 

25 self.add_mixin(PluginMixinEnum.CURRENCY_EXCHANGE, True, __class__) 

26 

27 def update_exchange_rates(self, base_currency: str, symbols: list[str]) -> dict: 

28 """Update currency exchange rates. 

29 

30 This method *must* be implemented by the plugin class. 

31 

32 Arguments: 

33 base_currency: The base currency to use for exchange rates 

34 symbols: A list of currency symbols to retrieve exchange rates for 

35 

36 Returns: 

37 A dictionary of exchange rates, or None if the update failed 

38 

39 Raises: 

40 Can raise any exception if the update fails 

41 """ 

42 raise MixinNotImplementedError( 

43 'Plugin must implement update_exchange_rates method' 

44 )