From 591bdf9234f17dce983f9640db657347b351ac7d Mon Sep 17 00:00:00 2001 From: ismail Date: Mon, 2 Jun 2025 14:16:45 +0300 Subject: [PATCH 1/3] update the lead and opportunity detail page + more fixes --- inventory/management/commands/claude.py | 433 ++++++++++++++++++ inventory/management/commands/deepseek.py | 124 +++++ inventory/management/commands/gemini.py | 127 +++++ inventory/management/commands/gpt.py | 123 +++++ inventory/management/commands/qwen.py | 76 +++ inventory/models.py | 4 + templates/crm/leads/lead_detail.html | 35 +- .../crm/opportunities/opportunity_detail.html | 18 +- 8 files changed, 916 insertions(+), 24 deletions(-) create mode 100644 inventory/management/commands/claude.py create mode 100644 inventory/management/commands/deepseek.py create mode 100644 inventory/management/commands/gemini.py create mode 100644 inventory/management/commands/gpt.py create mode 100644 inventory/management/commands/qwen.py diff --git a/inventory/management/commands/claude.py b/inventory/management/commands/claude.py new file mode 100644 index 00000000..eeaa5ec2 --- /dev/null +++ b/inventory/management/commands/claude.py @@ -0,0 +1,433 @@ +from django_ledger.io import roles +from django.core.management.base import BaseCommand +from django.utils.translation import gettext_lazy as _ +from django_ledger.models import ChartOfAccountModel, AccountModel,EntityModel + + +class Command(BaseCommand): + help = 'Creates Chart of Accounts for Deepseek entity' + + def handle(self, *args, **options): + """ + Create chart of accounts for automotive dealership business + """ + + # Create Chart of Accounts + entity_model = EntityModel.objects.get( + name="Claude" + ) + # entity_model.get_all_accounts().delete() + coa_model, created = ChartOfAccountModel.objects.get_or_create( + entity=entity_model, + name='Automotive Dealership Chart of Accounts', + ) + + accounts_data = [ + # Current Assets + { + 'code': '1010', + 'name': 'Cash on Hand', + 'name_arabic': 'الصندوق', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True + }, + { + 'code': '1020', + 'name': 'Bank', + 'name_arabic': 'البنك', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True + }, + { + 'code': '1030', + 'name': 'Accounts Receivable', + 'name_arabic': 'العملاء', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': True + }, + { + 'code': '1040', + 'name': 'Inventory (Cars)', + 'name_arabic': 'مخزون السيارات', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': True + }, + { + 'code': '1045', + 'name': 'Spare Parts Inventory', + 'name_arabic': 'مخزون قطع الغيار', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '1050', + 'name': 'Employee Advances', + 'name_arabic': 'سُلف وأمانات الموظفين', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '1060', + 'name': 'Prepaid Expenses', + 'name_arabic': 'مصروفات مدفوعة مقدماً', + 'role': roles.ASSET_CA_PREPAID, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '1070', + 'name': 'Notes Receivable', + 'name_arabic': 'أوراق القبض', + 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + 'balance_type': roles.DEBIT, + 'locked': False + }, + + # Fixed Assets (2000-2999) + { + 'code': '2010', + 'name': 'Lands', + 'name_arabic': 'أراضي', + 'role': roles.ASSET_LTI_LAND, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2011', + 'name': 'Buildings', + 'name_arabic': 'مباني', + 'role': roles.ASSET_PPE_BUILDINGS, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2012', + 'name': 'Company Vehicles', + 'name_arabic': 'سيارات الشركة', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2013', + 'name': 'Equipment & Tools', + 'name_arabic': 'أجهزة ومعدات', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2014', + 'name': 'Furniture & Fixtures', + 'name_arabic': 'أثاث وديكور', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2015', + 'name': 'Other Fixed Assets', + 'name_arabic': 'أصول ثابتة أخرى', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2020', + 'name': 'Long-term Investments', + 'name_arabic': 'استثمارات طويلة الأجل', + 'role': roles.ASSET_LTI_SECURITIES, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '2030', + 'name': 'Intangible Assets', + 'name_arabic': 'أصول غير ملموسة', + 'role': roles.ASSET_INTANGIBLE_ASSETS, + 'balance_type': roles.DEBIT, + 'locked': False + }, + + # Current Liabilities (3000-3999) + { + 'code': '3010', + 'name': 'Accounts Payable', + 'name_arabic': 'الموردين', + 'role': roles.LIABILITY_CL_ACC_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': True + }, + { + 'code': '3020', + 'name': 'Notes Payable', + 'name_arabic': 'أوراق الدفع', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '3030', + 'name': 'Short-term Loans', + 'name_arabic': 'قروض قصيرة الأجل', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '3040', + 'name': 'Employee Payables', + 'name_arabic': 'السلف المستحقة', + 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '3050', + 'name': 'Accrued Expenses', + 'name_arabic': 'مصروفات مستحقة', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '3060', + 'name': 'Accrued Taxes', + 'name_arabic': 'ضرائب مستحقة', + 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '3070', + 'name': 'Provisions', + 'name_arabic': 'مخصصات', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False + }, + + # Long-term Liabilities (4000-4999) + { + 'code': '4010', + 'name': 'Long-term Bank Loans', + 'name_arabic': 'قروض طويلة الأجل', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '4020', + 'name': 'Lease Liabilities', + 'name_arabic': 'التزامات تمويلية', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '4030', + 'name': 'Other Long-term Liabilities', + 'name_arabic': 'التزامات أخرى طويلة الأجل', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + + # Equity (5000-5999) + { + 'code': '5010', + 'name': 'Capital', + 'name_arabic': 'رأس المال', + 'role': roles.EQUITY_CAPITAL, + 'balance_type': roles.CREDIT, + 'locked': True + }, + { + 'code': '5020', + 'name': 'Statutory Reserve', + 'name_arabic': 'الاحتياطي القانوني', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '5030', + 'name': 'Retained Earnings', + 'name_arabic': 'احتياطي الأرباح', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '5040', + 'name': 'Profit & Loss for the Period', + 'name_arabic': 'أرباح وخسائر الفترة', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False + }, + + # Revenue (6000-6999) + { + 'code': '6010', + 'name': 'Car Sales', + 'name_arabic': 'مبيعات السيارات', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': True + }, + { + 'code': '6020', + 'name': 'After-Sales Services', + 'name_arabic': 'إيرادات خدمات ما بعد البيع', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '6030', + 'name': 'Car Rental Income', + 'name_arabic': 'إيرادات تأجير سيارات', + 'role': roles.INCOME_PASSIVE, + 'balance_type': roles.CREDIT, + 'locked': False + }, + { + 'code': '6040', + 'name': 'Other Income', + 'name_arabic': 'إيرادات أخرى', + 'role': roles.INCOME_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False + }, + + # Expenses (7000-7999) + { + 'code': '7010', + 'name': 'Cost of Goods Sold', + 'name_arabic': 'تكلفة البضاعة المباعة', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': True + }, + { + 'code': '7015', + 'name': 'Spare Parts Cost Consumed', + 'name_arabic': 'تكلفة قطع الغيار المستهلكة', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7020', + 'name': 'Salaries & Wages', + 'name_arabic': 'رواتب وأجور', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7030', + 'name': 'Rent', + 'name_arabic': 'إيجار', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7040', + 'name': 'Utilities', + 'name_arabic': 'كهرباء ومياه', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7050', + 'name': 'Advertising & Marketing', + 'name_arabic': 'دعاية وإعلان', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7060', + 'name': 'Maintenance', + 'name_arabic': 'صيانة', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7070', + 'name': 'Operating Expenses', + 'name_arabic': 'مصاريف تشغيلية', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7080', + 'name': 'Depreciation', + 'name_arabic': 'استهلاك أصول ثابتة', + 'role': roles.EXPENSE_DEPRECIATION, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7090', + 'name': 'Fees & Taxes', + 'name_arabic': 'رسوم وضرائب', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7100', + 'name': 'Bank Charges', + 'name_arabic': 'مصاريف بنكية', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False + }, + { + 'code': '7110', + 'name': 'Other Expenses', + 'name_arabic': 'مصاريف أخرى', + 'role': roles.EXPENSE_OTHER, + 'balance_type': roles.DEBIT, + 'locked': False + } + ] + # Create accounts + created_accounts = [] + + for account_data in accounts_data: + try: + account = entity_model.create_account( + coa_model=coa_model, + code=account_data['code'], + name=_(account_data['name']), + role=_(account_data['role']), + balance_type=_(account_data['balance_type']), + active=True + ) + created_accounts.append(account) + self.stdout.write(self.style.SUCCESS( + f"Created account: {account.code} - {account.name}" + )) + except Exception as e: + self.stdout.write(self.style.ERROR( + f"Error creating account {account_data['code']}: {str(e)}" + )) + + self.stdout.write(self.style.SUCCESS( + f"\nSuccessfully created {len(created_accounts)} accounts in Chart of Accounts" + )) + return coa_model, created_accounts \ No newline at end of file diff --git a/inventory/management/commands/deepseek.py b/inventory/management/commands/deepseek.py new file mode 100644 index 00000000..01712cb6 --- /dev/null +++ b/inventory/management/commands/deepseek.py @@ -0,0 +1,124 @@ +from django.core.management.base import BaseCommand +from django_ledger.models import EntityModel, ChartOfAccountModel, AccountModel +from django.contrib.auth import get_user_model + +User = get_user_model() + +class Command(BaseCommand): + help = 'Creates Chart of Accounts for Deepseek entity' + + def handle(self, *args, **options): + # Get or create admin user + admin_user = User.objects.filter(is_superuser=True).first() + if not admin_user: + self.stdout.write(self.style.ERROR('No admin user found!')) + return + + # Get or create Deepseek entity with minimal valid fields + entity, created = EntityModel.objects.get_or_create( + name='Deepseek', + defaults={ + 'admin': admin_user, + 'fy_start_month': 1, # January fiscal year start + 'accrual_method': True # Using accrual accounting + } + ) + + if created: + self.stdout.write(self.style.SUCCESS('Created Deepseek entity')) + else: + self.stdout.write(self.style.SUCCESS('Deepseek entity already exists')) + + # Get or create Chart of Accounts + coa, created = ChartOfAccountModel.objects.get_or_create( + slug='deepseek-coa', + defaults={ + 'name': 'Deepseek Chart of Accounts', + 'entity': entity, + 'description': 'Standard COA for Deepseek automotive business' + } + ) + + if created: + self.stdout.write(self.style.SUCCESS('Created Chart of Accounts')) + else: + self.stdout.write(self.style.SUCCESS('Chart of Accounts already exists')) + + # Account definitions with string role literals + ACCOUNTS = [ + # Assets + ('1010', 'Cash on Hand', 'الصندوق', 'asset_ca_cash'), + ('1020', 'Bank', 'البنك', 'asset_ca_cash'), + ('1030', 'Accounts Receivable', 'العملاء', 'asset_ca_receivable'), + ('1040', 'Inventory (Cars)', 'مخزون السيارات', 'asset_ca_inventory'), + ('1045', 'Spare Parts Inventory', 'مخزون قطع الغيار', 'asset_ca_inventory'), + ('1050', 'Employee Advances', 'سُلف وأمانات الموظفين', 'asset_ca_other'), + ('1060', 'Prepaid Expenses', 'مصروفات مدفوعة مقدماً', 'asset_ca_other'), + ('1070', 'Notes Receivable', 'أوراق القبض', 'asset_ca_receivable'), + ('2010', 'Lands', 'أراضي', 'asset_ppe_land'), + ('2011', 'Buildings', 'مباني', 'asset_ppe_building'), + ('2012', 'Company Vehicles', 'سيارات الشركة', 'asset_ppe_equipment'), + ('2013', 'Equipment & Tools', 'أجهزة ومعدات', 'asset_ppe_equipment'), + ('2014', 'Furniture & Fixtures', 'أثاث وديكور', 'asset_ppe_equipment'), + ('2015', 'Other Fixed Assets', 'أصول ثابتة أخرى', 'asset_ppe_other'), + ('2020', 'Long-term Investments', 'استثمارات طويلة الأجل', 'asset_lt_investments'), + ('2030', 'Intangible Assets', 'أصول غير ملموسة', 'asset_lt_intangible'), + + # Liabilities + ('3010', 'Accounts Payable', 'الموردين', 'liability_cl_acc_payable'), + ('3020', 'Notes Payable', 'أوراق الدفع', 'liability_cl_acc_payable'), + ('3030', 'Short-term Loans', 'قروض قصيرة الأجل', 'liability_cl_debt'), + ('3040', 'Employee Payables', 'السلف المستحقة', 'liability_cl_acc_payable'), + ('3050', 'Accrued Expenses', 'مصروفات مستحقة', 'liability_cl_acc_expense'), + ('3060', 'Accrued Taxes', 'ضرائب مستحقة', 'liability_cl_acc_expense'), + ('3070', 'Provisions', 'مخصصات', 'liability_cl_acc_expense'), + ('4010', 'Long-term Bank Loans', 'قروض طويلة الأجل', 'liability_lt_loans'), + ('4020', 'Lease Liabilities', 'التزامات تمويلية', 'liability_lt_loans'), + ('4030', 'Other Long-term Liabilities', 'التزامات أخرى طويلة الأجل', 'liability_lt_other'), + + # Equity + ('5010', 'Capital', 'رأس المال', 'equity_capital'), + ('5020', 'Statutory Reserve', 'الاحتياطي القانوني', 'equity_retained'), + ('5030', 'Retained Earnings', 'احتياطي الأرباح', 'equity_retained'), + ('5040', 'Profit & Loss for the Period', 'أرباح وخسائر الفترة', 'equity_earnings'), + + # Income + ('6010', 'Car Sales', 'مبيعات السيارات', 'income_operating'), + ('6020', 'After-Sales Services', 'إيرادات خدمات ما بعد البيع', 'income_operating'), + ('6030', 'Car Rental Income', 'إيرادات تأجير سيارات', 'income_operating'), + ('6040', 'Other Income', 'إيرادات أخرى', 'income_other'), + + # Expenses + ('7010', 'Cost of Goods Sold', 'تكلفة البضاعة المباعة', 'expense_cogs'), + ('7015', 'Spare Parts Cost Consumed', 'تكلفة قطع الغيار المستهلكة', 'expense_cogs'), + ('7020', 'Salaries & Wages', 'رواتب وأجور', 'expense_operating'), + ('7030', 'Rent', 'إيجار', 'expense_operating'), + ('7040', 'Utilities', 'كهرباء ومياه', 'expense_operating'), + ('7050', 'Advertising & Marketing', 'دعاية وإعلان', 'expense_operating'), + ('7060', 'Maintenance', 'صيانة', 'expense_operating'), + ('7070', 'Operating Expenses', 'مصاريف تشغيلية', 'expense_operating'), + ('7080', 'Depreciation', 'استهلاك أصول ثابتة', 'expense_depreciation'), + ('7090', 'Fees & Taxes', 'رسوم وضرائب', 'expense_operating'), + ('7100', 'Bank Charges', 'مصاريف بنكية', 'expense_operating'), + ('7110', 'Other Expenses', 'مصاريف أخرى', 'expense_other'), + ] + + # Create accounts + created_count = 0 + for code, name_en, name_ar, role in ACCOUNTS: + acc, created = AccountModel.objects.get_or_create( + coa=coa, + code=code, + defaults={ + 'name': name_en, + 'name_ar': name_ar, + 'role_default': role, + 'active': True, + 'balance_type': 'debit' if role.startswith(('asset', 'expense')) else 'credit' + } + ) + if created: + created_count += 1 + + self.stdout.write(self.style.SUCCESS(f'Successfully created {created_count} accounts')) + self.stdout.write(self.style.SUCCESS(f'Total accounts in COA: {len(ACCOUNTS)}')) \ No newline at end of file diff --git a/inventory/management/commands/gemini.py b/inventory/management/commands/gemini.py new file mode 100644 index 00000000..3208e6f5 --- /dev/null +++ b/inventory/management/commands/gemini.py @@ -0,0 +1,127 @@ +from django.core.management.base import BaseCommand, CommandError +from django_ledger.models import AccountModel, EntityModel, AccountRole, AccountType # تم التعديل هنا + +class Command(BaseCommand): + help = 'ينشئ أو يحدث حسابات Django Ledger المحددة لكيان معين.' + + def add_arguments(self, parser): + # إضافة وسيط لتحديد اسم الكيان + parser.add_argument( + '--entity_name', + type=str, + default='qemini', # اسم الكيان الافتراضي + help='اسم الكيان الذي سيتم ربط الحسابات به (افتراضي: qemini).' + ) + + def handle(self, *args, **options): + entity_name = options['entity_name'] + + # البحث عن الكيان بناءً على الاسم المقدم + try: + entity = EntityModel.objects.get(name__iexact=entity_name) + self.stdout.write(self.style.SUCCESS(f"تم العثور على الكيان: {entity.name}")) + except EntityModel.DoesNotExist: + raise CommandError(f"لم يتم العثور على كيان باسم '{entity_name}'. يرجى التأكد من وجوده.") + except Exception as e: + raise CommandError(f"حدث خطأ أثناء جلب الكيان '{entity_name}': {e}") + + # قائمة الحسابات المراد إنشاؤها + accounts_data = [ + # الأصول (مدين) + {'code': '1010', 'name': 'Cash on Hand', 'role': AccountRole.CASH, 'balance_type': AccountType.DEBIT}, + {'code': '1020', 'name': 'Bank', 'role': AccountRole.CASH, 'balance_type': AccountType.DEBIT}, + {'code': '1030', 'name': 'Accounts Receivable', 'role': AccountRole.RECEIVABLE, 'balance_type': AccountType.DEBIT}, + {'code': '1040', 'name': 'Inventory (Cars)', 'role': AccountRole.INVENTORY, 'balance_type': AccountType.DEBIT}, + {'code': '1045', 'name': 'Spare Parts Inventory', 'role': AccountRole.INVENTORY, 'balance_type': AccountType.DEBIT}, + {'code': '1050', 'name': 'Employee Advances', 'role': AccountRole.OTHER_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '1060', 'name': 'Prepaid Expenses', 'role': AccountRole.OTHER_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '1070', 'name': 'Notes Receivable', 'role': AccountRole.RECEIVABLE, 'balance_type': AccountType.DEBIT}, + + {'code': '2010', 'name': 'Lands', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2011', 'name': 'Buildings', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2012', 'name': 'Company Vehicles', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2013', 'name': 'Equipment & Tools', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2014', 'name': 'Furniture & Fixtures', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2015', 'name': 'Other Fixed Assets', 'role': AccountRole.FIXED_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2020', 'name': 'Long-term Investments', 'role': AccountRole.OTHER_ASSET, 'balance_type': AccountType.DEBIT}, + {'code': '2030', 'name': 'Intangible Assets', 'role': AccountRole.INTANGIBLE_ASSET, 'balance_type': AccountType.DEBIT}, + + # الخصوم (دائن) + {'code': '3010', 'name': 'Accounts Payable', 'role': AccountRole.PAYABLE, 'balance_type': AccountType.CREDIT}, + {'code': '3020', 'name': 'Notes Payable', 'role': AccountRole.PAYABLE, 'balance_type': AccountType.CREDIT}, + {'code': '3030', 'name': 'Short-term Loans', 'role': AccountRole.OTHER_LIABILITY, 'balance_type': AccountType.CREDIT}, + {'code': '3040', 'name': 'Employee Payables', 'role': AccountRole.OTHER_LIABILITY, 'balance_type': AccountType.CREDIT}, + {'code': '3050', 'name': 'Accrued Expenses', 'role': AccountRole.OTHER_LIABILITY, 'balance_type': AccountType.CREDIT}, + {'code': '3060', 'name': 'Accrued Taxes', 'role': AccountRole.OTHER_LIABILITY, 'balance_type': AccountType.CREDIT}, + {'code': '3070', 'name': 'Provisions', 'role': AccountRole.PROVISION, 'balance_type': AccountType.CREDIT}, + + {'code': '4010', 'name': 'Long-term Bank Loans', 'role': AccountRole.LONG_TERM_DEBT, 'balance_type': AccountType.CREDIT}, + {'code': '4020', 'name': 'Lease Liabilities', 'role': AccountRole.LONG_TERM_DEBT, 'balance_type': AccountType.CREDIT}, + {'code': '4030', 'name': 'Other Long-term Liabilities', 'role': AccountRole.LONG_TERM_DEBT, 'balance_type': AccountType.CREDIT}, + + # حقوق الملكية (دائن) + {'code': '5010', 'name': 'Capital', 'role': AccountRole.EQUITY, 'balance_type': AccountType.CREDIT}, + {'code': '5020', 'name': 'Statutory Reserve', 'role': AccountRole.RETAINED_EARNINGS, 'balance_type': AccountType.CREDIT}, + {'code': '5030', 'name': 'Retained Earnings', 'role': AccountRole.RETAINED_EARNINGS, 'balance_type': AccountType.CREDIT}, + {'code': '5040', 'name': 'Profit & Loss for the Period', 'role': AccountRole.RETAINED_EARNINGS, 'balance_type': AccountType.CREDIT}, + + # الإيرادات (دائن) + {'code': '6010', 'name': 'Car Sales', 'role': AccountRole.SALES, 'balance_type': AccountType.CREDIT}, + {'code': '6020', 'name': 'After-Sales Services', 'role': AccountRole.SALES, 'balance_type': AccountType.CREDIT}, + {'code': '6030', 'name': 'Car Rental Income', 'role': AccountRole.SALES, 'balance_type': AccountType.CREDIT}, + {'code': '6040', 'name': 'Other Income', 'role': AccountRole.OTHER_INCOME, 'balance_type': AccountType.CREDIT}, + + # المصروفات (مدين) + {'code': '7010', 'name': 'Cost of Goods Sold', 'role': AccountRole.COST_OF_GOODS_SOLD, 'balance_type': AccountType.DEBIT}, + {'code': '7015', 'name': 'Spare Parts Cost Consumed', 'role': AccountRole.COST_OF_GOODS_SOLD, 'balance_type': AccountType.DEBIT}, + {'code': '7020', 'name': 'Salaries & Wages', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7030', 'name': 'Rent', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7040', 'name': 'Utilities', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7050', 'name': 'Advertising & Marketing', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7060', 'name': 'Maintenance', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7070', 'name': 'Operating Expenses', 'role': AccountRole.OPERATING_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7080', 'name': 'Depreciation', 'role': AccountRole.DEPRECIATION_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7090', 'name': 'Fees & Taxes', 'role': AccountRole.OTHER_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7100', 'name': 'Bank Charges', 'role': AccountRole.OTHER_EXPENSE, 'balance_type': AccountType.DEBIT}, + {'code': '7110', 'name': 'Other Expenses', 'role': AccountRole.OTHER_EXPENSE, 'balance_type': AccountType.DEBIT}, + ] + + created_count = 0 + updated_count = 0 + + for acc_data in accounts_data: + try: + # البحث عن الحساب الموجود أو إنشاء حساب جديد + account, created = AccountModel.objects.get_or_create( + entity=entity, + code=acc_data['code'], + defaults={ + 'name': acc_data['name'], + 'role': acc_data['role'], # تم التعديل هنا + 'balance_type': acc_data['balance_type'] # تم التعديل هنا + } + ) + + if created: + created_count += 1 + self.stdout.write(self.style.SUCCESS(f"تم إنشاء الحساب: {account.code} - {account.name}")) + else: + # إذا كان الحساب موجودًا، نقوم بتحديث اسمه ودوره ونوع رصيده إذا كان مختلفًا + if (account.name != acc_data['name'] or + account.role != acc_data['role'] or # تم التعديل هنا + account.balance_type != acc_data['balance_type']): # تم التعديل هنا + account.name = acc_data['name'] + account.role = acc_data['role'] + account.balance_type = acc_data['balance_type'] + account.save() + updated_count += 1 + self.stdout.write(self.style.WARNING(f"تم تحديث الحساب: {account.code} - {account.name}")) + else: + self.stdout.write(f"الحساب موجود بالفعل ولم يتطلب تحديث: {account.code} - {account.name}") + + except Exception as e: + self.stdout.write(self.style.ERROR(f"خطأ في معالجة الحساب {acc_data['code']} - {acc_data['name']}: {e}")) + + self.stdout.write(self.style.SUCCESS(f"\nعملية إنشاء/تحديث الحسابات اكتملت.")) + self.stdout.write(self.style.SUCCESS(f"عدد الحسابات التي تم إنشاؤها حديثًا: {created_count}")) + self.stdout.write(self.style.SUCCESS(f"عدد الحسابات التي تم تحديثها: {updated_count}")) diff --git a/inventory/management/commands/gpt.py b/inventory/management/commands/gpt.py new file mode 100644 index 00000000..ed26711a --- /dev/null +++ b/inventory/management/commands/gpt.py @@ -0,0 +1,123 @@ +from django.core.management.base import BaseCommand +from django_ledger.models.entity import EntityModel +from django_ledger.models.chart_of_accounts import ChartOfAccountModel +from django_ledger.models.accounts import AccountModel +from django_ledger.models.roles import RoleModel +from django_ledger.models.balance_types import BalanceTypeModel + +class Command(BaseCommand): + help = 'Create the chart of accounts for the ChatGPT entity' + + def handle(self, *args, **options): + # Step 1: Retrieve or create the entity + entity, created = EntityModel.objects.get_or_create(name="chatgpt") + if created: + self.stdout.write(self.style.SUCCESS("Entity 'chatgpt' created.")) + else: + self.stdout.write(self.style.WARNING("Entity 'chatgpt' already exists.")) + + # Step 2: Retrieve or create the default Chart of Accounts + if hasattr(entity, 'default_coa') and entity.default_coa: + coa = entity.default_coa + self.stdout.write(self.style.WARNING("Default Chart of Accounts already exists.")) + else: + coa = ChartOfAccountModel.objects.create(name="Default CoA", entity=entity) + entity.default_coa = coa + entity.save() + self.stdout.write(self.style.SUCCESS("Default Chart of Accounts created.")) + + # Step 3: Define the accounts to be created + accounts = [ + (1010, 'Cash on Hand', 'الصندوق', 'asset'), + (1020, 'Bank', 'البنك', 'asset'), + (1030, 'Accounts Receivable', 'العملاء', 'asset'), + (1040, 'Inventory (Cars)', 'مخزون السيارات', 'asset'), + (1045, 'Spare Parts Inventory', 'مخزون قطع الغيار', 'asset'), + (1050, 'Employee Advances', 'سُلف وأمانات الموظفين', 'asset'), + (1060, 'Prepaid Expenses', 'مصروفات مدفوعة مقدماً', 'asset'), + (1070, 'Notes Receivable', 'أوراق القبض', 'asset'), + (2010, 'Lands', 'أراضي', 'asset'), + (2011, 'Buildings', 'مباني', 'asset'), + (2012, 'Company Vehicles', 'سيارات الشركة', 'asset'), + (2013, 'Equipment & Tools', 'أجهزة ومعدات', 'asset'), + (2014, 'Furniture & Fixtures', 'أثاث وديكور', 'asset'), + (2015, 'Other Fixed Assets', 'أصول ثابتة أخرى', 'asset'), + (2020, 'Long-term Investments', 'استثمارات طويلة الأجل', 'asset'), + (2030, 'Intangible Assets', 'أصول غير ملموسة', 'asset'), + (3010, 'Accounts Payable', 'الموردين', 'liability'), + (3020, 'Notes Payable', 'أوراق الدفع', 'liability'), + (3030, 'Short-term Loans', 'قروض قصيرة الأجل', 'liability'), + (3040, 'Employee Payables', 'السلف المستحقة', 'liability'), + (3050, 'Accrued Expenses', 'مصروفات مستحقة', 'liability'), + (3060, 'Accrued Taxes', 'ضرائب مستحقة', 'liability'), + (3070, 'Provisions', 'مخصصات', 'liability'), + (4010, 'Long-term Bank Loans', 'قروض طويلة الأجل', 'liability'), + (4020, 'Lease Liabilities', 'التزامات تمويلية', 'liability'), + (4030, 'Other Long-term Liabilities', 'التزامات أخرى طويلة الأجل', 'liability'), + (5010, 'Capital', 'رأس المال', 'equity'), + (5020, 'Statutory Reserve', 'الاحتياطي القانوني', 'equity'), + (5030, 'Retained Earnings', 'احتياطي الأرباح', 'equity'), + (5040, 'Profit & Loss for the Period', 'أرباح وخسائر الفترة', 'equity'), + (6010, 'Car Sales', 'مبيعات السيارات', 'income'), + (6020, 'After-Sales Services', 'إيرادات خدمات ما بعد البيع', 'income'), + (6030, 'Car Rental Income', 'إيرادات تأجير سيارات', 'income'), + (6040, 'Other Income', 'إيرادات أخرى', 'income'), + (7010, 'Cost of Goods Sold', 'تكلفة البضاعة المباعة', 'expense'), + (7015, 'Spare Parts Cost Consumed', 'تكلفة قطع الغيار المستهلكة', 'expense'), + (7020, 'Salaries & Wages', 'رواتب وأجور', 'expense'), + (7030, 'Rent', 'إيجار', 'expense'), + (7040, 'Utilities', 'كهرباء ومياه', 'expense'), + (7050, 'Advertising & Marketing', 'دعاية وإعلان', 'expense'), + (7060, 'Maintenance', 'صيانة', 'expense'), + (7070, 'Operating Expenses', 'مصاريف تشغيلية', 'expense'), + (7080, 'Depreciation', 'استهلاك أصول ثابتة', 'expense'), + (7090, 'Fees & Taxes', 'رسوم وضرائب', 'expense'), + (7100, 'Bank Charges', 'مصاريف بنكية', 'expense'), + (7110, 'Other Expenses', 'مصاريف أخرى', 'expense'), + ] + + # Mapping for role and balance_type + role_mapping = { + 'asset': 'ASSET', + 'liability': 'LIABILITY', + 'equity': 'EQUITY', + 'income': 'INCOME', + 'expense': 'EXPENSE', + } + + balance_type_mapping = { + 'ASSET': 'DEBIT', + 'LIABILITY': 'CREDIT', + 'EQUITY': 'CREDIT', + 'INCOME': 'CREDIT', + 'EXPENSE': 'DEBIT', + } + + # Step 4: Delete existing accounts in the CoA + existing_accounts = AccountModel.objects.filter(coa_model=coa) + count_deleted = existing_accounts.count() + existing_accounts.delete() + self.stdout.write(self.style.SUCCESS(f"Deleted {count_deleted} existing accounts.")) + + # Step 5: Create new accounts + for code, name_en, name_ar, role_slug in accounts: + role = RoleModel.objects.get(slug=role_slug) + balance_type = BalanceTypeModel.objects.get(role=role) + parent = None # Set to None for root accounts + + # Determine parent-child relationships + if code in [1040, 1045, 2012, 2013, 2014, 2015, 2020, 2030]: + parent_code = code - 10 # Example logic for determining parent code + parent = AccountModel.objects.get(coa_model=coa, code=parent_code) + + account = AccountModel.objects.create( + coa_model=coa, + code=code, + name=name_en, + arabic_name=name_ar, + role=role, + balance_type=balance_type, + parent=parent, + depth=parent.depth + 1 if parent else 0, + ) + self.stdout.write(self.style.SUCCESS(f"Account {name_en} ({code}) created.")) diff --git a/inventory/management/commands/qwen.py b/inventory/management/commands/qwen.py new file mode 100644 index 00000000..66d77ac0 --- /dev/null +++ b/inventory/management/commands/qwen.py @@ -0,0 +1,76 @@ +from django.core.management.base import BaseCommand +from django_ledger.models import AccountModel +from django_ledger.constants import ACCOUNT_TYPE_ASSET, ACCOUNT_TYPE_LIABILITY, ACCOUNT_TYPE_EQUITY, ACCOUNT_TYPE_INCOME, ACCOUNT_TYPE_EXPENSE + +class Command(BaseCommand): + help = 'Creates default accounts for the entity "qwen" in Django Ledger' + + def handle(self, *args, **kwargs): + self.stdout.write('Creating accounts for entity "qwen"...') + + accounts_data = [ + # Assets (Debit Balance) + {'code': '1010', 'name_ar': 'الصندوق', 'name_en': 'Cash on Hand', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1020', 'name_ar': 'البنك', 'name_en': 'Bank', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1030', 'name_ar': 'العملاء', 'name_en': 'Accounts Receivable', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1040', 'name_ar': 'مخزون السيارات', 'name_en': 'Inventory (Cars)', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1045', 'name_ar': 'مخزون قطع الغيار', 'name_en': 'Spare Parts Inventory', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1050', 'name_ar': 'سُلف وأمانات الموظفين', 'name_en': 'Employee Advances', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1060', 'name_ar': 'مصروفات مدفوعة مقدماً', 'name_en': 'Prepaid Expenses', 'type': ACCOUNT_TYPE_ASSET}, + {'code': '1070', 'name_ar': 'أوراق القبض', 'name_en': 'Notes Receivable', 'type': ACCOUNT_TYPE_ASSET}, + + # Liabilities (Credit Balance) + {'code': '3010', 'name_ar': 'الموردين', 'name_en': 'Accounts Payable', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3020', 'name_ar': 'أوراق الدفع', 'name_en': 'Notes Payable', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3030', 'name_ar': 'قروض قصيرة الأجل', 'name_en': 'Short-term Loans', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3040', 'name_ar': 'السلف المستحقة', 'name_en': 'Employee Payables', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3050', 'name_ar': 'مصروفات مستحقة', 'name_en': 'Accrued Expenses', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3060', 'name_ar': 'ضرائب مستحقة', 'name_en': 'Accrued Taxes', 'type': ACCOUNT_TYPE_LIABILITY}, + {'code': '3070', 'name_ar': 'مخصصات', 'name_en': 'Provisions', 'type': ACCOUNT_TYPE_LIABILITY}, + + # Equity (Credit Balance) + {'code': '5010', 'name_ar': 'رأس المال', 'name_en': 'Capital', 'type': ACCOUNT_TYPE_EQUITY}, + {'code': '5020', 'name_ar': 'الاحتياطي القانوني', 'name_en': 'Statutory Reserve', 'type': ACCOUNT_TYPE_EQUITY}, + {'code': '5030', 'name_ar': 'احتياطي الأرباح', 'name_en': 'Retained Earnings', 'type': ACCOUNT_TYPE_EQUITY}, + {'code': '5040', 'name_ar': 'أرباح وخسائر الفترة', 'name_en': 'Profit & Loss for the Period', 'type': ACCOUNT_TYPE_EQUITY}, + + # Income (Revenue) (Credit Balance) + {'code': '6010', 'name_ar': 'مبيعات السيارات', 'name_en': 'Car Sales', 'type': ACCOUNT_TYPE_INCOME}, + {'code': '6020', 'name_ar': 'إيرادات خدمات ما بعد البيع', 'name_en': 'After-Sales Services', 'type': ACCOUNT_TYPE_INCOME}, + {'code': '6030', 'name_ar': 'إيرادات تأجير سيارات', 'name_en': 'Car Rental Income', 'type': ACCOUNT_TYPE_INCOME}, + {'code': '6040', 'name_ar': 'إيرادات أخرى', 'name_en': 'Other Income', 'type': ACCOUNT_TYPE_INCOME}, + + # Expenses (Debit Balance) + {'code': '7010', 'name_ar': 'تكلفة البضاعة المباعة', 'name_en': 'Cost of Goods Sold', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7015', 'name_ar': 'تكلفة قطع الغيار المستهلكة', 'name_en': 'Spare Parts Cost Consumed', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7020', 'name_ar': 'رواتب وأجور', 'name_en': 'Salaries & Wages', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7030', 'name_ar': 'إيجار', 'name_en': 'Rent', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7040', 'name_ar': 'كهرباء ومياه', 'name_en': 'Utilities', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7050', 'name_ar': 'دعاية وإعلان', 'name_en': 'Advertising & Marketing', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7060', 'name_ar': 'صيانة', 'name_en': 'Maintenance', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7070', 'name_ar': 'مصاريف تشغيلية', 'name_en': 'Operating Expenses', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7080', 'name_ar': 'استهلاك أصول ثابتة', 'name_en': 'Depreciation', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7090', 'name_ar': 'رسوم وضرائب', 'name_en': 'Fees & Taxes', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7100', 'name_ar': 'مصاريف بنكية', 'name_en': 'Bank Charges', 'type': ACCOUNT_TYPE_EXPENSE}, + {'code': '7110', 'name_ar': 'مصاريف أخرى', 'name_en': 'Other Expenses', 'type': ACCOUNT_TYPE_EXPENSE}, + ] + + created_count = 0 + for acc in accounts_data: + account, created = objects.get_or_create( + code=acc['code'], + defaults={ + 'name': acc['name_ar'], + 'name_en': acc['name_en'], + 'account_type': acc['type'], + 'balance_type': BALANCE_TYPE_CREDIT if acc['type'] in [ + ACCOUNT_TYPE_LIABILITY, + ACCOUNT_TYPE_EQUITY, + ACCOUNT_TYPE_INCOME + ] else BALANCE_TYPE_DEBIT + } + ) + if created: + created_count += 1 + + self.stdout.write(self.style.SUCCESS(f'Successfully created {created_count} accounts for "qwen".')) \ No newline at end of file diff --git a/inventory/models.py b/inventory/models.py index f31ae132..f6ef07b0 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -1965,6 +1965,10 @@ class Opportunity(models.Model): def get_tasks(self): return self._get_filter(Tasks) + def get_meetings(self): + return self.lead.get_meetings() + def get_calls(self): + return self.lead.get_calls() def get_schedules(self): return self.lead.get_all_schedules().filter( scheduled_at__gt=timezone.now() diff --git a/templates/crm/leads/lead_detail.html b/templates/crm/leads/lead_detail.html index 30baf6e8..324b275d 100644 --- a/templates/crm/leads/lead_detail.html +++ b/templates/crm/leads/lead_detail.html @@ -102,6 +102,21 @@ +
+
+
+
+
{{ _("Related Records") }}
+
{{ _("Opportunity") }}
+ {% if lead.opportunity %} + {{ lead.opportunity }} + {% else %} +

