From 8571ddc88a5e2dea906181101c9f3c2aadcf3f8c Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Sun, 14 Jun 2026 16:20:16 +0700 Subject: [PATCH] refactor: update loyalty history retrieval to calculate points from issued/used fields and use description as fallback reference --- controllers/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/main.py b/controllers/main.py index 64769f4..d0c43f9 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -177,14 +177,16 @@ class AppNotificationController(http.Controller): history_records = request.env['loyalty.history'].sudo().search_read( [('card_id', 'in', card_ids)], - ['id', 'card_id', 'points', 'date', 'order_id'], - order='date desc', + ['id', 'card_id', 'issued', 'used', 'create_date', 'order_id', 'description'], + order='create_date desc', limit=100 ) result = [] for rec in history_records: - points = rec.get('points') or 0 + issued = rec.get('issued') or 0.0 + used = rec.get('used') or 0.0 + points = issued - used point_type = 'earn' if points >= 0 else 'spend' order_ref = '' @@ -194,9 +196,12 @@ class AppNotificationController(http.Controller): elif order_id: order_ref = str(order_id) + if not order_ref: + order_ref = rec.get('description') or '' + result.append({ 'id': rec['id'], - 'date': str(rec.get('date') or ''), + 'date': str(rec.get('create_date') or ''), 'points': round(float(points), 2), 'type': point_type, 'order_ref': order_ref,