fix(fusion_plating): bug review fixes + progress/net-terms invoicing + formal CoC rebuild
Bug review fixes (found by code review + live QWeb error):
- report_fp_sale.xml: product_uom → product_uom_id (Odoo 19 renamed;
was raising KeyError during PDF render, blocking all sale-order prints)
- mrp_production.button_mark_done: add idempotency guard on delivery
auto-create (was duplicating on every re-close)
- fp.certificate._compute_batch_ids: use empty recordset instead of
False for Many2many computed fields
- fp_notification_template._collect_attachments: collapse attach_quotation
+ attach_sale_order into a single render so email doesn't double-attach
the same PDF
- fp.operator.certification: SQL unique on computed state was unreliable;
added explicit `revoked` boolean, made state pure-compute, replaced
SQL constraint with @api.constrains that checks active-only uniqueness;
has_active_cert now reads revoked + expires_date directly (no stale
stored state between nightly recomputes)
Two missing invoice strategies implemented + 1 pre-existing deposit bug fix:
- Progress Billing: new x_fc_progress_initial_percent field on sale.order;
_create_progress_initial_invoice bills the configured % on SO confirm
via down-payment wizard, _create_final_balance_invoice bills the
remainder on delivery
- Net Terms: no invoice on confirm; full invoice auto-created when
fusion.plating.delivery.action_mark_delivered fires
- Fix for deposit (pre-existing, silent): sale.advance.payment.inv
reads active_ids at wizard-create time, not on create_invoices();
context was being set on the wrong call, so every deposit attempt
raised "Expected singleton" and message-posted to chatter instead
of actually invoicing
- New fusion_plating_invoicing/models/fp_delivery.py hooks
action_mark_delivered to dispatch final invoice for progress/net_terms
- fp.direct.order.wizard + SO form surface the progress_initial_percent
field (conditional on strategy)
Report styling cleanup:
- Hide DISCOUNT column from sale + invoice landscape reports unless at
least one line has a non-zero discount; colspan auto-adjusts
- Replace hardcoded #0066a1 in all reports with company.primary_color
driven by doc.company_id → company → user.company_id fallback chain,
with #1d1f1e as ultimate fallback; new .fp-header-primary class
exposes the colour for inline section headers (CARGO DESCRIPTION,
PAYMENT DETAILS, OPERATOR SIGN-OFF, etc.) so they retint with the
company theme without template edits
Certificate of Conformance — formal ENTECH-style rebuild:
- New res.company fields: x_fc_owner_user_id (default signer, sig from
hr.employee.signature), x_fc_coc_signature_override (manual upload),
x_fc_{nadcap,as9100,cgp}_logo + _active toggles for accreditation
badges
- New res.config.settings section "Fusion Plating" exposing the above
as configurable blocks; manager-only menu under Configuration →
Fusion Plating Settings
- New fp.certificate fields: nc_quantity, customer_job_no,
contact_partner_id (child contact for Name / Email / Phone block)
- New report_coc_en + report_coc_fr templates (primary): custom header
(company contact | accreditations | company logo), bilingual labels
per variant, customer info block with customer logo, 3-column cert
info table, 6-column line-item table (Part # | Process | Customer
PO | Shipped | NC Qty | Customer Job No.), signature image + bordered
certification statement, footer "Fusion Plating by Nexa Systems"
- Legacy report_coc + report_coc_portrait kept for existing portal-job
bindings (no behaviour change)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -45,20 +45,17 @@ class FpOperatorCertification(models.Model):
|
||||
'ir.attachment', string='Training Record',
|
||||
)
|
||||
notes = fields.Text(string='Notes')
|
||||
revoked = fields.Boolean(string='Revoked', tracking=True)
|
||||
revoked_reason = fields.Text(string='Revoked Reason')
|
||||
state = fields.Selection(
|
||||
[('active', 'Active'),
|
||||
('expired', 'Expired'),
|
||||
('revoked', 'Revoked')],
|
||||
string='Status', default='active', required=True,
|
||||
compute='_compute_state', store=True, readonly=False, tracking=True,
|
||||
string='Status',
|
||||
compute='_compute_state', store=True, tracking=True,
|
||||
# NOT readonly=False — this is purely derived from revoked + expires_date
|
||||
# so the nightly recompute never fights with manual edits.
|
||||
)
|
||||
revoked_reason = fields.Text(string='Revoked Reason')
|
||||
|
||||
_sql_constraints = [
|
||||
('fp_operator_cert_unique',
|
||||
'unique(employee_id, process_type_id, state)',
|
||||
'An operator cannot hold two active certifications for the same process.'),
|
||||
]
|
||||
|
||||
@api.depends('employee_id', 'process_type_id')
|
||||
def _compute_name(self):
|
||||
@@ -68,33 +65,64 @@ class FpOperatorCertification(models.Model):
|
||||
else:
|
||||
rec.name = ''
|
||||
|
||||
@api.depends('expires_date')
|
||||
@api.depends('expires_date', 'revoked')
|
||||
def _compute_state(self):
|
||||
today = fields.Date.today()
|
||||
for rec in self:
|
||||
if rec.state == 'revoked':
|
||||
if rec.revoked:
|
||||
rec.state = 'revoked'
|
||||
elif rec.expires_date and rec.expires_date < today:
|
||||
rec.state = 'expired'
|
||||
else:
|
||||
rec.state = 'active'
|
||||
|
||||
@api.constrains('employee_id', 'process_type_id', 'revoked', 'expires_date')
|
||||
def _check_single_active(self):
|
||||
"""At most one active certification per (employee, process_type)."""
|
||||
today = fields.Date.today()
|
||||
for rec in self:
|
||||
if rec.revoked:
|
||||
continue
|
||||
if rec.expires_date and rec.expires_date < today:
|
||||
rec.state = 'expired'
|
||||
elif rec.state != 'active':
|
||||
rec.state = 'active'
|
||||
continue
|
||||
# This record is active — look for another active sibling
|
||||
dupes = self.search_count([
|
||||
('id', '!=', rec.id),
|
||||
('employee_id', '=', rec.employee_id.id),
|
||||
('process_type_id', '=', rec.process_type_id.id),
|
||||
('revoked', '=', False),
|
||||
'|', ('expires_date', '=', False),
|
||||
('expires_date', '>=', today),
|
||||
])
|
||||
if dupes:
|
||||
from odoo.exceptions import ValidationError
|
||||
raise ValidationError(_(
|
||||
'Operator %s already has an active certification for "%s". '
|
||||
'Revoke or expire the existing one before adding another.'
|
||||
) % (rec.employee_id.name, rec.process_type_id.name))
|
||||
|
||||
def action_revoke(self):
|
||||
for rec in self:
|
||||
rec.state = 'revoked'
|
||||
rec.revoked = True
|
||||
rec.message_post(body=_('Certification revoked.'))
|
||||
|
||||
@api.model
|
||||
def has_active_cert(self, employee_id, process_type_id):
|
||||
"""Utility — True if this employee holds a current certification
|
||||
for this process type (or one of its ancestors in the category tree).
|
||||
"""Utility — True if this employee holds a current certification.
|
||||
|
||||
Checks revoked + expires_date directly instead of the computed
|
||||
`state` column, so even a certification that expired yesterday
|
||||
is caught immediately (no wait for nightly recompute).
|
||||
"""
|
||||
if not employee_id or not process_type_id:
|
||||
return False
|
||||
today = fields.Date.today()
|
||||
return bool(self.search_count([
|
||||
('employee_id', '=', employee_id),
|
||||
('process_type_id', '=', process_type_id),
|
||||
('state', '=', 'active'),
|
||||
('revoked', '=', False),
|
||||
'|', ('expires_date', '=', False),
|
||||
('expires_date', '>=', today),
|
||||
]))
|
||||
|
||||
|
||||
|
||||
@@ -28,3 +28,38 @@ class ResCompany(models.Model):
|
||||
def _compute_x_fc_facility_count(self):
|
||||
for rec in self:
|
||||
rec.x_fc_facility_count = len(rec.x_fc_facility_ids)
|
||||
|
||||
# =====================================================================
|
||||
# CoC / Certificate report settings
|
||||
# =====================================================================
|
||||
x_fc_owner_user_id = fields.Many2one(
|
||||
'res.users',
|
||||
string='Certificate Owner (Default Signer)',
|
||||
help='Quality manager / owner whose signature appears on Certificates '
|
||||
'of Conformance by default. Signature is pulled from their linked '
|
||||
'HR Employee record.',
|
||||
)
|
||||
x_fc_coc_signature_override = fields.Binary(
|
||||
string='Signature Override Image',
|
||||
help='Optional. Upload a pre-scanned signature image to use on '
|
||||
'Certificates of Conformance. Overrides the Owner user\'s '
|
||||
'employee signature when set. Useful if the owner doesn\'t have '
|
||||
'an HR record or wants a different signature for plating certs.',
|
||||
)
|
||||
|
||||
# --- Accreditation logos shown in CoC header ---
|
||||
x_fc_nadcap_logo = fields.Binary(string='Nadcap Logo')
|
||||
x_fc_nadcap_active = fields.Boolean(
|
||||
string='Nadcap Accredited',
|
||||
help='Show the Nadcap logo on certificates.',
|
||||
)
|
||||
x_fc_as9100_logo = fields.Binary(string='AS9100 / ISO 9001 Logo')
|
||||
x_fc_as9100_active = fields.Boolean(
|
||||
string='AS9100 / ISO 9001 Certified',
|
||||
help='Show the AS9100 / ISO 9001 logo on certificates.',
|
||||
)
|
||||
x_fc_cgp_logo = fields.Binary(string='Controlled Goods Program Logo')
|
||||
x_fc_cgp_active = fields.Boolean(
|
||||
string='CGP Registered',
|
||||
help='Show the Controlled Goods Program logo on certificates.',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user