env = env # noqa
# Pick the SO we last tested
so = env['sale.order'].search([('name', '=', 'S00038')], limit=1)
if not so:
print('S00038 not found, picking last sale.order')
so = env['sale.order'].search([], order='id desc', limit=1)
print(f'SO: {so.name}')
print(f' state: {so.state}')
print(f' invoice_status: {so.invoice_status}')
print(f' invoice_ids: {[(i.name, i.state, i.payment_state) for i in so.invoice_ids]}')
print(f' workflow_stage: {so.x_fc_workflow_stage}')
print(f' → BANNER VISIBLE? {so.x_fc_workflow_stage not in ("draft","invoicing","paid","complete","cancelled")}')
# Post a fresh test message that exercises the new Markup path
mo = env['mrp.production'].search([('origin', '=', so.name)], limit=1)
if mo:
from markupsafe import Markup
so.message_post(body=Markup(
'TEST: Draft Manufacturing Order %s '
'should render as a clickable link with bold text.'
) % (mo.id, mo.name))
print(f'\\nposted test message on {so.name} referencing {mo.name}')
# Check the latest 2 messages on the SO
msgs = env['mail.message'].search([
('model', '=', 'sale.order'), ('res_id', '=', so.id),
], order='id desc', limit=3)
print(f'\\nLast {len(msgs)} chatter messages on {so.name}:')
for m in msgs:
body = (m.body or '')[:200]
print(f' [{m.id}] {body!r}')
env.cr.commit()