mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
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:
parent
f396642d16
commit
3511450b3d
@ -1102,16 +1102,26 @@ def currency_exchange_plugins():
|
|||||||
return [('', _('No plugin'))] + [(plug.slug, plug.human_name) for plug in plugs]
|
return [('', _('No plugin'))] + [(plug.slug, plug.human_name) for plug in plugs]
|
||||||
|
|
||||||
|
|
||||||
def update_exchange_rates(setting):
|
def after_change_currency(setting):
|
||||||
"""Update exchange rates when base currency is changed."""
|
"""Callback function when base currency is changed.
|
||||||
|
|
||||||
|
- Update exchange rates
|
||||||
|
- Recalculate prices for all parts
|
||||||
|
"""
|
||||||
if InvenTree.ready.isImportingData():
|
if InvenTree.ready.isImportingData():
|
||||||
return
|
return
|
||||||
|
|
||||||
if not InvenTree.ready.canAppAccessDatabase():
|
if not InvenTree.ready.canAppAccessDatabase():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
from part import tasks as part_tasks
|
||||||
|
|
||||||
|
# Immediately update exchange rates
|
||||||
InvenTree.tasks.update_exchange_rates(force=True)
|
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):
|
def reload_plugin_registry(setting):
|
||||||
"""When a core plugin setting is changed, reload the plugin registry."""
|
"""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'),
|
'description': _('Select base currency for pricing calculations'),
|
||||||
'default': 'USD',
|
'default': 'USD',
|
||||||
'choices': CURRENCY_CHOICES,
|
'choices': CURRENCY_CHOICES,
|
||||||
'after_save': update_exchange_rates,
|
'after_save': after_change_currency,
|
||||||
},
|
},
|
||||||
'CURRENCY_UPDATE_INTERVAL': {
|
'CURRENCY_UPDATE_INTERVAL': {
|
||||||
'name': _('Currency Update Interval'),
|
'name': _('Currency Update Interval'),
|
||||||
@ -2753,7 +2763,7 @@ class NotificationEntry(MetaMixin):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationMessage(models.Model):
|
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.
|
Notification messages can be generated by a variety of sources.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user