Update callback when base currency is adjusted (#6243)

* Update callback when base currency is adjusted

- Schedule recalculation of part pricing

* Revert old changes
This commit is contained in:
Oliver 2024-01-15 17:12:16 +11:00 committed by GitHub
parent f396642d16
commit 3511450b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.