diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 1d888e5d8d..33274dd3ac 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -1102,16 +1102,26 @@ def currency_exchange_plugins(): return [('', _('No plugin'))] + [(plug.slug, plug.human_name) for plug in plugs] -def update_exchange_rates(setting): - """Update exchange rates when base currency is changed.""" +def after_change_currency(setting): + """Callback function when base currency is changed. + + - Update exchange rates + - Recalculate prices for all parts + """ if InvenTree.ready.isImportingData(): return if not InvenTree.ready.canAppAccessDatabase(): return + from part import tasks as part_tasks + + # Immediately update exchange rates InvenTree.tasks.update_exchange_rates(force=True) + # Offload update of part prices to a background task + InvenTree.tasks.offload_task(part_tasks.check_missing_pricing, force_async=True) + def reload_plugin_registry(setting): """When a core plugin setting is changed, reload the plugin registry.""" @@ -1212,7 +1222,7 @@ class InvenTreeSetting(BaseInvenTreeSetting): 'description': _('Select base currency for pricing calculations'), 'default': 'USD', 'choices': CURRENCY_CHOICES, - 'after_save': update_exchange_rates, + 'after_save': after_change_currency, }, 'CURRENCY_UPDATE_INTERVAL': { 'name': _('Currency Update Interval'), @@ -2753,7 +2763,7 @@ class NotificationEntry(MetaMixin): class NotificationMessage(models.Model): - """A NotificationMessage is a message sent to a particular user, notifying them of some *important information*. + """A NotificationMessage is a message sent to a particular user, notifying them of some important information. Notification messages can be generated by a variety of sources.