Skip to content

Commit

Permalink
Update callback when base currency is adjusted (#6243)
Browse files Browse the repository at this point in the history
* Update callback when base currency is adjusted

- Schedule recalculation of part pricing

* Revert old changes
  • Loading branch information
SchrodingersGat committed Jan 15, 2024
1 parent f396642 commit 3511450
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -1212,7 +1222,7 @@ def save(self, *args, **kwargs):
'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'),
Expand Down Expand Up @@ -2753,7 +2763,7 @@ def notify(cls, key: str, uid: int):


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.
Expand Down

0 comments on commit 3511450

Please sign in to comment.