Files
gsinghpal f08f328688 changes
2026-04-27 00:11:18 -04:00

59 lines
2.1 KiB
Python

# Step 8 re-verify — fresh SO with net_terms strategy should now get
# Net-30 payment term auto-filled, and the invoice should post.
from odoo import fields
W = env['fp.direct.order.wizard']
Line = env['fp.direct.order.line']
Part = env['fp.part.catalog']
P = env['res.partner']
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-STEP8RV-001',
'invoice_strategy': 'net_terms',
})
w._onchange_partner_id()
w._onchange_invoice_strategy() # also fires _apply_strategy_payment_term
print(f'[Sarah] After invoice_strategy=net_terms, payment_term_id={w.payment_term_id.name if w.payment_term_id else None}')
Line.create({
'wizard_id': w.id, 'part_catalog_id': part.id,
'coating_config_id': part.x_fc_default_coating_config_id.id,
'quantity': 4, 'unit_price': 30.0,
})
r = w.action_create_order()
so = env['sale.order'].browse(r['res_id'])
print(f'[Sarah] SO {so.name} created, payment_term_id={so.payment_term_id.name if so.payment_term_id else None}')
so.action_confirm()
print(f'[Sarah] Confirmed → state={so.state}')
# Walk job to done so it's invoiceable.
job = env['fp.job'].search([('sale_order_id', '=', so.id)], limit=1)
for s in job.step_ids.sorted('sequence'):
if s.state in ('pending', 'ready'):
s.button_start()
if s.state == 'in_progress':
s.button_finish()
job.button_mark_done()
print(f'[Carlos] Job {job.name} done')
# Jane invoices.
print()
print('[Jane] Creating + posting invoice:')
result = so._create_invoices()
inv = env['account.move'].search([('invoice_origin', '=', so.name)], order='id desc', limit=1)
print(f' Invoice {inv.name or "(unnamed draft)"}: state={inv.state}, payment_term={inv.invoice_payment_term_id.name if inv.invoice_payment_term_id else None}')
try:
inv.action_post()
print(f' ✓ Posted: state={inv.state}, payment_state={inv.payment_state}')
print(f' ✓ Invoice name: {inv.name}, due date: {inv.invoice_date_due}')
except Exception as e:
print(f'{e}')
env.cr.commit()
print()
print('== Step 8 re-verify complete ==')