{{ _("No Opportunity") }}

+ {% endif %} +
+
+
+
@@ -469,25 +484,7 @@ {% for task in tasks %} - - -
- -
- - {{task.title}} -
{{task.description}}
- - {{task.assigned_to}} - {{task.created|naturalday|capfirst}} - - {% if task.completed %} - - {% else %} - - {% endif %} - - + {% include "partials/task.html" %} {% endfor %} diff --git a/templates/crm/opportunities/opportunity_detail.html b/templates/crm/opportunities/opportunity_detail.html index 6f301997..b84db598 100644 --- a/templates/crm/opportunities/opportunity_detail.html +++ b/templates/crm/opportunities/opportunity_detail.html @@ -99,6 +99,16 @@

{{ _("Related Records")}}

+
+
+
{{ _("Lead") }}
+
+ {% if opportunity.lead %} + {{ _("View Lead")}}  + {% else %} +

{{ _("No Lead") }}

+ {% endif %} +
{{ _("Estimate") }}
@@ -432,7 +442,7 @@
- {% for metting in opportunity.lead.get_meetings %} + {% for metting in opportunity.get_meetings %}
@@ -454,12 +464,10 @@

Call

-
-
{{opportunity.get_all_notes}}
@@ -471,7 +479,7 @@ - {% for call in opportunity.lead.get_calls %} + {% for call in opportunity.get_calls %} @@ -543,7 +551,7 @@ - {% for email in opportunity.lead.get_emails %} + {% for email in opportunity.get_emails %} - + - +
{{call.purpose}} {{call.scheduled_by}}
From 1d16c548115d25354a69e653695a363de0617cc8 Mon Sep 17 00:00:00 2001 From: ismail Date: Mon, 2 Jun 2025 14:30:03 +0300 Subject: [PATCH 2/3] more updates --- .../crm/opportunities/opportunity_detail.html | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/templates/crm/opportunities/opportunity_detail.html b/templates/crm/opportunities/opportunity_detail.html index b84db598..f758cee0 100644 --- a/templates/crm/opportunities/opportunity_detail.html +++ b/templates/crm/opportunities/opportunity_detail.html @@ -1,6 +1,14 @@ {% extends 'base.html' %} {% load i18n static humanize %} {% block title %}{{ _("Opportunity Detail") }}{% endblock title %} +{% block customCSS %} + +{% endblock customCSS %} {% block content %}
@@ -79,12 +87,12 @@
    {% for event in opportunity.get_schedules %} -
  • -
    +
  • {{ event.scheduled_type|capfirst }} - {{ event.purpose }} -
