125 lines
3.6 KiB
Python
125 lines
3.6 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 FpAvl(models.Model):
|
|
"""Approved Vendor List entry.
|
|
|
|
The AVL ties an approval state to a res.partner. Each entry tracks
|
|
approval date, expiry, scorecard rating, and what processes the
|
|
vendor is approved to supply for. Suspended or removed vendors stay
|
|
in the list for traceability.
|
|
"""
|
|
_name = 'fusion.plating.avl'
|
|
_description = 'Fusion Plating — Approved Vendor List'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
_order = 'state, name'
|
|
_rec_name = 'name'
|
|
|
|
name = fields.Char(
|
|
string='Vendor',
|
|
compute='_compute_name',
|
|
store=True,
|
|
)
|
|
partner_id = fields.Many2one(
|
|
'res.partner',
|
|
string='Partner',
|
|
required=True,
|
|
tracking=True,
|
|
)
|
|
company_id = fields.Many2one(
|
|
'res.company',
|
|
string='Company',
|
|
default=lambda self: self.env.company,
|
|
)
|
|
category = fields.Selection(
|
|
[
|
|
('chemical', 'Chemical'),
|
|
('equipment', 'Equipment'),
|
|
('service', 'Service'),
|
|
('lab', 'Lab / Calibration'),
|
|
('shipping', 'Shipping'),
|
|
('other', 'Other'),
|
|
],
|
|
string='Category',
|
|
default='chemical',
|
|
tracking=True,
|
|
)
|
|
approval_date = fields.Date(
|
|
string='Approval Date',
|
|
tracking=True,
|
|
)
|
|
approval_expiry = fields.Date(
|
|
string='Approval Expiry',
|
|
tracking=True,
|
|
)
|
|
state = fields.Selection(
|
|
[
|
|
('pending', 'Pending'),
|
|
('approved', 'Approved'),
|
|
('conditional', 'Conditional'),
|
|
('suspended', 'Suspended'),
|
|
('removed', 'Removed'),
|
|
],
|
|
string='Status',
|
|
default='pending',
|
|
required=True,
|
|
tracking=True,
|
|
)
|
|
approved_for = fields.Char(
|
|
string='Approved For',
|
|
help='Free text — what processes / products / services this vendor '
|
|
'is approved to supply.',
|
|
)
|
|
notes = fields.Html(
|
|
string='Notes',
|
|
)
|
|
scorecard_rating = fields.Float(
|
|
string='Scorecard',
|
|
help='0 to 5 rating from the most recent vendor scorecard.',
|
|
)
|
|
is_expired = fields.Boolean(
|
|
string='Expired',
|
|
compute='_compute_is_expired',
|
|
search='_search_is_expired',
|
|
)
|
|
active = fields.Boolean(default=True)
|
|
|
|
@api.depends('partner_id')
|
|
def _compute_name(self):
|
|
for rec in self:
|
|
rec.name = rec.partner_id.name or 'New Vendor'
|
|
|
|
@api.depends('approval_expiry')
|
|
def _compute_is_expired(self):
|
|
today = fields.Date.context_today(self)
|
|
for rec in self:
|
|
rec.is_expired = bool(
|
|
rec.approval_expiry and rec.approval_expiry < today
|
|
)
|
|
|
|
def _search_is_expired(self, operator, value):
|
|
today = fields.Date.context_today(self)
|
|
if (operator == '=' and value) or (operator == '!=' and not value):
|
|
return [('approval_expiry', '<', today)]
|
|
return ['|', ('approval_expiry', '>=', today), ('approval_expiry', '=', False)]
|
|
|
|
def action_approve(self):
|
|
self.write({
|
|
'state': 'approved',
|
|
'approval_date': fields.Date.context_today(self),
|
|
})
|
|
|
|
def action_suspend(self):
|
|
self.write({'state': 'suspended'})
|
|
|
|
def action_remove(self):
|
|
self.write({'state': 'removed'})
|
|
|
|
def action_reinstate(self):
|
|
self.write({'state': 'approved'})
|