# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) # Part of the Fusion Plating product family. from odoo import api, fields, models class FpCustomerSpec(models.Model): """Customer specification library entry. Holds the metadata about a specification (industry, customer, or internal) so jobs and process types can reference it. The actual document lives at document_url — could be a SharePoint link, a Google Drive URL, or any other location the shop already uses. """ _name = 'fusion.plating.customer.spec' _description = 'Fusion Plating — Customer Specification' _inherit = ['mail.thread', 'mail.activity.mixin'] _order = 'spec_type, code, revision desc' _rec_name = 'display_name' name = fields.Char( string='Title', required=True, tracking=True, ) display_name = fields.Char( compute='_compute_display_name', store=True, ) code = fields.Char( string='Spec Code', required=True, tracking=True, help='e.g. AMS 2404, ASTM B733, MIL-C-26074', ) revision = fields.Char( string='Revision', tracking=True, ) effective_date = fields.Date( string='Effective Date', tracking=True, ) partner_id = fields.Many2one( 'res.partner', string='Customer', help='Leave blank for industry / internal specs.', ) process_type_ids = fields.Many2many( 'fusion.plating.process.type', 'fp_customer_spec_process_rel', 'spec_id', 'process_type_id', string='Applicable Processes', ) spec_type = fields.Selection( [ ('industry', 'Industry / Standard'), ('customer', 'Customer'), ('internal', 'Internal'), ], string='Type', default='industry', required=True, tracking=True, ) document_url = fields.Char( string='Document URL', help='Link to the controlled copy of the specification (SharePoint, ' 'Google Drive, etc.).', ) notes = fields.Html( string='Notes', ) recipe_ids = fields.Many2many( 'fusion.plating.process.node', 'fp_customer_spec_recipe_rel', 'spec_id', 'recipe_id', domain="[('node_type', '=', 'recipe'), ('parent_id', '=', False)]", string='Applicable Recipes', help='Recipes that can produce work to this specification. ' 'Many-to-many — one spec can cover multiple processes; ' 'one recipe can satisfy multiple specs.', ) print_on_cert = fields.Boolean( string='Print on Certificate', default=True, help="When enabled, this spec's code+revision appear on the CoC " 'when the spec is selected on the SO line.', ) company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env.company, ) active = fields.Boolean(default=True) _sql_constraints = [ ( 'fp_customer_spec_code_rev_uniq', 'unique(code, revision, company_id)', 'A specification at the same revision must be unique per company.', ), ] @api.depends('code', 'revision', 'name') def _compute_display_name(self): for rec in self: parts = [rec.code or ''] if rec.revision: parts.append(f'Rev {rec.revision}') if rec.name: parts.append(f'— {rec.name}') rec.display_name = ' '.join(p for p in parts if p)