From 1c560c6df2c319d7895ee1cb5bac177918043134 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Thu, 2 Apr 2026 17:55:32 -0400 Subject: [PATCH] changes --- .../fusion_woocommerce/models/woo_sync_log.py | 56 +++++++++++++++++-- .../static/src/css/woo_styles.css | 3 + .../static/src/js/dashboard.js | 13 ++++- .../static/src/xml/dashboard.xml | 11 +++- .../views/woo_sync_log_views.xml | 12 +++- 5 files changed, 87 insertions(+), 8 deletions(-) diff --git a/fusion-woo-odoo/fusion_woocommerce/models/woo_sync_log.py b/fusion-woo-odoo/fusion_woocommerce/models/woo_sync_log.py index 39ccadd8..aa64f480 100644 --- a/fusion-woo-odoo/fusion_woocommerce/models/woo_sync_log.py +++ b/fusion-woo-odoo/fusion_woocommerce/models/woo_sync_log.py @@ -1,5 +1,12 @@ +import logging + from odoo import api, fields, models +_logger = logging.getLogger(__name__) + +SUCCESS_RETENTION_DAYS = 30 +ERROR_RETENTION_DAYS = 90 + class WooSyncLog(models.Model): _name = 'woo.sync.log' @@ -32,11 +39,50 @@ class WooSyncLog(models.Model): @api.model def _cron_cleanup_logs(self): - """Purge sync logs older than 90 days (180 for errors).""" - cutoff_success = fields.Datetime.subtract(fields.Datetime.now(), hours=90 * 24) - cutoff_error = fields.Datetime.subtract(fields.Datetime.now(), hours=180 * 24) - self.search([ + """Purge success/conflict logs older than 30 days, errors older than 90.""" + now = fields.Datetime.now() + cutoff_success = fields.Datetime.subtract(now, days=SUCCESS_RETENTION_DAYS) + cutoff_error = fields.Datetime.subtract(now, days=ERROR_RETENTION_DAYS) + logs = self.search([ '|', '&', ('state', '!=', 'failed'), ('create_date', '<', cutoff_success), '&', ('state', '=', 'failed'), ('create_date', '<', cutoff_error), - ]).unlink() + ]) + count = len(logs) + if count: + logs.unlink() + _logger.info("WooCommerce: purged %d old sync log entries", count) + + def action_purge_old_logs(self): + """Manual purge: delete success logs > 7 days, error logs > 30 days.""" + self.env['woo.sync.log'].check_access_rights('unlink') + now = fields.Datetime.now() + cutoff_success = fields.Datetime.subtract(now, days=7) + cutoff_error = fields.Datetime.subtract(now, days=30) + logs = self.env['woo.sync.log'].search([ + '|', + '&', ('state', '!=', 'failed'), ('create_date', '<', cutoff_success), + '&', ('state', '=', 'failed'), ('create_date', '<', cutoff_error), + ]) + count = len(logs) + logs.unlink() + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': 'Sync Logs Purged', + 'message': f'{count} old log entries deleted.', + 'type': 'success', + 'next': {'type': 'ir.actions.act_window_close'}, + }, + } + + @api.model + def action_clear_errors(self): + """Clear all failed sync log entries. Called from dashboard.""" + self.check_access_rights('unlink') + logs = self.search([('state', '=', 'failed')]) + count = len(logs) + logs.unlink() + _logger.info("WooCommerce: manually cleared %d error log entries", count) + return count diff --git a/fusion-woo-odoo/fusion_woocommerce/static/src/css/woo_styles.css b/fusion-woo-odoo/fusion_woocommerce/static/src/css/woo_styles.css index 51cc58eb..650693a9 100644 --- a/fusion-woo-odoo/fusion_woocommerce/static/src/css/woo_styles.css +++ b/fusion-woo-odoo/fusion_woocommerce/static/src/css/woo_styles.css @@ -406,3 +406,6 @@ outline: none; } .woo-edit-input-text { text-align: left; width: 120px; } + +/* Clear errors button inside dashboard card */ +.woo-clear-btn { font-size: 0.72rem; padding: 1px 8px; } diff --git a/fusion-woo-odoo/fusion_woocommerce/static/src/js/dashboard.js b/fusion-woo-odoo/fusion_woocommerce/static/src/js/dashboard.js index 712cf82e..68d8cb5f 100644 --- a/fusion-woo-odoo/fusion_woocommerce/static/src/js/dashboard.js +++ b/fusion-woo-odoo/fusion_woocommerce/static/src/js/dashboard.js @@ -199,12 +199,23 @@ export class WooDashboard extends Component { type: "ir.actions.act_window", name: "Sync Errors (Last 24 h)", res_model: "woo.sync.log", - view_mode: "list,form", + views: [[false, "list"], [false, "form"]], domain: [["state", "=", "failed"]], target: "current", }); } + async clearErrors() { + const count = await rpc("/web/dataset/call_kw", { + model: "woo.sync.log", + method: "action_clear_errors", + args: [], + kwargs: {}, + }); + this.state.errors24h = 0; + this.notification.add(`${count} error log entries cleared.`, { type: "success" }); + } + openConflicts() { this.actionService.doAction("fusion_woocommerce.action_woo_conflict"); } diff --git a/fusion-woo-odoo/fusion_woocommerce/static/src/xml/dashboard.xml b/fusion-woo-odoo/fusion_woocommerce/static/src/xml/dashboard.xml index 3c4e5337..df5acb3c 100644 --- a/fusion-woo-odoo/fusion_woocommerce/static/src/xml/dashboard.xml +++ b/fusion-woo-odoo/fusion_woocommerce/static/src/xml/dashboard.xml @@ -50,7 +50,16 @@
⚠️
Errors (Last 24 h)
-
Click to view sync log
+
+ Click to view sync log + + + +
diff --git a/fusion-woo-odoo/fusion_woocommerce/views/woo_sync_log_views.xml b/fusion-woo-odoo/fusion_woocommerce/views/woo_sync_log_views.xml index be160e8e..66388182 100644 --- a/fusion-woo-odoo/fusion_woocommerce/views/woo_sync_log_views.xml +++ b/fusion-woo-odoo/fusion_woocommerce/views/woo_sync_log_views.xml @@ -6,7 +6,7 @@ woo.sync.log.tree woo.sync.log - + @@ -87,4 +87,14 @@ + + + Purge Old Logs + + + list + code + action = records.action_purge_old_logs() + +