Skip to content

Commit

Permalink
set default currency if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
szymi- committed Sep 11, 2020
1 parent 53b7003 commit 8e099b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ralph/data_importer/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion src/ralph/lib/mixins/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8e099b8

Please sign in to comment.