changes
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
# only). One record per MO.
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class FpRackingInspection(models.Model):
|
||||
@@ -19,13 +19,13 @@ class FpRackingInspection(models.Model):
|
||||
_order = 'create_date desc, id desc'
|
||||
|
||||
name = fields.Char(compute='_compute_name', store=True)
|
||||
production_id = fields.Many2one(
|
||||
'mrp.production',
|
||||
string='Manufacturing Order',
|
||||
required=True,
|
||||
ondelete='cascade',
|
||||
index=True,
|
||||
tracking=True,
|
||||
# Phase 6 (Sub 11) — production_id retired (MRP module gone).
|
||||
# x_fc_job_id is the canonical link. Declared here so this module's
|
||||
# views can reference it at view-load time; fusion_plating_jobs adds
|
||||
# the constraints + compute overrides via inheritance.
|
||||
x_fc_job_id = fields.Many2one(
|
||||
'fp.job', string='Plating Job',
|
||||
index=True, ondelete='cascade',
|
||||
)
|
||||
sale_order_id = fields.Many2one(
|
||||
'sale.order',
|
||||
@@ -81,33 +81,27 @@ class FpRackingInspection(models.Model):
|
||||
flagged_count = fields.Integer(compute='_compute_line_stats')
|
||||
has_variance = fields.Boolean(compute='_compute_line_stats')
|
||||
|
||||
_sql_constraints = [
|
||||
('fp_racking_insp_mo_uniq',
|
||||
'unique(production_id)',
|
||||
'Only one racking inspection per manufacturing order.'),
|
||||
]
|
||||
# Phase 6 (Sub 11) — production_id retired (MRP module gone). The
|
||||
# uniqueness constraint that used to ride on production_id is now
|
||||
# enforced via @api.constrains on x_fc_job_id (added by
|
||||
# fusion_plating_jobs).
|
||||
|
||||
# ---- Computes ------------------------------------------------------------
|
||||
|
||||
@api.depends('production_id.name', 'partner_id.name')
|
||||
@api.depends('partner_id.name')
|
||||
def _compute_name(self):
|
||||
# Override in fusion_plating_jobs reads x_fc_job_id; this base
|
||||
# version is the bare-bones fallback.
|
||||
for rec in self:
|
||||
if rec.production_id:
|
||||
rec.name = _('Inspection — %s') % rec.production_id.name
|
||||
else:
|
||||
rec.name = _('Racking Inspection')
|
||||
rec.name = _('Racking Inspection')
|
||||
|
||||
@api.depends('production_id.origin')
|
||||
@api.depends('partner_id')
|
||||
def _compute_sale_order(self):
|
||||
SO = self.env['sale.order']
|
||||
# Override in fusion_plating_jobs walks x_fc_job_id.sale_order_id;
|
||||
# this base version is a fallback.
|
||||
for rec in self:
|
||||
so = False
|
||||
if rec.production_id and rec.production_id.origin:
|
||||
so = SO.search(
|
||||
[('name', '=', rec.production_id.origin)], limit=1,
|
||||
)
|
||||
rec.sale_order_id = so or False
|
||||
rec.partner_id = so.partner_id if so else False
|
||||
rec.sale_order_id = rec.sale_order_id or False
|
||||
rec.partner_id = rec.partner_id or False
|
||||
|
||||
@api.depends('sale_order_id')
|
||||
def _compute_receiving_id(self):
|
||||
@@ -160,7 +154,7 @@ class FpRackingInspection(models.Model):
|
||||
rec.activity_schedule(
|
||||
'mail.mail_activity_data_todo',
|
||||
summary=_('Racking discrepancy on %s') % (
|
||||
rec.production_id.name or ''
|
||||
rec.name or ''
|
||||
),
|
||||
note=_(
|
||||
'%(n)d line(s) flagged — review before starting '
|
||||
@@ -224,3 +218,12 @@ class FpRackingInspectionLine(models.Model):
|
||||
def _compute_qty_variance(self):
|
||||
for rec in self:
|
||||
rec.qty_variance = (rec.qty_found or 0) - (rec.qty_expected or 0)
|
||||
|
||||
@api.depends('part_catalog_id', 'part_number', 'qty_found', 'qty_expected')
|
||||
def _compute_display_name(self):
|
||||
for rec in self:
|
||||
label = (rec.part_catalog_id.display_name
|
||||
or rec.part_number
|
||||
or 'Inspection Line')
|
||||
qty = '%d/%d' % (rec.qty_found or 0, rec.qty_expected or 0)
|
||||
rec.display_name = '%s (%s)' % (label, qty)
|
||||
|
||||
Reference in New Issue
Block a user