changes
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
# boxes (which is DIFFERENT from receiving — receiving is box count
|
||||
# only). One record per MO.
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
@@ -151,6 +153,27 @@ class FpRackingInspection(models.Model):
|
||||
'inspection_completed': fields.Datetime.now(),
|
||||
})
|
||||
if new_state == 'discrepancy_flagged':
|
||||
# 2026-04-28 — Activity must land on a real user.
|
||||
# Resolve the assignee in priority order:
|
||||
# 1. The job's plating manager (if set on fp.job)
|
||||
# 2. The inspector who just flagged it
|
||||
# 3. The current user (env.uid fallback)
|
||||
# `activity_schedule` defaults to env.uid only when the
|
||||
# record has a `user_id` field; fp.racking.inspection
|
||||
# has `inspector_id` but not `user_id`, so we'd land on
|
||||
# False if we let it default. Explicit assignment is
|
||||
# the only safe path.
|
||||
assignee = False
|
||||
if (rec.x_fc_job_id and 'manager_id' in rec.x_fc_job_id._fields
|
||||
and rec.x_fc_job_id.manager_id):
|
||||
assignee = rec.x_fc_job_id.manager_id.id
|
||||
elif rec.inspector_id:
|
||||
assignee = rec.inspector_id.id
|
||||
else:
|
||||
assignee = self.env.uid
|
||||
# 3-day deadline so it surfaces in "Overdue" dashboards
|
||||
# if not addressed before plating starts.
|
||||
deadline = fields.Date.today() + relativedelta(days=3)
|
||||
rec.activity_schedule(
|
||||
'mail.mail_activity_data_todo',
|
||||
summary=_('Racking discrepancy on %s') % (
|
||||
@@ -160,6 +183,8 @@ class FpRackingInspection(models.Model):
|
||||
'%(n)d line(s) flagged — review before starting '
|
||||
'the first plating WO.'
|
||||
) % {'n': rec.flagged_count},
|
||||
user_id=assignee,
|
||||
date_deadline=deadline,
|
||||
)
|
||||
rec.message_post(body=_(
|
||||
'Inspection completed — %(ok)d ok / %(flag)d flagged.'
|
||||
@@ -214,6 +239,50 @@ class FpRackingInspectionLine(models.Model):
|
||||
)
|
||||
notes = fields.Char(string='Notes')
|
||||
|
||||
# 2026-04-28 — photos on a line (compliance need: damage evidence,
|
||||
# box-by-box condition record). Many2many to ir.attachment so an
|
||||
# operator can shoot multiple angles per box from the floor without
|
||||
# leaving the form. Cascade-deleted with the line.
|
||||
photo_ids = fields.Many2many(
|
||||
'ir.attachment',
|
||||
relation='fp_racking_insp_line_photo_rel',
|
||||
column1='line_id',
|
||||
column2='attachment_id',
|
||||
string='Photos',
|
||||
domain="[('mimetype', 'ilike', 'image/')]",
|
||||
help='Damage / condition photos for this box. Click + to upload '
|
||||
'one or more from the camera roll. Cascades on delete.',
|
||||
)
|
||||
photo_count = fields.Integer(
|
||||
string='# Photos',
|
||||
compute='_compute_photo_count',
|
||||
)
|
||||
|
||||
@api.depends('photo_ids')
|
||||
def _compute_photo_count(self):
|
||||
for rec in self:
|
||||
rec.photo_count = len(rec.photo_ids)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
# Auto-populate part_catalog_id from the parent inspection's job
|
||||
# when the operator added a line without picking a part. The
|
||||
# job's SO carries the customer's part — pre-fill the line so
|
||||
# the audit trail captures it without requiring extra clicks.
|
||||
for vals in vals_list:
|
||||
if not vals.get('part_catalog_id') and vals.get('inspection_id'):
|
||||
ri = self.env['fp.racking.inspection'].browse(
|
||||
vals['inspection_id'])
|
||||
if ri.exists() and ri.x_fc_job_id:
|
||||
so = ri.x_fc_job_id.sale_order_id
|
||||
if so:
|
||||
line = so.order_line.filtered(
|
||||
lambda l: l.x_fc_part_catalog_id
|
||||
)[:1]
|
||||
if line:
|
||||
vals['part_catalog_id'] = line.x_fc_part_catalog_id.id
|
||||
return super().create(vals_list)
|
||||
|
||||
@api.depends('qty_expected', 'qty_found')
|
||||
def _compute_qty_variance(self):
|
||||
for rec in self:
|
||||
|
||||
Reference in New Issue
Block a user