# Stress-test the BoL with progressively longer notes env = env # noqa import re rep = env.ref('fusion_plating_reports.action_report_fp_bol_landscape') dlv = env['fusion.plating.delivery'].search([], order='id desc', limit=1) orig_notes = dlv.notes print(f'baseline (current notes={len(orig_notes or "") } chars)') scenarios = [ ('empty notes', '', 1), ('one short line', '

Handle with care.

', 1), ('three lines', '

Line 1

Line 2

Line 3

', 1), ('ten lines', ''.join(f'

Special instruction line {i}: handle with care, fragile, do not stack.

' for i in range(10)), 1), ('paragraph block', '

' + ('Long instructions filling the cargo description box. ' * 30) + '

', 1), ('huge block', '

' + ('Very long instructions. ' * 80) + '

', 1), ] print(f'\n{"scenario":<22} {"chars":<8} {"pages":<6} signature row intact?') print('-' * 70) for label, notes, _ in scenarios: dlv.write({'notes': notes}) pdf, _e = rep.with_context(force_report_rendering=True )._render_qweb_pdf(rep.report_name, [dlv.id]) n_pages = len(re.findall(rb'/Type\s*/Page[^s]', pdf)) # Save last for inspection with open(f'/tmp/bol_stress_{label.replace(" ","_")}.pdf', 'wb') as f: f.write(pdf) # Quick "intact" heuristic: if it's >1 page and the size is small, # likely overflowed. Real check is in pypdf locally. print(f'{label:<22} {len(notes):<8} {n_pages:<6} (PDF saved)') # Restore dlv.write({'notes': orig_notes or False}) print('\noriginal notes restored')