finance: expence and income type import command added
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
from core.apps.finance.models import ExpenceType, TypeIncome
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2JhY2tlbmQuYXBwLnV5cXVyLnV6L21haW4vYXV0aC9sb2dpbiIsImlhdCI6MTc2MTkyMDM2MSwiZXhwIjoxNzYyMDA2NzYxLCJuYmYiOjE3NjE5MjAzNjEsImp0aSI6Inhqak81azJLc2pSaEJJOGUiLCJzdWIiOiIxMDQiLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3In0.ZcREfvT21qpd9eK_-zBumKBtaKKJ-l9QoudSLZ3IpP4"
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_data():
|
||||||
|
url = "https://backend.app.uyqur.uz/main/financial/view"
|
||||||
|
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
data = get_data()
|
||||||
|
income_categories = {
|
||||||
|
"Boshqalar": "OTHERS",
|
||||||
|
"Doimiy daromad": "CONTANT_INCOME"
|
||||||
|
}
|
||||||
|
expence_categories = {
|
||||||
|
"Boshqalar": "OTHERS",
|
||||||
|
"Doimiy xarajatlar": "FIXED_COST",
|
||||||
|
}
|
||||||
|
activities = {
|
||||||
|
"Moliyaviy": "FINANCIAL",
|
||||||
|
"Sarmoya": "CAPITAL"
|
||||||
|
}
|
||||||
|
|
||||||
|
for income in data['data']['income']:
|
||||||
|
TypeIncome.objects.get_or_create(
|
||||||
|
name=income['name'],
|
||||||
|
defaults={
|
||||||
|
"comment": income['description'],
|
||||||
|
"category": income_categories.get(income['financial_category']['name']['uz']),
|
||||||
|
"activity": activities.get(income['activity_type']['name']['uz']),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
for expence in data['data']['expense']:
|
||||||
|
ExpenceType.objects.get_or_create(
|
||||||
|
name=expence['name'],
|
||||||
|
defaults={
|
||||||
|
"comment": expence.get('description') if expence.get('description') else "Comment",
|
||||||
|
"category": expence_categories.get(expence['financial_category']['name']['uz']),
|
||||||
|
"activity": activities.get(expence['activity_type']['name']['uz']),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stdout.write("IncomeType and ExpenceType qo'shildi")
|
||||||
Reference in New Issue
Block a user