38086-vm/core/views.py
2026-02-09 18:51:27 +00:00

223 lines
6.6 KiB
Python

# Force reload of views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.http import JsonResponse, HttpResponse
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from django.db import transaction, models
from django.db.models import Sum, Count, F, Q
from django.utils import timezone
from django.core.paginator import Paginator
from django.utils.text import slugify
import json
import decimal
import datetime
from datetime import timedelta
from .models import *
from .forms import *
from .helpers import number_to_words_en
from .views_import import import_categories, import_suppliers, import_products
# ==========================================
# Debug Index View with AUTO-FIX
# ==========================================
@login_required
def index(request):
from django.db import connection
messages = []
# 1. Attempt to FIX the missing column
try:
with connection.cursor() as cursor:
# Check if column exists
cursor.execute("SHOW COLUMNS FROM core_product LIKE 'is_service'")
result = cursor.fetchone()
if not result:
messages.append("Column 'is_service' missing. Attempting to add...")
cursor.execute("ALTER TABLE core_product ADD COLUMN is_service tinyint(1) NOT NULL DEFAULT 0")
messages.append("SUCCESS: Column 'is_service' added manually.")
else:
messages.append("Column 'is_service' already exists.")
# Check if migration is recorded
cursor.execute("SELECT applied FROM django_migrations WHERE app='core' AND name='0032_product_is_service'")
mig = cursor.fetchone()
if not mig:
messages.append("Migration 0032 NOT recorded. (You might need to fake it later)")
else:
messages.append(f"Migration 0032 recorded at {mig[0]}")
except Exception as e:
messages.append(f"CRITICAL ERROR during fix: {str(e)}")
# 2. Show Debug Info
try:
with connection.cursor() as cursor:
cursor.execute("SELECT app, name, applied FROM django_migrations WHERE app='core' ORDER BY id DESC LIMIT 10")
migrations = cursor.fetchall()
cursor.execute("DESCRIBE core_product")
columns = cursor.fetchall()
html = f"""
<html><body>
<h1>Migration Auto-Fixer</h1>
<div style="background: #f0f0f0; padding: 10px; border: 1px solid #ccc;">
<h3>Log:</h3>
<ul>
{''.join(f'<li>{m}</li>' for m in messages)}
</ul>
</div>
<h2>Migrations (Last 10)</h2><pre>{migrations}</pre>
<h2>Product Columns</h2><pre>{columns}</pre>
</body></html>
"""
return HttpResponse(html)
except Exception as e:
return HttpResponse(f"Error during debug display: {str(e)}")
def dashboard_data(request):
return JsonResponse({'labels': [], 'data': []})
# ==========================================
# Stubs to prevent crashes
# ==========================================
def stub_view(request, *args, **kwargs):
return HttpResponse("This view is currently being restored. Please check back later.")
def stub_api(request, *args, **kwargs):
return JsonResponse({'success': False, 'message': 'Endpoint under maintenance'})
# Map all missing views to stubs
inventory = stub_view
pos = stub_view
customer_display = stub_view
customers = stub_view
suppliers = stub_view
purchases = stub_view
reports = stub_view
customer_statement = stub_view
supplier_statement = stub_view
cashflow_report = stub_view
settings_view = stub_view
profile_view = stub_view
user_management = stub_view
group_details_api = stub_api
invoice_list = stub_view
invoice_create = stub_view
invoice_detail = stub_view
add_sale_payment = stub_view
delete_sale = stub_view
customer_payments = stub_view
customer_payment_receipt = stub_view
sale_receipt = stub_view
edit_invoice = stub_view
quotations = stub_view
quotation_create = stub_view
quotation_detail = stub_view
convert_quotation_to_invoice = stub_view
delete_quotation = stub_view
create_quotation_api = stub_api
sales_returns = stub_view
sale_return_create = stub_view
sale_return_detail = stub_view
delete_sale_return = stub_view
create_sale_return_api = stub_api
purchase_create = stub_view
purchase_detail = stub_view
edit_purchase = stub_view
add_purchase_payment = stub_view
delete_purchase = stub_view
supplier_payments = stub_view
purchase_returns = stub_view
purchase_return_create = stub_view
purchase_return_detail = stub_view
delete_purchase_return = stub_view
create_purchase_return_api = stub_api
expenses_view = stub_view
expense_create_view = stub_view
expense_edit_view = stub_view
expense_delete_view = stub_view
expense_categories_view = stub_view
expense_category_delete_view = stub_view
expense_report = stub_view
export_expenses_excel = stub_view
pos_sync_update = stub_api
pos_sync_state = stub_api
create_sale_api = stub_api
update_sale_api = stub_api
create_purchase_api = stub_api
update_purchase_api = stub_api
hold_sale_api = stub_api
get_held_sales_api = stub_api
recall_held_sale_api = stub_api
delete_held_sale_api = stub_api
add_customer = stub_view
edit_customer = stub_view
delete_customer = stub_view
add_customer_ajax = stub_api
search_customers_api = stub_api
add_supplier = stub_view
edit_supplier = stub_view
delete_supplier = stub_view
add_supplier_ajax = stub_api
suggest_sku = stub_api
add_product = stub_view
edit_product = stub_view
delete_product = stub_view
barcode_labels = stub_view
add_category = stub_view
edit_category = stub_view
delete_category = stub_view
add_category_ajax = stub_api
add_unit = stub_view
edit_unit = stub_view
delete_unit = stub_view
add_unit_ajax = stub_api
add_payment_method = stub_view
edit_payment_method = stub_view
delete_payment_method = stub_view
add_payment_method_ajax = stub_api
add_loyalty_tier = stub_view
edit_loyalty_tier = stub_view
delete_loyalty_tier = stub_view
get_customer_loyalty_api = stub_api
send_invoice_whatsapp = stub_api
test_whatsapp_connection = stub_api
add_device = stub_view
edit_device = stub_view
delete_device = stub_view
lpo_list = stub_view
lpo_create = stub_view
lpo_detail = stub_view
convert_lpo_to_purchase = stub_view
lpo_delete = stub_view
create_lpo_api = stub_api
cashier_registry = stub_view
cashier_session_list = stub_view
start_session = stub_view
close_session = stub_view
session_detail = stub_view