diff --git a/fusion_plating/fusion_plating_jobs/__manifest__.py b/fusion_plating/fusion_plating_jobs/__manifest__.py index 89ef5d71..75a4f5c7 100644 --- a/fusion_plating/fusion_plating_jobs/__manifest__.py +++ b/fusion_plating/fusion_plating_jobs/__manifest__.py @@ -3,7 +3,7 @@ # License OPL-1 (Odoo Proprietary License v1.0) { 'name': 'Fusion Plating — Native Jobs', - 'version': '19.0.8.22.1', + 'version': '19.0.8.22.2', 'category': 'Manufacturing/Plating', 'summary': 'Native plating job model — replaces mrp.production / mrp.workorder bridge.', 'author': 'Nexa Systems Inc.', diff --git a/fusion_plating/fusion_plating_jobs/models/sale_order.py b/fusion_plating/fusion_plating_jobs/models/sale_order.py index d20b77b0..2f93af0f 100644 --- a/fusion_plating/fusion_plating_jobs/models/sale_order.py +++ b/fusion_plating/fusion_plating_jobs/models/sale_order.py @@ -12,6 +12,7 @@ import logging from markupsafe import Markup from odoo import _, api, fields, models +from odoo.exceptions import UserError _logger = logging.getLogger(__name__) @@ -245,6 +246,35 @@ class SaleOrder(models.Model): return super().create(vals_list) def action_confirm(self): + """Assign parent number + rename Q-…-N to SO-, then run + the standard confirm (which kicks off WO creation). + + Parent number is drawn from fp.parent.number; the quote name + was already saved to x_fc_quote_ref on create() so it survives + the rename. Idempotent — if x_fc_parent_number is already set, + the rename is skipped (re-confirm scenarios).""" + Seq = self.env['ir.sequence'] + for so in self: + if so.x_fc_parent_number: + continue + parent = Seq.next_by_code('fp.parent.number') + if not parent: + raise UserError(_( + 'Sequence fp.parent.number is missing. Reinstall ' + 'fusion_plating to restore it.' + )) + parent_int = int(parent) + old_name = so.name + # fp_allow_name_rename whitelists this single legitimate + # rename path through the immutability write() guard + # (added in Task 11). + so.with_context(fp_allow_name_rename=True).write({ + 'name': f'SO-{parent_int}', + 'x_fc_parent_number': parent_int, + }) + so.message_post(body=_( + 'Confirmed quote %s as %s.' + ) % (old_name, so.name)) result = super().action_confirm() for so in self: so._fp_auto_create_job()