add main controller for dine360 dashboard and SaaS management
This commit is contained in:
parent
6daa038bd4
commit
1af74bd16b
@ -71,39 +71,62 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning("Error fetching saas.plan: %s", e)
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if is_saas_master and 'saas.restaurant' in request.env:
|
||||
try:
|
||||
records = request.env['saas.restaurant'].sudo().search([], order='id desc')
|
||||
saas_stats['total'] = len(records)
|
||||
for r in records:
|
||||
if r.status == 'active':
|
||||
needed_fields = [
|
||||
'id', 'name', 'owner_name', 'email', 'phone', 'city',
|
||||
'database_name', 'subdomain', 'status', 'plan_id',
|
||||
'billing_cycle', 'start_date', 'expiry_date'
|
||||
]
|
||||
fields_to_read = [f for f in needed_fields if f in request.env['saas.restaurant']._fields]
|
||||
raw_data = records.read(fields_to_read)
|
||||
|
||||
for r_data in raw_data:
|
||||
st = r_data.get('status') or 'active'
|
||||
if st == 'active':
|
||||
saas_stats['active'] += 1
|
||||
elif r.status == 'provisioning':
|
||||
elif st == 'provisioning':
|
||||
saas_stats['provisioning'] += 1
|
||||
elif r.status in ('expired', 'suspended', 'failed'):
|
||||
elif st in ('expired', 'suspended', 'failed'):
|
||||
saas_stats['expired'] += 1
|
||||
|
||||
expiry_fmt = r.expiry_date.strftime('%d %b %Y') if r.expiry_date else 'N/A'
|
||||
exp_date = r_data.get('expiry_date')
|
||||
expiry_fmt = exp_date.strftime('%d %b %Y') if hasattr(exp_date, 'strftime') else (str(exp_date) if exp_date else 'N/A')
|
||||
plan_val = r_data.get('plan_id')
|
||||
plan_name = plan_val[1] if isinstance(plan_val, (list, tuple)) and len(plan_val) > 1 else 'Standard'
|
||||
r_id = r_data.get('id')
|
||||
db_name_val = r_data.get('database_name') or ''
|
||||
|
||||
onboarded_restaurants.append({
|
||||
'id': r.id,
|
||||
'name': r.name,
|
||||
'owner_name': r.owner_name or 'Admin',
|
||||
'email': r.email or '',
|
||||
'phone': r.phone or '',
|
||||
'city': r.city or '',
|
||||
'database_name': r.database_name or '',
|
||||
'subdomain': r.subdomain or '',
|
||||
'status': r.status or 'active',
|
||||
'plan_name': r.plan_id.name if r.plan_id else 'Standard',
|
||||
'billing_cycle': 'Monthly' if r.billing_cycle == 'monthly' else 'Annual',
|
||||
'start_date': str(r.start_date) if r.start_date else '',
|
||||
'id': r_id,
|
||||
'name': r_data.get('name') or '',
|
||||
'owner_name': r_data.get('owner_name') or 'Admin',
|
||||
'email': r_data.get('email') or '',
|
||||
'phone': r_data.get('phone') or '',
|
||||
'city': r_data.get('city') or '',
|
||||
'database_name': db_name_val,
|
||||
'subdomain': r_data.get('subdomain') or '',
|
||||
'status': st,
|
||||
'plan_name': plan_name,
|
||||
'billing_cycle': 'Monthly' if r_data.get('billing_cycle') == 'monthly' else 'Annual',
|
||||
'start_date': str(r_data.get('start_date') or ''),
|
||||
'expiry_date': expiry_fmt,
|
||||
'launch_url': f"/web/login?db={r.database_name}" if r.database_name else '#',
|
||||
'manage_url': f"/web#id={r.id}&model=saas.restaurant&view_type=form",
|
||||
'launch_url': f"/web/login?db={db_name_val}" if db_name_val else '#',
|
||||
'manage_url': f"/web#id={r_id}&model=saas.restaurant&view_type=form",
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning("Error fetching SaaS restaurants: %s", e)
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
first_res = onboarded_restaurants[0] if onboarded_restaurants else None
|
||||
|
||||
@ -116,7 +139,10 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
try:
|
||||
res_count = request.env['restaurant.reservation'].sudo().search_count([])
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
orders_count = 0
|
||||
total_sales = 0.0
|
||||
@ -126,31 +152,44 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
orders_count += len(orders)
|
||||
total_sales += sum(orders.mapped('amount_total'))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
if 'pos.order' in request.env:
|
||||
try:
|
||||
pos_orders = request.env['pos.order'].sudo().search([])
|
||||
orders_count += len(pos_orders)
|
||||
total_sales += sum(pos_orders.mapped('amount_total'))
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
avg_val = (total_sales / orders_count) if orders_count else 0.0
|
||||
|
||||
recent_activities = []
|
||||
if is_saas_master and 'saas.restaurant' in request.env:
|
||||
try:
|
||||
for r in request.env['saas.restaurant'].sudo().search([], order='create_date desc', limit=5):
|
||||
records = request.env['saas.restaurant'].sudo().search([], order='create_date desc', limit=5)
|
||||
for r_data in records.read(['id', 'name', 'database_name', 'status', 'create_date']):
|
||||
st = r_data.get('status') or 'active'
|
||||
c_date = r_data.get('create_date')
|
||||
time_str = c_date.strftime('%d %b, %H:%M') if hasattr(c_date, 'strftime') else (str(c_date) if c_date else '')
|
||||
recent_activities.append({
|
||||
'title': f"Restaurant {r.status.capitalize() if r.status else 'Registered'}",
|
||||
'subtitle': f"{r.name} ({r.database_name or 'N/A'})",
|
||||
'time': r.create_date.strftime('%d %b, %H:%M') if getattr(r, 'create_date', False) else '',
|
||||
'badge': (r.status or 'active').capitalize(),
|
||||
'badge_type': 'completed' if r.status == 'active' else 'info',
|
||||
'title': f"Restaurant {st.capitalize() if st else 'Registered'}",
|
||||
'subtitle': f"{r_data.get('name')} ({r_data.get('database_name') or 'N/A'})",
|
||||
'time': time_str,
|
||||
'badge': (st or 'active').capitalize(),
|
||||
'badge_type': 'completed' if st == 'active' else 'info',
|
||||
'icon': 'fa fa-cutlery'
|
||||
})
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tot_restaurants = saas_stats.get('total', 0)
|
||||
act_restaurants = saas_stats.get('active', 0)
|
||||
@ -182,7 +221,10 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
'table_count': t_count,
|
||||
})
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if 'restaurant.table' in request.env:
|
||||
try:
|
||||
@ -210,6 +252,10 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
table_stats['capacity'] = total_seats
|
||||
except Exception as e:
|
||||
_logger.warning("Error fetching restaurant.table: %s", e)
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 3. Reservations Data
|
||||
reservations_list = []
|
||||
@ -251,6 +297,10 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
})
|
||||
except Exception as e:
|
||||
_logger.warning("Error fetching reservations: %s", e)
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 4. Online Orders Data
|
||||
online_orders_data = {
|
||||
@ -314,6 +364,10 @@ def get_dashboard_context(active_page='dashboard'):
|
||||
online_orders_data['orders'] = orders_list
|
||||
except Exception as e:
|
||||
_logger.warning("Error fetching sale.order: %s", e)
|
||||
try:
|
||||
request.env.cr.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 5. Backups Data
|
||||
backups_list = []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user