From 8e099b8cec73b51050b0fc48212920a43fb50e2e Mon Sep 17 00:00:00 2001 From: Szymon Jasinski Date: Fri, 11 Sep 2020 10:36:25 +0200 Subject: [PATCH] set default currency if not set --- src/ralph/data_importer/fields.py | 8 +++++++- src/ralph/lib/mixins/models.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ralph/data_importer/fields.py b/src/ralph/data_importer/fields.py index 1e2cc27fbf..cb239638fa 100644 --- a/src/ralph/data_importer/fields.py +++ b/src/ralph/data_importer/fields.py @@ -3,6 +3,8 @@ from djmoney.money import Money from import_export import fields +from ralph.settings import DEFAULT_CURRENCY_CODE + logger = logging.getLogger(__name__) @@ -87,4 +89,8 @@ def save(self, obj, data): class PriceField(fields.Field): def save(self, obj, data): - setattr(obj, 'price', Money(data['price'], data['price_currency'])) + price = Money( + data['price'], + data.get('price_currency', DEFAULT_CURRENCY_CODE) + ) + setattr(obj, 'price', price) diff --git a/src/ralph/lib/mixins/models.py b/src/ralph/lib/mixins/models.py index 7ee6059e03..333e7acfdb 100644 --- a/src/ralph/lib/mixins/models.py +++ b/src/ralph/lib/mixins/models.py @@ -7,6 +7,7 @@ from taggit.managers import TaggableManager as TaggableManagerOriginal from ralph.lib.mixins.fields import TaggitTagField +from ralph.settings import DEFAULT_CURRENCY_CODE class NamedMixin(models.Model): @@ -123,7 +124,7 @@ class Meta: class PriceMixin(models.Model): price = MoneyField( max_digits=15, decimal_places=2, null=True, default=0, - default_currency='XXX' + default_currency=DEFAULT_CURRENCY_CODE ) class Meta: