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