This commit is contained in:
gsinghpal
2026-05-25 20:11:03 -04:00
parent 67af54b46e
commit 5f372b462a
21 changed files with 444 additions and 833 deletions

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""Force-send a PIN reset email synchronously to see the SMTP error.
Run via odoo-shell on entech.
"""
import logging
_logger = logging.getLogger('bt_pin_send_debug')
# Garry (uid=2) — has gs@nexasystems.ca
u = env['res.users'].sudo().browse(2)
print('user:', u.name, '| email:', u.email, '| login:', u.login)
tpl = env.ref('fusion_plating_shopfloor.fp_mail_template_tablet_pin_reset')
print('template found:', tpl.name)
print('template email_from raw:', repr(tpl.email_from))
print('template email_to raw:', repr(tpl.email_to))
# Render to see what gets put on mail.mail
vals = tpl.with_context(code='5555')._generate_template(
[u.id],
{'email_to', 'email_from', 'partner_to', 'subject'},
)
print('--- rendered ---')
import json
print(json.dumps({str(k): str(v)[:200] if not isinstance(v, dict) else {kk: (list(vv) if hasattr(vv, '__iter__') and not isinstance(vv, str) else str(vv)[:200]) for kk, vv in v.items()} for k, v in vals.items()}, indent=2, default=str))
# Generate a real reset code + send via the same path the controller uses
Reset = env['fp.tablet.pin.reset'].sudo()
old = Reset.search([('user_id', '=', u.id), ('used_at', '=', False)])
if old:
print('purging', len(old), 'stale active reset rows')
old.unlink()
rec, code = Reset._generate_for_user(u, requester_ip='127.0.0.1')
print('generated code:', code, '(reset id', rec.id, ')')
# Send WITHOUT force_send first (matches controller), then peek at outbox
tpl.with_context(code=code).send_mail(u.id, force_send=False)
queued = env['mail.mail'].sudo().search(
[('mail_message_id.subject', 'like', '%ENTECH tablet temporary PIN%'),
('state', '=', 'outgoing')],
order='id desc', limit=1,
)
print('queued mail.mail id:', queued.id if queued else None,
'| state:', queued.state if queued else None,
'| email_to:', repr(queued.email_to) if queued else None,
'| recipients:', queued.recipient_ids.mapped('email') if queued else None,
'| email_from:', queued.email_from if queued else None)
# Now force-send and surface ANY SMTP error
if queued:
try:
print('--- attempting synchronous send ---')
queued.send(raise_exception=True)
print('queued.send() returned without exception')
except Exception as e:
print('SEND FAILED:', type(e).__name__, str(e)[:600])
import traceback
traceback.print_exc()
# Re-check state (might be deleted on success, or marked exception on fail)
try:
queued.invalidate_recordset()
print('after-send state:', queued.state, '| failure:', queued.failure_reason)
except Exception as e:
print('row deleted (auto_delete) -- send was treated as success:', type(e).__name__)
env.cr.commit()
print('--- done ---')

View File

@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
"""Verify the new _fp_resolve_from_header helper + rewrite the
mail.template record so it uses the helper (XML has noupdate=1 so -u
doesn't pick up the data-file change on existing installs).
Run via odoo-shell after `-u fusion_plating_shopfloor`.
"""
import time
u = env['res.users'].sudo().browse(2)
print('===== Helper resolution =====')
print('resolved from_header:', u._fp_resolve_from_header())
print()
print('===== Current template state =====')
tpl = env.ref('fusion_plating_shopfloor.fp_mail_template_tablet_pin_reset')
print(' subject: ', str(tpl.subject))
print(' email_from: ', str(tpl.email_from))
print(' reply_to: ', str(tpl.reply_to or '<empty>'))
print()
print('===== Rewriting template via ORM =====')
new_subject = "Your ENTECH tablet temporary PIN: {{ ctx.get('code', '----') }}"
new_from = "{{ object._fp_resolve_from_header() }}"
tpl.sudo().write({
'subject': new_subject,
'email_from': new_from,
'reply_to': new_from,
})
tpl.invalidate_recordset()
print(' subject: ', str(tpl.subject))
print(' email_from: ', str(tpl.email_from))
print(' reply_to: ', str(tpl.reply_to))
print()
print('===== Real send: time end-to-end =====')
Reset = env['fp.tablet.pin.reset'].sudo()
Reset.search([('user_id', '=', 2), ('used_at', '=', False)]).unlink()
t0 = time.time()
rec, code = Reset._generate_for_user(u)
t_gen = time.time() - t0
t1 = time.time()
tpl.sudo().with_context(code=code).send_mail(u.id, force_send=True)
t_send = time.time() - t1
t_total = time.time() - t0
print(' new code: ', code)
print(' _generate_for_user: {:.3f}s'.format(t_gen))
print(' send_mail (force_send): {:.3f}s'.format(t_send))
print(' TOTAL (Odoo-side): {:.3f}s'.format(t_total))
env.cr.commit()
print()
print('Watch gs@nexasystems.ca — measure wall-clock from now until it lands.')