add new management commands for finance and counterparty
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.finance.models import CashTransaction
|
||||
from core.apps.accounts.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('file_path', type=str)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
file_path = options['file_path']
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
for item in data['data']['cashs']:
|
||||
users_data = item['users']
|
||||
users_full_name = []
|
||||
for user_data in users_data:
|
||||
users_full_name.append(user_data['full_name'])
|
||||
users = User.objects.filter(full_name__in=users_full_name)
|
||||
cash_tx, created = CashTransaction.objects.get_or_create(
|
||||
name=item['name']
|
||||
)
|
||||
|
||||
cash_tx.employees.set(users)
|
||||
cash_tx.save()
|
||||
|
||||
self.stdout.write("Cash Transactions added")
|
||||
Reference in New Issue
Block a user