feat(quality_dashboard): populate section items (Task 3)
_fetch_section_items pulls top-5 open records per type, ranked overdue-first by oldest create_date. _build_item shapes each row with id/name/customer/subtitle/urgency/open_action. _resolve_partner defensively walks partner_id -> job_id.partner_id -> ncr_id.partner_id per type. _build_subtitle generates the human-readable second line. Tests cover empty list, 5-cap on 8-record set, and required item keys (id/name/customer/subtitle/urgency/open_action). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,3 +52,60 @@ class TestDashboardSnapshotShape(TransactionCase):
|
||||
self.assertIsInstance(section['items'], list)
|
||||
self.assertIsInstance(section['open'], int)
|
||||
self.assertIsInstance(section['overdue'], int)
|
||||
|
||||
|
||||
class TestDashboardSnapshotItems(TransactionCase):
|
||||
"""Per-section items list — ranking + cap + shape."""
|
||||
|
||||
def _build(self):
|
||||
from odoo.addons.fusion_plating_quality.controllers.fp_quality_dashboard \
|
||||
import FpQualityDashboardSnapshot
|
||||
return FpQualityDashboardSnapshot(self.env).build()
|
||||
|
||||
def _get_section(self, snap, type_code):
|
||||
for s in snap['sections']:
|
||||
if s['type'] == type_code:
|
||||
return s
|
||||
return None
|
||||
|
||||
def test_section_items_empty_when_no_records(self):
|
||||
snap = self._build()
|
||||
cert_sec = self._get_section(snap, 'cert')
|
||||
if cert_sec is None:
|
||||
self.skipTest('fp.certificate not installed')
|
||||
self.assertEqual(cert_sec['items'], [])
|
||||
|
||||
def test_section_items_capped_at_5(self):
|
||||
if 'fusion.plating.quality.hold' not in self.env:
|
||||
self.skipTest('fusion.plating.quality.hold not installed')
|
||||
partner = self.env['res.partner'].create({'name': 'Cust'})
|
||||
# Create 8 holds in the same open state
|
||||
Hold = self.env['fusion.plating.quality.hold']
|
||||
for i in range(8):
|
||||
Hold.create({
|
||||
'partner_id': partner.id,
|
||||
'state': 'on_hold',
|
||||
'reason': f'test hold {i}',
|
||||
})
|
||||
snap = self._build()
|
||||
sec = self._get_section(snap, 'hold')
|
||||
self.assertEqual(len(sec['items']), 5)
|
||||
self.assertEqual(sec['open'], 8)
|
||||
|
||||
def test_item_has_required_keys(self):
|
||||
if 'fusion.plating.quality.hold' not in self.env:
|
||||
self.skipTest('fusion.plating.quality.hold not installed')
|
||||
partner = self.env['res.partner'].create({'name': 'Cust'})
|
||||
hold = self.env['fusion.plating.quality.hold'].create({
|
||||
'partner_id': partner.id, 'state': 'on_hold', 'reason': 'x',
|
||||
})
|
||||
snap = self._build()
|
||||
sec = self._get_section(snap, 'hold')
|
||||
self.assertEqual(len(sec['items']), 1)
|
||||
item = sec['items'][0]
|
||||
for k in ('id', 'name', 'customer', 'subtitle',
|
||||
'urgency', 'open_action'):
|
||||
self.assertIn(k, item, f'item missing key {k!r}')
|
||||
self.assertEqual(item['open_action']['res_model'],
|
||||
'fusion.plating.quality.hold')
|
||||
self.assertEqual(item['open_action']['res_id'], hold.id)
|
||||
|
||||
Reference in New Issue
Block a user