Files
Odoo-Modules/fusion_plating/fusion_plating_quality/scripts/bt_s12_verify.py
gsinghpal f08f328688 changes
2026-04-27 00:11:18 -04:00

60 lines
2.1 KiB
Python

# Verify mid-job qty change posts chatter + sync action works.
from odoo import fields
W = env['fp.direct.order.wizard']
Line = env['fp.direct.order.line']
P = env['res.partner']
Part = env['fp.part.catalog']
target = P.browse(2529)
part = Part.search([('x_fc_default_coating_config_id', '!=', False)], limit=1)
w = W.create({
'partner_id': target.id, 'po_pending': True,
'po_number': 'PO-S12V-' + fields.Datetime.now().strftime('%H%M%S'),
'invoice_strategy': 'net_terms',
})
w._onchange_partner_id()
Line.create({
'wizard_id': w.id, 'part_catalog_id': part.id,
'coating_config_id': part.x_fc_default_coating_config_id.id,
'quantity': 5, 'unit_price': 20.0,
})
r = w.action_create_order()
so = env['sale.order'].browse(r['res_id'])
so.action_confirm()
job = env['fp.job'].search([('sale_order_id', '=', so.id)], limit=1)
sol = so.order_line[:1]
job.step_ids.sorted('sequence')[0].button_start()
print(f' Initial: SO={sol.product_uom_qty}, job.qty={job.qty}')
before_msgs = len(job.message_ids)
print()
print(f' Sarah edits SO line qty 5 → 8 mid-job')
sol.product_uom_qty = 8
job.invalidate_recordset()
after_msgs = len(job.message_ids)
print(f' Job chatter: {before_msgs}{after_msgs} (delta {after_msgs - before_msgs})')
warn = job.message_ids.filtered(lambda m: 'qty changed mid-job' in (m.body or ''))
print(f' Warning messages on job: {len(warn)}')
if warn:
print(f' ✓ Chatter warning posted')
print(f' Job.qty still: {job.qty} (unchanged — supervisor must explicitly sync)')
print()
print(f' Bob clicks "Sync qty from SO" on the job')
job.action_sync_qty_from_so()
print(f' Job.qty after sync: {job.qty} (expect 8)')
sync_msgs = job.message_ids.filtered(lambda m: 'synced from SO' in (m.body or ''))
print(f' Sync chatter messages: {len(sync_msgs)}')
print()
# Now what about LOWER qty
print(f' Customer reduces to 3...')
sol.product_uom_qty = 3
job.invalidate_recordset()
warn2 = len(job.message_ids.filtered(lambda m: 'qty changed mid-job' in (m.body or '')))
print(f' Warnings now: {warn2}')
job.action_sync_qty_from_so()
print(f' After sync: job.qty={job.qty}')
env.cr.commit()