feat(pricing): add workspace user rates and price units
This commit is contained in:
1
apps/workspaces/management/commands/__init__.py
Normal file
1
apps/workspaces/management/commands/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
44
apps/workspaces/management/commands/populate_price_units.py
Normal file
44
apps/workspaces/management/commands/populate_price_units.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.workspaces.models import PriceUnit
|
||||
|
||||
|
||||
PRICE_UNITS = [
|
||||
{"code": "USD", "name": "US Dollar", "local_name": "دلار آمریکا", "symbol": "$"},
|
||||
{"code": "EUR", "name": "Euro", "local_name": "یورو", "symbol": "€"},
|
||||
{"code": "GBP", "name": "British Pound", "local_name": "پوند بریتانیا", "symbol": "£"},
|
||||
{"code": "AED", "name": "UAE Dirham", "local_name": "درهم امارات", "symbol": "AED"},
|
||||
{"code": "TRY", "name": "Turkish Lira", "local_name": "لیر ترکیه", "symbol": "₺"},
|
||||
{"code": "IRR", "name": "Iranian Rial", "local_name": "ریال", "symbol": "ریال"},
|
||||
{"code": "IRT", "name": "Iranian Toman", "local_name": "تومان", "symbol": "تومان"},
|
||||
]
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Populate popular price units for workspace billing rates."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
created = 0
|
||||
updated = 0
|
||||
|
||||
for payload in PRICE_UNITS:
|
||||
unit, was_created = PriceUnit.all_objects.update_or_create(
|
||||
code=payload["code"],
|
||||
defaults={
|
||||
"name": payload["name"],
|
||||
"local_name": payload["local_name"],
|
||||
"symbol": payload["symbol"],
|
||||
"is_deleted": False,
|
||||
"deleted_at": None,
|
||||
},
|
||||
)
|
||||
if was_created:
|
||||
created += 1
|
||||
else:
|
||||
updated += 1
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"Price units populated. created={created} updated={updated}"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user