refactor: update loyalty history retrieval to calculate points from issued/used fields and use description as fallback reference

This commit is contained in:
Suherdy Yacob 2026-06-14 16:20:16 +07:00
parent 369c1a92e3
commit 8571ddc88a

View File

@ -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,