122 lines
3.2 KiB
Python
122 lines
3.2 KiB
Python
# -*- 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 FpAudit(models.Model):
|
|
"""Internal, customer, certification, or supplier audit.
|
|
|
|
Holds the planning, execution, and findings for any audit the shop
|
|
is involved in. Findings drive CAPAs through the optional many-to-many
|
|
relationship.
|
|
"""
|
|
_name = 'fusion.plating.audit'
|
|
_description = 'Fusion Plating — Audit'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
_order = 'audit_date desc, id desc'
|
|
|
|
name = fields.Char(
|
|
string='Reference',
|
|
required=True,
|
|
copy=False,
|
|
readonly=True,
|
|
default=lambda self: self._default_name(),
|
|
tracking=True,
|
|
)
|
|
audit_type = fields.Selection(
|
|
[
|
|
('internal', 'Internal'),
|
|
('customer', 'Customer'),
|
|
('certification', 'Certification Body'),
|
|
('supplier', 'Supplier'),
|
|
],
|
|
string='Type',
|
|
default='internal',
|
|
required=True,
|
|
tracking=True,
|
|
)
|
|
scope = fields.Char(
|
|
string='Scope',
|
|
tracking=True,
|
|
)
|
|
facility_id = fields.Many2one(
|
|
'fusion.plating.facility',
|
|
string='Facility',
|
|
tracking=True,
|
|
)
|
|
company_id = fields.Many2one(
|
|
'res.company',
|
|
related='facility_id.company_id',
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
auditor_ids = fields.Many2many(
|
|
'res.users',
|
|
'fp_audit_auditor_rel',
|
|
'audit_id',
|
|
'user_id',
|
|
string='Auditors',
|
|
)
|
|
audit_date = fields.Date(
|
|
string='Audit Date',
|
|
tracking=True,
|
|
)
|
|
state = fields.Selection(
|
|
[
|
|
('planned', 'Planned'),
|
|
('in_progress', 'In Progress'),
|
|
('findings', 'Findings'),
|
|
('closed', 'Closed'),
|
|
],
|
|
string='Status',
|
|
default='planned',
|
|
required=True,
|
|
tracking=True,
|
|
)
|
|
findings_count = fields.Integer(
|
|
string='# Findings',
|
|
)
|
|
findings_html = fields.Html(
|
|
string='Findings',
|
|
)
|
|
capa_ids = fields.Many2many(
|
|
'fusion.plating.capa',
|
|
'fp_audit_capa_rel',
|
|
'audit_id',
|
|
'capa_id',
|
|
string='CAPAs',
|
|
)
|
|
capa_count = fields.Integer(
|
|
compute='_compute_capa_count',
|
|
)
|
|
active = fields.Boolean(default=True)
|
|
|
|
@api.model
|
|
def _default_name(self):
|
|
seq = self.env['ir.sequence'].next_by_code('fusion.plating.audit')
|
|
return seq or '/'
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if not vals.get('name') or vals.get('name') == '/':
|
|
vals['name'] = self._default_name()
|
|
return super().create(vals_list)
|
|
|
|
@api.depends('capa_ids')
|
|
def _compute_capa_count(self):
|
|
for rec in self:
|
|
rec.capa_count = len(rec.capa_ids)
|
|
|
|
def action_start(self):
|
|
self.write({'state': 'in_progress'})
|
|
|
|
def action_findings(self):
|
|
self.write({'state': 'findings'})
|
|
|
|
def action_close(self):
|
|
self.write({'state': 'closed'})
|