-
{{ event.scheduled_at|naturaltime|capfirst }}
+
+ {{ event.purpose|capfirst }} + {{ event.scheduled_at|naturaltime|capfirst }} +
{% empty %}
  • {{ _("No upcoming events") }}
  • @@ -104,7 +112,7 @@
    {{ _("Lead") }}
    {% if opportunity.lead %} - {{ _("View Lead")}}  + {{ _("View Lead")}}  {% else %}

    {{ _("No Lead") }}

    {% endif %} @@ -114,7 +122,7 @@
    {{ _("Estimate") }}
    {% if opportunity.estimate %} - {{ _("View Quotation")}} + {{ _("View Quotation")}} {% else %}

    {{ _("No Estimate") }}

    {% endif %} @@ -124,7 +132,7 @@
    {{ _("Invoice") }}
    {% if opportunity.estimate.invoice %} - {{ _("View Invoice")}} + {{ _("View Invoice")}} {% else %}

    {{ _("No Invoice") }}

    {% endif %} @@ -244,7 +252,7 @@
    :{{ opportunity.customer.phone_number }}{{ opportunity.lead.phone_number }}
    @@ -254,7 +262,7 @@ :{{ opportunity.customer.email}}{{ opportunity.lead.email}}
    From 351d23a6d8ec5d09742ba89932dc0949b8cc874b Mon Sep 17 00:00:00 2001 From: ismail Date: Mon, 2 Jun 2025 17:58:41 +0300 Subject: [PATCH 3/3] update the lead transfer queryset --- inventory/management/commands/claude.py | 1874 +++++++++++++---- inventory/tasks.py | 744 +++++++ inventory/templatetags/custom_filters.py | 9 +- inventory/views.py | 1 + .../ledger/coa_accounts/account_list.html | 221 +- .../coa_accounts/partials/account_table.html | 69 + 6 files changed, 2432 insertions(+), 486 deletions(-) create mode 100644 templates/ledger/coa_accounts/partials/account_table.html diff --git a/inventory/management/commands/claude.py b/inventory/management/commands/claude.py index eeaa5ec2..bfb14a05 100644 --- a/inventory/management/commands/claude.py +++ b/inventory/management/commands/claude.py @@ -16,396 +16,1505 @@ class Command(BaseCommand): entity_model = EntityModel.objects.get( name="Claude" ) + coa_model = entity_model.get_default_coa() # entity_model.get_all_accounts().delete() - coa_model, created = ChartOfAccountModel.objects.get_or_create( - entity=entity_model, - name='Automotive Dealership Chart of Accounts', - ) + # coa_model, created = ChartOfAccountModel.objects.get_or_create( + # entity=entity_model, + # name='Automotive Dealership Chart of Accounts', + # ) + + # accounts_data = [ + # # Current Assets + # { + # 'code': '1010', + # 'name': 'Cash on Hand', + # 'name_arabic': 'الصندوق', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1020', + # 'name': 'Bank', + # 'name_arabic': 'البنك', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1030', + # 'name': 'Accounts Receivable', + # 'name_arabic': 'العملاء', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1040', + # 'name': 'Inventory (Cars)', + # 'name_arabic': 'مخزون السيارات', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1045', + # 'name': 'Spare Parts Inventory', + # 'name_arabic': 'مخزون قطع الغيار', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1050', + # 'name': 'Employee Advances', + # 'name_arabic': 'سُلف وأمانات الموظفين', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1060', + # 'name': 'Prepaid Expenses', + # 'name_arabic': 'مصروفات مدفوعة مقدماً', + # 'role': roles.ASSET_CA_PREPAID, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1070', + # 'name': 'Notes Receivable', + # 'name_arabic': 'أوراق القبض', + # 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Fixed Assets (2000-2999) + # { + # 'code': '2010', + # 'name': 'Lands', + # 'name_arabic': 'أراضي', + # 'role': roles.ASSET_LTI_LAND, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2011', + # 'name': 'Buildings', + # 'name_arabic': 'مباني', + # 'role': roles.ASSET_PPE_BUILDINGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2012', + # 'name': 'Company Vehicles', + # 'name_arabic': 'سيارات الشركة', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2013', + # 'name': 'Equipment & Tools', + # 'name_arabic': 'أجهزة ومعدات', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2014', + # 'name': 'Furniture & Fixtures', + # 'name_arabic': 'أثاث وديكور', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2015', + # 'name': 'Other Fixed Assets', + # 'name_arabic': 'أصول ثابتة أخرى', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2020', + # 'name': 'Long-term Investments', + # 'name_arabic': 'استثمارات طويلة الأجل', + # 'role': roles.ASSET_LTI_SECURITIES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '2030', + # 'name': 'Intangible Assets', + # 'name_arabic': 'أصول غير ملموسة', + # 'role': roles.ASSET_INTANGIBLE_ASSETS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Current Liabilities (3000-3999) + # { + # 'code': '3010', + # 'name': 'Accounts Payable', + # 'name_arabic': 'الموردين', + # 'role': roles.LIABILITY_CL_ACC_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '3020', + # 'name': 'Notes Payable', + # 'name_arabic': 'أوراق الدفع', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3030', + # 'name': 'Short-term Loans', + # 'name_arabic': 'قروض قصيرة الأجل', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3040', + # 'name': 'Employee Payables', + # 'name_arabic': 'السلف المستحقة', + # 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3050', + # 'name': 'Accrued Expenses', + # 'name_arabic': 'مصروفات مستحقة', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3060', + # 'name': 'Accrued Taxes', + # 'name_arabic': 'ضرائب مستحقة', + # 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3070', + # 'name': 'Provisions', + # 'name_arabic': 'مخصصات', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Long-term Liabilities (4000-4999) + # { + # 'code': '4010', + # 'name': 'Long-term Bank Loans', + # 'name_arabic': 'قروض طويلة الأجل', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4020', + # 'name': 'Lease Liabilities', + # 'name_arabic': 'التزامات تمويلية', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4030', + # 'name': 'Other Long-term Liabilities', + # 'name_arabic': 'التزامات أخرى طويلة الأجل', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Equity (5000-5999) + # { + # 'code': '5010', + # 'name': 'Capital', + # 'name_arabic': 'رأس المال', + # 'role': roles.EQUITY_CAPITAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '5020', + # 'name': 'Statutory Reserve', + # 'name_arabic': 'الاحتياطي القانوني', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '5030', + # 'name': 'Retained Earnings', + # 'name_arabic': 'احتياطي الأرباح', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '5040', + # 'name': 'Profit & Loss for the Period', + # 'name_arabic': 'أرباح وخسائر الفترة', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Revenue (6000-6999) + # { + # 'code': '6010', + # 'name': 'Car Sales', + # 'name_arabic': 'مبيعات السيارات', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '6020', + # 'name': 'After-Sales Services', + # 'name_arabic': 'إيرادات خدمات ما بعد البيع', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '6030', + # 'name': 'Car Rental Income', + # 'name_arabic': 'إيرادات تأجير سيارات', + # 'role': roles.INCOME_PASSIVE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '6040', + # 'name': 'Other Income', + # 'name_arabic': 'إيرادات أخرى', + # 'role': roles.INCOME_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Expenses (7000-7999) + # { + # 'code': '7010', + # 'name': 'Cost of Goods Sold', + # 'name_arabic': 'تكلفة البضاعة المباعة', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '7015', + # 'name': 'Spare Parts Cost Consumed', + # 'name_arabic': 'تكلفة قطع الغيار المستهلكة', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7020', + # 'name': 'Salaries & Wages', + # 'name_arabic': 'رواتب وأجور', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7030', + # 'name': 'Rent', + # 'name_arabic': 'إيجار', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7040', + # 'name': 'Utilities', + # 'name_arabic': 'كهرباء ومياه', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7050', + # 'name': 'Advertising & Marketing', + # 'name_arabic': 'دعاية وإعلان', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7060', + # 'name': 'Maintenance', + # 'name_arabic': 'صيانة', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7070', + # 'name': 'Operating Expenses', + # 'name_arabic': 'مصاريف تشغيلية', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7080', + # 'name': 'Depreciation', + # 'name_arabic': 'استهلاك أصول ثابتة', + # 'role': roles.EXPENSE_DEPRECIATION, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7090', + # 'name': 'Fees & Taxes', + # 'name_arabic': 'رسوم وضرائب', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7100', + # 'name': 'Bank Charges', + # 'name_arabic': 'مصاريف بنكية', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '7110', + # 'name': 'Other Expenses', + # 'name_arabic': 'مصاريف أخرى', + # 'role': roles.EXPENSE_OTHER, + # 'balance_type': roles.DEBIT, + # 'locked': False + # } + # ] + # # Create accounts + + # accounts_data = [ + # # Current Assets (1XXXX) + # { + # 'code': '10100', + # 'name': 'Cash on Hand', + # 'name_arabic': 'الصندوق', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '10200', + # 'name': 'Bank', + # 'name_arabic': 'البنك', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '10300', + # 'name': 'Accounts Receivable', + # 'name_arabic': 'العملاء', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '10400', + # 'name': 'Inventory (Cars)', + # 'name_arabic': 'مخزون السيارات', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '10450', + # 'name': 'Spare Parts Inventory', + # 'name_arabic': 'مخزون قطع الغيار', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '10500', + # 'name': 'Employee Advances', + # 'name_arabic': 'سُلف وأمانات الموظفين', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '10600', + # 'name': 'Prepaid Expenses', + # 'name_arabic': 'مصروفات مدفوعة مقدماً', + # 'role': roles.ASSET_CA_PREPAID, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '10700', + # 'name': 'Notes Receivable', + # 'name_arabic': 'أوراق القبض', + # 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Fixed Assets (2XXXX) + # { + # 'code': '20100', + # 'name': 'Lands', + # 'name_arabic': 'أراضي', + # 'role': roles.ASSET_LTI_LAND, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20110', + # 'name': 'Buildings', + # 'name_arabic': 'مباني', + # 'role': roles.ASSET_PPE_BUILDINGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20120', + # 'name': 'Company Vehicles', + # 'name_arabic': 'سيارات الشركة', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20130', + # 'name': 'Equipment & Tools', + # 'name_arabic': 'أجهزة ومعدات', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20140', + # 'name': 'Furniture & Fixtures', + # 'name_arabic': 'أثاث وديكور', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20150', + # 'name': 'Other Fixed Assets', + # 'name_arabic': 'أصول ثابتة أخرى', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20200', + # 'name': 'Long-term Investments', + # 'name_arabic': 'استثمارات طويلة الأجل', + # 'role': roles.ASSET_LTI_SECURITIES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '20300', + # 'name': 'Intangible Assets', + # 'name_arabic': 'أصول غير ملموسة', + # 'role': roles.ASSET_INTANGIBLE_ASSETS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Current Liabilities (3XXXX) + # { + # 'code': '30100', + # 'name': 'Accounts Payable', + # 'name_arabic': 'الموردين', + # 'role': roles.LIABILITY_CL_ACC_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '30200', + # 'name': 'Notes Payable', + # 'name_arabic': 'أوراق الدفع', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '30300', + # 'name': 'Short-term Loans', + # 'name_arabic': 'قروض قصيرة الأجل', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '30400', + # 'name': 'Employee Payables', + # 'name_arabic': 'السلف المستحقة', + # 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '30500', + # 'name': 'Accrued Expenses', + # 'name_arabic': 'مصروفات مستحقة', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '30600', + # 'name': 'Accrued Taxes', + # 'name_arabic': 'ضرائب مستحقة', + # 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '30700', + # 'name': 'Provisions', + # 'name_arabic': 'مخصصات', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Long-term Liabilities (4XXXX) + # { + # 'code': '40100', + # 'name': 'Long-term Bank Loans', + # 'name_arabic': 'قروض طويلة الأجل', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '40200', + # 'name': 'Lease Liabilities', + # 'name_arabic': 'التزامات تمويلية', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '40300', + # 'name': 'Other Long-term Liabilities', + # 'name_arabic': 'التزامات أخرى طويلة الأجل', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Equity (5XXXX) + # { + # 'code': '50100', + # 'name': 'Capital', + # 'name_arabic': 'رأس المال', + # 'role': roles.EQUITY_CAPITAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '50200', + # 'name': 'Statutory Reserve', + # 'name_arabic': 'الاحتياطي القانوني', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '50300', + # 'name': 'Retained Earnings', + # 'name_arabic': 'احتياطي الأرباح', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '50400', + # 'name': 'Profit & Loss for the Period', + # 'name_arabic': 'أرباح وخسائر الفترة', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Revenue (6XXXX) + # { + # 'code': '60100', + # 'name': 'Car Sales', + # 'name_arabic': 'مبيعات السيارات', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '60200', + # 'name': 'After-Sales Services', + # 'name_arabic': 'إيرادات خدمات ما بعد البيع', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '60300', + # 'name': 'Car Rental Income', + # 'name_arabic': 'إيرادات تأجير سيارات', + # 'role': roles.INCOME_PASSIVE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '60400', + # 'name': 'Other Income', + # 'name_arabic': 'إيرادات أخرى', + # 'role': roles.INCOME_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Expenses (7XXXX) + # { + # 'code': '70100', + # 'name': 'Cost of Goods Sold', + # 'name_arabic': 'تكلفة البضاعة المباعة', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '70150', + # 'name': 'Spare Parts Cost Consumed', + # 'name_arabic': 'تكلفة قطع الغيار المستهلكة', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70200', + # 'name': 'Salaries & Wages', + # 'name_arabic': 'رواتب وأجور', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70300', + # 'name': 'Rent', + # 'name_arabic': 'إيجار', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70400', + # 'name': 'Utilities', + # 'name_arabic': 'كهرباء ومياه', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70500', + # 'name': 'Advertising & Marketing', + # 'name_arabic': 'دعاية وإعلان', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70600', + # 'name': 'Maintenance', + # 'name_arabic': 'صيانة', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70700', + # 'name': 'Operating Expenses', + # 'name_arabic': 'مصاريف تشغيلية', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70800', + # 'name': 'Depreciation', + # 'name_arabic': 'استهلاك أصول ثابتة', + # 'role': roles.EXPENSE_DEPRECIATION, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '70900', + # 'name': 'Fees & Taxes', + # 'name_arabic': 'رسوم وضرائب', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '71000', + # 'name': 'Bank Charges', + # 'name_arabic': 'مصاريف بنكية', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '71100', + # 'name': 'Other Expenses', + # 'name_arabic': 'مصاريف أخرى', + # 'role': roles.EXPENSE_OTHER, + # 'balance_type': roles.DEBIT, + # 'locked': False + # } + # ] + + # accounts_data = [ + # # Current Assets (must start with 1) + # { + # 'code': '1010', + # 'name': 'Cash on Hand', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1020', + # 'name': 'Bank', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1030', + # 'name': 'Accounts Receivable', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1040', + # 'name': 'Inventory (Cars)', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1045', + # 'name': 'Spare Parts Inventory', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1050', + # 'name': 'Employee Advances', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1060', + # 'name': 'Prepaid Expenses', + # 'role': roles.ASSET_CA_PREPAID, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1070', + # 'name': 'Notes Receivable', + # 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Fixed Assets (must also start with 1) + # { + # 'code': '1110', + # 'name': 'Lands', + # 'role': roles.ASSET_LTI_LAND, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1111', + # 'name': 'Buildings', + # 'role': roles.ASSET_PPE_BUILDINGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1112', + # 'name': 'Company Vehicles', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1113', + # 'name': 'Equipment & Tools', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1114', + # 'name': 'Furniture & Fixtures', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1115', + # 'name': 'Other Fixed Assets', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1120', + # 'name': 'Long-term Investments', + # 'role': roles.ASSET_LTI_SECURITIES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1130', + # 'name': 'Intangible Assets', + # 'role': roles.ASSET_INTANGIBLE_ASSETS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Current Liabilities (must start with 2) + # { + # 'code': '2010', + # 'name': 'Accounts Payable', + # 'role': roles.LIABILITY_CL_ACC_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '2020', + # 'name': 'Notes Payable', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2030', + # 'name': 'Short-term Loans', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2040', + # 'name': 'Employee Payables', + # 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2050', + # 'name': 'Accrued Expenses', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2060', + # 'name': 'Accrued Taxes', + # 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2070', + # 'name': 'Provisions', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Long-term Liabilities (must also start with 2) + # { + # 'code': '2210', + # 'name': 'Long-term Bank Loans', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2220', + # 'name': 'Lease Liabilities', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2230', + # 'name': 'Other Long-term Liabilities', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Equity (must start with 3) + # { + # 'code': '3010', + # 'name': 'Capital', + # 'role': roles.EQUITY_CAPITAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '3020', + # 'name': 'Statutory Reserve', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3030', + # 'name': 'Retained Earnings', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3040', + # 'name': 'Profit & Loss for the Period', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Revenue (must start with 4) + # { + # 'code': '4010', + # 'name': 'Car Sales', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '4020', + # 'name': 'After-Sales Services', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4030', + # 'name': 'Car Rental Income', + # 'role': roles.INCOME_PASSIVE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4040', + # 'name': 'Other Income', + # 'role': roles.INCOME_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Expenses (must start with 5 for COGS, 6 for others) + # { + # 'code': '5010', + # 'name': 'Cost of Goods Sold', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '5015', + # 'name': 'Spare Parts Cost Consumed', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6010', + # 'name': 'Salaries & Wages', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6020', + # 'name': 'Rent', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6030', + # 'name': 'Utilities', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6040', + # 'name': 'Advertising & Marketing', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6050', + # 'name': 'Maintenance', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6060', + # 'name': 'Operating Expenses', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6070', + # 'name': 'Depreciation', + # 'role': roles.EXPENSE_DEPRECIATION, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6080', + # 'name': 'Fees & Taxes', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6090', + # 'name': 'Bank Charges', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6100', + # 'name': 'Other Expenses', + # 'role': roles.EXPENSE_OTHER, + # 'balance_type': roles.DEBIT, + # 'locked': False + # } + # ] + accounts_data = [ - # Current Assets - { - 'code': '1010', - 'name': 'Cash on Hand', - 'name_arabic': 'الصندوق', - 'role': roles.ASSET_CA_CASH, - 'balance_type': roles.DEBIT, - 'locked': True - }, - { - 'code': '1020', - 'name': 'Bank', - 'name_arabic': 'البنك', - 'role': roles.ASSET_CA_CASH, - 'balance_type': roles.DEBIT, - 'locked': True - }, - { - 'code': '1030', - 'name': 'Accounts Receivable', - 'name_arabic': 'العملاء', - 'role': roles.ASSET_CA_RECEIVABLES, - 'balance_type': roles.DEBIT, - 'locked': True - }, - { - 'code': '1040', - 'name': 'Inventory (Cars)', - 'name_arabic': 'مخزون السيارات', - 'role': roles.ASSET_CA_INVENTORY, - 'balance_type': roles.DEBIT, - 'locked': True - }, - { - 'code': '1045', - 'name': 'Spare Parts Inventory', - 'name_arabic': 'مخزون قطع الغيار', - 'role': roles.ASSET_CA_INVENTORY, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '1050', - 'name': 'Employee Advances', - 'name_arabic': 'سُلف وأمانات الموظفين', - 'role': roles.ASSET_CA_RECEIVABLES, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '1060', - 'name': 'Prepaid Expenses', - 'name_arabic': 'مصروفات مدفوعة مقدماً', - 'role': roles.ASSET_CA_PREPAID, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '1070', - 'name': 'Notes Receivable', - 'name_arabic': 'أوراق القبض', - 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, - 'balance_type': roles.DEBIT, - 'locked': False - }, + # Current Assets (must start with 1) + { + 'code': '1010', + 'name': 'Cash on Hand', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_CASH + }, + { + 'code': '1020', + 'name': 'Bank', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': False + }, + { + 'code': '1030', + 'name': 'Accounts Receivable', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_RECEIVABLES + }, + { + 'code': '1040', + 'name': 'Inventory (Cars)', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_INVENTORY + }, + { + 'code': '1045', + 'name': 'Spare Parts Inventory', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1050', + 'name': 'Employee Advances', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1060', + 'name': 'Prepaid Expenses', + 'role': roles.ASSET_CA_PREPAID, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_CA_PREPAID + }, + { + 'code': '1070', + 'name': 'Notes Receivable', + 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_NOTES_RECEIVABLE + }, - # Fixed Assets (2000-2999) - { - 'code': '2010', - 'name': 'Lands', - 'name_arabic': 'أراضي', - 'role': roles.ASSET_LTI_LAND, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2011', - 'name': 'Buildings', - 'name_arabic': 'مباني', - 'role': roles.ASSET_PPE_BUILDINGS, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2012', - 'name': 'Company Vehicles', - 'name_arabic': 'سيارات الشركة', - 'role': roles.ASSET_PPE_EQUIPMENT, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2013', - 'name': 'Equipment & Tools', - 'name_arabic': 'أجهزة ومعدات', - 'role': roles.ASSET_PPE_EQUIPMENT, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2014', - 'name': 'Furniture & Fixtures', - 'name_arabic': 'أثاث وديكور', - 'role': roles.ASSET_PPE_EQUIPMENT, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2015', - 'name': 'Other Fixed Assets', - 'name_arabic': 'أصول ثابتة أخرى', - 'role': roles.ASSET_PPE_EQUIPMENT, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2020', - 'name': 'Long-term Investments', - 'name_arabic': 'استثمارات طويلة الأجل', - 'role': roles.ASSET_LTI_SECURITIES, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '2030', - 'name': 'Intangible Assets', - 'name_arabic': 'أصول غير ملموسة', - 'role': roles.ASSET_INTANGIBLE_ASSETS, - 'balance_type': roles.DEBIT, - 'locked': False - }, + # Fixed Assets (must also start with 1) + { + 'code': '1110', + 'name': 'Lands', + 'role': roles.ASSET_LTI_LAND, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_LAND + }, + { + 'code': '1111', + 'name': 'Buildings', + 'role': roles.ASSET_PPE_BUILDINGS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_PPE_BUILDINGS + }, + { + 'code': '1112', + 'name': 'Company Vehicles', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_PPE_EQUIPMENT + }, + { + 'code': '1113', + 'name': 'Equipment & Tools', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1114', + 'name': 'Furniture & Fixtures', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1115', + 'name': 'Other Fixed Assets', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1120', + 'name': 'Long-term Investments', + 'role': roles.ASSET_LTI_SECURITIES, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_SECURITIES + }, + { + 'code': '1130', + 'name': 'Intangible Assets', + 'role': roles.ASSET_INTANGIBLE_ASSETS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_INTANGIBLE_ASSETS + }, - # Current Liabilities (3000-3999) - { - 'code': '3010', - 'name': 'Accounts Payable', - 'name_arabic': 'الموردين', - 'role': roles.LIABILITY_CL_ACC_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': True - }, - { - 'code': '3020', - 'name': 'Notes Payable', - 'name_arabic': 'أوراق الدفع', - 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '3030', - 'name': 'Short-term Loans', - 'name_arabic': 'قروض قصيرة الأجل', - 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '3040', - 'name': 'Employee Payables', - 'name_arabic': 'السلف المستحقة', - 'role': roles.LIABILITY_CL_WAGES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '3050', - 'name': 'Accrued Expenses', - 'name_arabic': 'مصروفات مستحقة', - 'role': roles.LIABILITY_CL_OTHER, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '3060', - 'name': 'Accrued Taxes', - 'name_arabic': 'ضرائب مستحقة', - 'role': roles.LIABILITY_CL_TAXES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '3070', - 'name': 'Provisions', - 'name_arabic': 'مخصصات', - 'role': roles.LIABILITY_CL_OTHER, - 'balance_type': roles.CREDIT, - 'locked': False - }, + # Current Liabilities (must start with 2) + { + 'code': '2010', + 'name': 'Accounts Payable', + 'role': roles.LIABILITY_CL_ACC_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for LIABILITY_CL_ACC_PAYABLE + }, + { + 'code': '2020', + 'name': 'Notes Payable', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_ST_NOTES_PAYABLE + }, + { + 'code': '2030', + 'name': 'Short-term Loans', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '2040', + 'name': 'Employee Payables', + 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_WAGES_PAYABLE + }, + { + 'code': '2050', + 'name': 'Accrued Expenses', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_OTHER + }, + { + 'code': '2060', + 'name': 'Accrued Taxes', + 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_TAXES_PAYABLE + }, + { + 'code': '2070', + 'name': 'Provisions', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, - # Long-term Liabilities (4000-4999) - { - 'code': '4010', - 'name': 'Long-term Bank Loans', - 'name_arabic': 'قروض طويلة الأجل', - 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '4020', - 'name': 'Lease Liabilities', - 'name_arabic': 'التزامات تمويلية', - 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '4030', - 'name': 'Other Long-term Liabilities', - 'name_arabic': 'التزامات أخرى طويلة الأجل', - 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, - 'balance_type': roles.CREDIT, - 'locked': False - }, + # Long-term Liabilities (must also start with 2) + { + 'code': '2210', + 'name': 'Long-term Bank Loans', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_LTL_NOTES_PAYABLE + }, + { + 'code': '2220', + 'name': 'Lease Liabilities', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '2230', + 'name': 'Other Long-term Liabilities', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, - # Equity (5000-5999) - { - 'code': '5010', - 'name': 'Capital', - 'name_arabic': 'رأس المال', - 'role': roles.EQUITY_CAPITAL, - 'balance_type': roles.CREDIT, - 'locked': True - }, - { - 'code': '5020', - 'name': 'Statutory Reserve', - 'name_arabic': 'الاحتياطي القانوني', - 'role': roles.EQUITY_ADJUSTMENT, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '5030', - 'name': 'Retained Earnings', - 'name_arabic': 'احتياطي الأرباح', - 'role': roles.EQUITY_ADJUSTMENT, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '5040', - 'name': 'Profit & Loss for the Period', - 'name_arabic': 'أرباح وخسائر الفترة', - 'role': roles.EQUITY_ADJUSTMENT, - 'balance_type': roles.CREDIT, - 'locked': False - }, + # Equity (must start with 3) + { + 'code': '3010', + 'name': 'Capital', + 'role': roles.EQUITY_CAPITAL, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for EQUITY_CAPITAL + }, + { + 'code': '3020', + 'name': 'Statutory Reserve', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for EQUITY_ADJUSTMENT + }, + { + 'code': '3030', + 'name': 'Retained Earnings', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '3040', + 'name': 'Profit & Loss for the Period', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, - # Revenue (6000-6999) - { - 'code': '6010', - 'name': 'Car Sales', - 'name_arabic': 'مبيعات السيارات', - 'role': roles.INCOME_OPERATIONAL, - 'balance_type': roles.CREDIT, - 'locked': True - }, - { - 'code': '6020', - 'name': 'After-Sales Services', - 'name_arabic': 'إيرادات خدمات ما بعد البيع', - 'role': roles.INCOME_OPERATIONAL, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '6030', - 'name': 'Car Rental Income', - 'name_arabic': 'إيرادات تأجير سيارات', - 'role': roles.INCOME_PASSIVE, - 'balance_type': roles.CREDIT, - 'locked': False - }, - { - 'code': '6040', - 'name': 'Other Income', - 'name_arabic': 'إيرادات أخرى', - 'role': roles.INCOME_OTHER, - 'balance_type': roles.CREDIT, - 'locked': False - }, + # Revenue (must start with 4) + { + 'code': '4010', + 'name': 'Car Sales', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for INCOME_OPERATIONAL + }, + { + 'code': '4020', + 'name': 'After-Sales Services', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '4030', + 'name': 'Car Rental Income', + 'role': roles.INCOME_PASSIVE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for INCOME_PASSIVE + }, + { + 'code': '4040', + 'name': 'Other Income', + 'role': roles.INCOME_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for INCOME_OTHER + }, + + # Expenses (must start with 5 for COGS, 6 for others) + { + 'code': '5010', + 'name': 'Cost of Goods Sold', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for COGS + }, + { + 'code': '5015', + 'name': 'Spare Parts Cost Consumed', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6010', + 'name': 'Salaries & Wages', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_OPERATIONAL + }, + { + 'code': '6020', + 'name': 'Rent', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6030', + 'name': 'Utilities', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6040', + 'name': 'Advertising & Marketing', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6050', + 'name': 'Maintenance', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6060', + 'name': 'Operating Expenses', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6070', + 'name': 'Depreciation', + 'role': roles.EXPENSE_DEPRECIATION, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_DEPRECIATION + }, + { + 'code': '6080', + 'name': 'Fees & Taxes', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6090', + 'name': 'Bank Charges', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6100', + 'name': 'Other Expenses', + 'role': roles.EXPENSE_OTHER, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_OTHER + } + ] - # Expenses (7000-7999) - { - 'code': '7010', - 'name': 'Cost of Goods Sold', - 'name_arabic': 'تكلفة البضاعة المباعة', - 'role': roles.COGS, - 'balance_type': roles.DEBIT, - 'locked': True - }, - { - 'code': '7015', - 'name': 'Spare Parts Cost Consumed', - 'name_arabic': 'تكلفة قطع الغيار المستهلكة', - 'role': roles.COGS, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7020', - 'name': 'Salaries & Wages', - 'name_arabic': 'رواتب وأجور', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7030', - 'name': 'Rent', - 'name_arabic': 'إيجار', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7040', - 'name': 'Utilities', - 'name_arabic': 'كهرباء ومياه', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7050', - 'name': 'Advertising & Marketing', - 'name_arabic': 'دعاية وإعلان', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7060', - 'name': 'Maintenance', - 'name_arabic': 'صيانة', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7070', - 'name': 'Operating Expenses', - 'name_arabic': 'مصاريف تشغيلية', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7080', - 'name': 'Depreciation', - 'name_arabic': 'استهلاك أصول ثابتة', - 'role': roles.EXPENSE_DEPRECIATION, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7090', - 'name': 'Fees & Taxes', - 'name_arabic': 'رسوم وضرائب', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7100', - 'name': 'Bank Charges', - 'name_arabic': 'مصاريف بنكية', - 'role': roles.EXPENSE_OPERATIONAL, - 'balance_type': roles.DEBIT, - 'locked': False - }, - { - 'code': '7110', - 'name': 'Other Expenses', - 'name_arabic': 'مصاريف أخرى', - 'role': roles.EXPENSE_OTHER, - 'balance_type': roles.DEBIT, - 'locked': False - } - ] - # Create accounts created_accounts = [] for account_data in accounts_data: @@ -418,6 +1527,8 @@ class Command(BaseCommand): balance_type=_(account_data['balance_type']), active=True ) + account.role_default = account_data['default'] + account.save() created_accounts.append(account) self.stdout.write(self.style.SUCCESS( f"Created account: {account.code} - {account.name}" @@ -430,4 +1541,3 @@ class Command(BaseCommand): self.stdout.write(self.style.SUCCESS( f"\nSuccessfully created {len(created_accounts)} accounts in Chart of Accounts" )) - return coa_model, created_accounts \ No newline at end of file diff --git a/inventory/tasks.py b/inventory/tasks.py index ee9ee7b2..821f3e44 100644 --- a/inventory/tasks.py +++ b/inventory/tasks.py @@ -25,6 +25,750 @@ def create_settings(pk): @background def create_coa_accounts(pk): + with transaction.atomic(): + instance = Dealer.objects.select_for_update().get(pk=pk) + entity = instance.entity + coa = entity.get_default_coa() + + # accounts_data = [ + # # Current Assets (must start with 1) + # { + # 'code': '1010', + # 'name': 'Cash on Hand', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True, + # }, + # { + # 'code': '1020', + # 'name': 'Bank', + # 'role': roles.ASSET_CA_CASH, + # 'balance_type': roles.DEBIT, + # 'locked': True, + # }, + # { + # 'code': '1030', + # 'name': 'Accounts Receivable', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1040', + # 'name': 'Inventory (Cars)', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '1045', + # 'name': 'Spare Parts Inventory', + # 'role': roles.ASSET_CA_INVENTORY, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1050', + # 'name': 'Employee Advances', + # 'role': roles.ASSET_CA_RECEIVABLES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1060', + # 'name': 'Prepaid Expenses', + # 'role': roles.ASSET_CA_PREPAID, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1070', + # 'name': 'Notes Receivable', + # 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Fixed Assets (must also start with 1) + # { + # 'code': '1110', + # 'name': 'Lands', + # 'role': roles.ASSET_LTI_LAND, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1111', + # 'name': 'Buildings', + # 'role': roles.ASSET_PPE_BUILDINGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1112', + # 'name': 'Company Vehicles', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1113', + # 'name': 'Equipment & Tools', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1114', + # 'name': 'Furniture & Fixtures', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1115', + # 'name': 'Other Fixed Assets', + # 'role': roles.ASSET_PPE_EQUIPMENT, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1120', + # 'name': 'Long-term Investments', + # 'role': roles.ASSET_LTI_SECURITIES, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '1130', + # 'name': 'Intangible Assets', + # 'role': roles.ASSET_INTANGIBLE_ASSETS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + + # # Current Liabilities (must start with 2) + # { + # 'code': '2010', + # 'name': 'Accounts Payable', + # 'role': roles.LIABILITY_CL_ACC_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '2020', + # 'name': 'Notes Payable', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2030', + # 'name': 'Short-term Loans', + # 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2040', + # 'name': 'Employee Payables', + # 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2050', + # 'name': 'Accrued Expenses', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2060', + # 'name': 'Accrued Taxes', + # 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2070', + # 'name': 'Provisions', + # 'role': roles.LIABILITY_CL_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Long-term Liabilities (must also start with 2) + # { + # 'code': '2210', + # 'name': 'Long-term Bank Loans', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2220', + # 'name': 'Lease Liabilities', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '2230', + # 'name': 'Other Long-term Liabilities', + # 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Equity (must start with 3) + # { + # 'code': '3010', + # 'name': 'Capital', + # 'role': roles.EQUITY_CAPITAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '3020', + # 'name': 'Statutory Reserve', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3030', + # 'name': 'Retained Earnings', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '3040', + # 'name': 'Profit & Loss for the Period', + # 'role': roles.EQUITY_ADJUSTMENT, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Revenue (must start with 4) + # { + # 'code': '4010', + # 'name': 'Car Sales', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': True + # }, + # { + # 'code': '4020', + # 'name': 'After-Sales Services', + # 'role': roles.INCOME_OPERATIONAL, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4030', + # 'name': 'Car Rental Income', + # 'role': roles.INCOME_PASSIVE, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + # { + # 'code': '4040', + # 'name': 'Other Income', + # 'role': roles.INCOME_OTHER, + # 'balance_type': roles.CREDIT, + # 'locked': False + # }, + + # # Expenses (must start with 5 for COGS, 6 for others) + # { + # 'code': '5010', + # 'name': 'Cost of Goods Sold', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': True + # }, + # { + # 'code': '5015', + # 'name': 'Spare Parts Cost Consumed', + # 'role': roles.COGS, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6010', + # 'name': 'Salaries & Wages', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6020', + # 'name': 'Rent', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6030', + # 'name': 'Utilities', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6040', + # 'name': 'Advertising & Marketing', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6050', + # 'name': 'Maintenance', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6060', + # 'name': 'Operating Expenses', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6070', + # 'name': 'Depreciation', + # 'role': roles.EXPENSE_DEPRECIATION, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6080', + # 'name': 'Fees & Taxes', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6090', + # 'name': 'Bank Charges', + # 'role': roles.EXPENSE_OPERATIONAL, + # 'balance_type': roles.DEBIT, + # 'locked': False + # }, + # { + # 'code': '6100', + # 'name': 'Other Expenses', + # 'role': roles.EXPENSE_OTHER, + # 'balance_type': roles.DEBIT, + # 'locked': False + # } + # ] + + accounts_data = [ + # Current Assets (must start with 1) + { + 'code': '1010', + 'name': 'Cash on Hand', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_CASH + }, + { + 'code': '1020', + 'name': 'Bank', + 'role': roles.ASSET_CA_CASH, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': False + }, + { + 'code': '1030', + 'name': 'Accounts Receivable', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_RECEIVABLES + }, + { + 'code': '1040', + 'name': 'Inventory (Cars)', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for ASSET_CA_INVENTORY + }, + { + 'code': '1045', + 'name': 'Spare Parts Inventory', + 'role': roles.ASSET_CA_INVENTORY, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1050', + 'name': 'Employee Advances', + 'role': roles.ASSET_CA_RECEIVABLES, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1060', + 'name': 'Prepaid Expenses', + 'role': roles.ASSET_CA_PREPAID, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_CA_PREPAID + }, + { + 'code': '1070', + 'name': 'Notes Receivable', + 'role': roles.ASSET_LTI_NOTES_RECEIVABLE, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_NOTES_RECEIVABLE + }, + + # Fixed Assets (must also start with 1) + { + 'code': '1110', + 'name': 'Lands', + 'role': roles.ASSET_LTI_LAND, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_LAND + }, + { + 'code': '1111', + 'name': 'Buildings', + 'role': roles.ASSET_PPE_BUILDINGS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_PPE_BUILDINGS + }, + { + 'code': '1112', + 'name': 'Company Vehicles', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_PPE_EQUIPMENT + }, + { + 'code': '1113', + 'name': 'Equipment & Tools', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1114', + 'name': 'Furniture & Fixtures', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1115', + 'name': 'Other Fixed Assets', + 'role': roles.ASSET_PPE_EQUIPMENT, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '1120', + 'name': 'Long-term Investments', + 'role': roles.ASSET_LTI_SECURITIES, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_LTI_SECURITIES + }, + { + 'code': '1130', + 'name': 'Intangible Assets', + 'role': roles.ASSET_INTANGIBLE_ASSETS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for ASSET_INTANGIBLE_ASSETS + }, + + # Current Liabilities (must start with 2) + { + 'code': '2010', + 'name': 'Accounts Payable', + 'role': roles.LIABILITY_CL_ACC_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for LIABILITY_CL_ACC_PAYABLE + }, + { + 'code': '2020', + 'name': 'Notes Payable', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_ST_NOTES_PAYABLE + }, + { + 'code': '2030', + 'name': 'Short-term Loans', + 'role': roles.LIABILITY_CL_ST_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '2040', + 'name': 'Employee Payables', + 'role': roles.LIABILITY_CL_WAGES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_WAGES_PAYABLE + }, + { + 'code': '2050', + 'name': 'Accrued Expenses', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_OTHER + }, + { + 'code': '2060', + 'name': 'Accrued Taxes', + 'role': roles.LIABILITY_CL_TAXES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_CL_TAXES_PAYABLE + }, + { + 'code': '2070', + 'name': 'Provisions', + 'role': roles.LIABILITY_CL_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + + # Long-term Liabilities (must also start with 2) + { + 'code': '2210', + 'name': 'Long-term Bank Loans', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for LIABILITY_LTL_NOTES_PAYABLE + }, + { + 'code': '2220', + 'name': 'Lease Liabilities', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '2230', + 'name': 'Other Long-term Liabilities', + 'role': roles.LIABILITY_LTL_NOTES_PAYABLE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + + # Equity (must start with 3) + { + 'code': '3010', + 'name': 'Capital', + 'role': roles.EQUITY_CAPITAL, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for EQUITY_CAPITAL + }, + { + 'code': '3020', + 'name': 'Statutory Reserve', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for EQUITY_ADJUSTMENT + }, + { + 'code': '3030', + 'name': 'Retained Earnings', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '3040', + 'name': 'Profit & Loss for the Period', + 'role': roles.EQUITY_ADJUSTMENT, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + + # Revenue (must start with 4) + { + 'code': '4010', + 'name': 'Car Sales', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': True, + 'default': True # Default for INCOME_OPERATIONAL + }, + { + 'code': '4020', + 'name': 'After-Sales Services', + 'role': roles.INCOME_OPERATIONAL, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': False + }, + { + 'code': '4030', + 'name': 'Car Rental Income', + 'role': roles.INCOME_PASSIVE, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for INCOME_PASSIVE + }, + { + 'code': '4040', + 'name': 'Other Income', + 'role': roles.INCOME_OTHER, + 'balance_type': roles.CREDIT, + 'locked': False, + 'default': True # Default for INCOME_OTHER + }, + + # Expenses (must start with 5 for COGS, 6 for others) + { + 'code': '5010', + 'name': 'Cost of Goods Sold', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': True, + 'default': True # Default for COGS + }, + { + 'code': '5015', + 'name': 'Spare Parts Cost Consumed', + 'role': roles.COGS, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6010', + 'name': 'Salaries & Wages', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_OPERATIONAL + }, + { + 'code': '6020', + 'name': 'Rent', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6030', + 'name': 'Utilities', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6040', + 'name': 'Advertising & Marketing', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6050', + 'name': 'Maintenance', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6060', + 'name': 'Operating Expenses', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6070', + 'name': 'Depreciation', + 'role': roles.EXPENSE_DEPRECIATION, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_DEPRECIATION + }, + { + 'code': '6080', + 'name': 'Fees & Taxes', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6090', + 'name': 'Bank Charges', + 'role': roles.EXPENSE_OPERATIONAL, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': False + }, + { + 'code': '6100', + 'name': 'Other Expenses', + 'role': roles.EXPENSE_OTHER, + 'balance_type': roles.DEBIT, + 'locked': False, + 'default': True # Default for EXPENSE_OTHER + } + ] + + for account_data in accounts_data: + try: + account = entity.create_account( + coa_model=coa, + code=account_data['code'], + name=_(account_data['name']), + role=_(account_data['role']), + balance_type=_(account_data['balance_type']), + active=True + ) + account.role_default = account_data['default'] + account.save() + except Exception as e: + print(e) + +@background +def create_coa_accounts1(pk): with transaction.atomic(): instance = Dealer.objects.select_for_update().get(pk=pk) entity = instance.entity diff --git a/inventory/templatetags/custom_filters.py b/inventory/templatetags/custom_filters.py index 85906f9f..5d4283f1 100644 --- a/inventory/templatetags/custom_filters.py +++ b/inventory/templatetags/custom_filters.py @@ -129,7 +129,7 @@ def period_navigation(context, base_url: str): def balance_sheet_statement(context, io_model, to_date=None): user_model = context['user'] activity = context['request'].GET.get('activity') - entity_slug = context['view'].kwargs.get('entity_slug') + entity_slug = context['view'].kwargs.get('entity_slug') if not to_date: to_date = context['to_date'] @@ -358,4 +358,9 @@ def splitlines(value): def currency_format(value): if not value: value = 0.00 - return number_format(value, decimal_pos=2, use_l10n=True, force_grouping=True) \ No newline at end of file + return number_format(value, decimal_pos=2, use_l10n=True, force_grouping=True) + + +@register.filter +def filter_by_role(accounts, role_prefix): + return [account for account in accounts if account.role.startswith(role_prefix)] \ No newline at end of file diff --git a/inventory/views.py b/inventory/views.py index efe9b285..a406d635 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -4823,6 +4823,7 @@ class LeadDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): lead=self.object ) context["transfer_form"] = forms.LeadTransferForm() + context["transfer_form"].fields["transfer_to"].queryset = (models.Staff.objects.filter(dealer=self.object.dealer,staff_type="sales")) context["activity_form"] = forms.ActivityForm() context["staff_task_form"] = forms.StaffTaskForm() context["note_form"] = forms.NoteForm() diff --git a/templates/ledger/coa_accounts/account_list.html b/templates/ledger/coa_accounts/account_list.html index 857af6e1..d4229287 100644 --- a/templates/ledger/coa_accounts/account_list.html +++ b/templates/ledger/coa_accounts/account_list.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n %} +{% load i18n custom_filters %} {% block title %}{% trans "Accounts" %}{% endblock title %} {% block accounts %} @@ -8,120 +8,137 @@ {% endblock %} {% block content %} -

    {% trans "Accounts" %}

    {% trans 'New Account' %}
    - {% include "partials/search_box.html" %} - {% if page_obj.object_list %} -
    - - - - - - - - - - - - - {% for account in accounts %} + +
    + - + +
    + {% include "partials/search_box.html" %} + {% with accounts=accounts|filter_by_role:"eq_" %} + {% include "ledger/coa_accounts/partials/account_table.html" %} + {% endwith %} +
    -
    - - - - - - - - {% empty %} - - - - {% endfor %} - -
    {% trans "Type" %}{% trans "Account Name" %}{% trans "Code" %}{% trans "Balance Type" %}{% trans "Active" %}
    - {{ account.role_bs|upper }} - - {{ account.name }} - - {{ account.code }} - + +
    + {% include "partials/search_box.html" %} + {% with accounts=accounts|filter_by_role:"in_" %} + {% include "ledger/coa_accounts/partials/account_table.html" %} + {% endwith %} +
    - {% if account.balance_type == 'debit' %} -
    {{ _("Debit") }}
    - {% else %} -
    {{ _("Credit") }}
    - {% endif %} -
    - {% if account.active %} - - {% else %} - - {% endif %} - -
    - - -
    -
    {% trans "No Accounts Found" %}
    + +
    + {% include "partials/search_box.html" %} + {% with accounts=accounts|filter_by_role:"ex_" %} + {% include "ledger/coa_accounts/partials/account_table.html" %} + {% endwith %} +
    + +
    + {% include "partials/search_box.html" %} + {% with accounts=accounts|filter_by_role:"lia_" %} + {% include "ledger/coa_accounts/partials/account_table.html" %} + {% endwith %} +
    +
    -
    -
    - {% if is_paginated %} - {% include 'partials/pagination.html' %} - {% endif %} -
    -
    - {% endif %} -
    - + + {% endblock %} - +{% block customerJS %} + +{% endblock %} \ No newline at end of file diff --git a/templates/ledger/coa_accounts/partials/account_table.html b/templates/ledger/coa_accounts/partials/account_table.html new file mode 100644 index 00000000..48e95c68 --- /dev/null +++ b/templates/ledger/coa_accounts/partials/account_table.html @@ -0,0 +1,69 @@ +{% load i18n %} +{% if accounts %} +
    + + + + + + + + + + + + {% for account in accounts %} + + + + + + + + {% empty %} + + + + {% endfor %} + +
    {% trans "Account Name" %}{% trans "Code" %}{% trans "Balance Type" %}{% trans "Active" %}
    + {{ account.name }} + + {{ account.code }} + + {% if account.balance_type == 'debit' %} +
    {{ _("Debit") }}
    + {% else %} +
    {{ _("Credit") }}
    + {% endif %} +
    + {% if account.active %} + + {% else %} + + {% endif %} + +
    + + +
    +
    {% trans "No Accounts Found" %}
    +
    +
    +
    + {% if is_paginated %} + {% include 'partials/pagination.html' %} + {% endif %} +
    +
    +{% else %} +
    + {% trans "No accounts found in this category." %} +
    +{% endif %} \ No newline at end of file