From 4a31f0d9f341f9ca90c10553ea5aabbca0b5e99f Mon Sep 17 00:00:00 2001 From: Alaguraj0361 Date: Wed, 8 Jul 2026 10:51:08 +0530 Subject: [PATCH] implement async restaurant database provisioning model with background worker and automated setup process --- .../models/saas_restaurant.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/dine360_saas_master/models/saas_restaurant.py b/addons/dine360_saas_master/models/saas_restaurant.py index 53aee02..09613e7 100644 --- a/addons/dine360_saas_master/models/saas_restaurant.py +++ b/addons/dine360_saas_master/models/saas_restaurant.py @@ -68,6 +68,16 @@ def _async_provisioning_worker(parent_db, saas_res_id, db_name, modules, company source_ref=template, subtype_xmlid='mail.mt_comment' ) + + # Send real-time bus notification to the backend UI to refresh the form view + try: + env['bus.bus']._sendone('saas_provisioning', 'saas_provisioning', { + 'saas_record_id': saas_record.id, + 'status': 'active' + }) + except Exception as bus_err: + _logger.error(f"Failed to send success bus notification: {str(bus_err)}") + cr.commit() _logger.info(f"Background thread: Async provisioning finished successfully for {db_name}!") @@ -88,6 +98,16 @@ def _async_provisioning_worker(parent_db, saas_res_id, db_name, modules, company saas_record = env['saas.restaurant'].browse(saas_res_id) saas_record.write({'status': 'failed'}) saas_record.message_post(body=f"Failed background database provisioning: {str(e)}") + + # Send real-time bus notification to the backend UI to refresh the form view + try: + env['bus.bus']._sendone('saas_provisioning', 'saas_provisioning', { + 'saas_record_id': saas_record.id, + 'status': 'failed' + }) + except Exception as bus_err: + _logger.error(f"Failed to send failure bus notification: {str(bus_err)}") + cr.commit() except Exception as update_err: _logger.error(f"Background thread: Failed to mark status as failed on SaaS record: {str(update_err)}") @@ -225,7 +245,7 @@ class SaasRestaurant(models.Model): 'title': 'Database Provisioning Started', 'message': 'Your database creation has started in the background. Please wait 1-2 minutes for completion before logging in.', 'sticky': False, - 'next': {'type': 'ir.actions.act_window_close'}, + 'next': {'type': 'ir.actions.client', 'tag': 'reload'}, } }