fix(portal): correct group indices after adding work_order to docs panel

Regression I introduced when adding the WO Detail group: the
groups.insert(2, wo_group) ran BEFORE the SPECIFICATIONS / QUALITY /
SHIPPING appends, so groups[2] shifted from 'quality' to 'work_order'
mid-helper. Result: the CoC got appended to the work_order group's
docs and shipping doc went into quality. Test caught it.

Restructured to declare the 5-group list up front in display order
and use stable indices throughout (0=from_you, 1=specs, 2=work_order,
3=quality, 4=shipping). Added a code comment warning future editors
that reordering means updating every groups[N] reference.

Test updated to expect 5 groups, asserting both 'work_order' and
'quality' keys are present + pending state in each.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-05-17 12:12:20 -04:00
parent 6cad69cb86
commit 153b980e2b
2 changed files with 39 additions and 34 deletions

View File

@@ -117,8 +117,9 @@ class TestPortalDashboard(TransactionCase):
statuses = [t['status'] for t in timeline]
self.assertEqual(statuses, ['done', 'done', 'done', 'done', 'done'])
def test_group_documents_v1_returns_4_groups(self):
"""V1 doc grouping returns 4 groups; quality populated when CoC set."""
def test_group_documents_returns_5_groups(self):
"""V1 doc grouping returns 5 groups: From You / Specs / Work Order /
Quality / Shipping. Quality populated when CoC set."""
from odoo.addons.fusion_plating_portal.controllers.portal import FpCustomerPortal
Job = self.env['fusion.plating.portal.job']
att = self.env['ir.attachment'].create({
@@ -133,13 +134,16 @@ class TestPortalDashboard(TransactionCase):
'coc_attachment_id': att.id,
})
groups = FpCustomerPortal()._fp_group_documents(job)
self.assertEqual(len(groups), 4)
self.assertEqual(len(groups), 5)
keys = [g['key'] for g in groups]
self.assertEqual(keys, ['from_you', 'specs', 'quality', 'shipping'])
self.assertEqual(keys, ['from_you', 'specs', 'work_order', 'quality', 'shipping'])
# Quality group has the CoC populated (not pending)
quality = next(g for g in groups if g['key'] == 'quality')
self.assertTrue(any(d['label'] == 'Certificate of Conformance' and not d.get('pending')
for d in quality['docs']))
# From You + Specifications are placeholders in V1
# From You is a placeholder when no SO link (test job has no x_fc_job_id)
from_you = next(g for g in groups if g['key'] == 'from_you')
self.assertTrue(all(d.get('pending') for d in from_you['docs']))
# Work Order is placeholder without a backend fp.job link
wo = next(g for g in groups if g['key'] == 'work_order')
self.assertTrue(all(d.get('pending') for d in wo['docs']))