68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
#
|
|
# Adds the Work Order smart button + header action to fp.receiving so
|
|
# the receiving form mirrors the SO's WO entry point. Button appears
|
|
# once the receiving is closed and stays until every linked fp.job
|
|
# reaches state='done'.
|
|
|
|
from odoo import _, fields, models
|
|
|
|
|
|
class FpReceiving(models.Model):
|
|
_inherit = 'fp.receiving'
|
|
|
|
x_fc_fp_job_count = fields.Integer(
|
|
string='Work Orders',
|
|
compute='_compute_fp_job_count',
|
|
)
|
|
x_fc_show_work_order_btn = fields.Boolean(
|
|
string='Show Work Order Button',
|
|
compute='_compute_show_work_order_btn',
|
|
help='True once this receiving is closed and at least one linked '
|
|
'work order is still open (state != done). Hidden again '
|
|
'when every job is done.',
|
|
)
|
|
|
|
def _compute_fp_job_count(self):
|
|
Job = self.env['fp.job'].sudo()
|
|
for rec in self:
|
|
if rec.sale_order_id:
|
|
rec.x_fc_fp_job_count = Job.search_count(
|
|
[('sale_order_id', '=', rec.sale_order_id.id)]
|
|
)
|
|
else:
|
|
rec.x_fc_fp_job_count = 0
|
|
|
|
def _compute_show_work_order_btn(self):
|
|
Job = self.env['fp.job'].sudo()
|
|
for rec in self:
|
|
if rec.state != 'closed' or not rec.sale_order_id:
|
|
rec.x_fc_show_work_order_btn = False
|
|
continue
|
|
jobs = Job.search([('sale_order_id', '=', rec.sale_order_id.id)])
|
|
rec.x_fc_show_work_order_btn = bool(jobs) and any(
|
|
j.state != 'done' for j in jobs
|
|
)
|
|
|
|
def action_view_fp_jobs(self):
|
|
"""Open the work order(s) linked to this receiving's sale order."""
|
|
self.ensure_one()
|
|
if not self.sale_order_id:
|
|
return False
|
|
jobs = self.env['fp.job'].search([
|
|
('sale_order_id', '=', self.sale_order_id.id),
|
|
])
|
|
action = {
|
|
'type': 'ir.actions.act_window',
|
|
'name': _('Work Orders'),
|
|
'res_model': 'fp.job',
|
|
'view_mode': 'list,form',
|
|
'domain': [('sale_order_id', '=', self.sale_order_id.id)],
|
|
'context': {'default_sale_order_id': self.sale_order_id.id},
|
|
}
|
|
if len(jobs) == 1:
|
|
action.update({'view_mode': 'form', 'res_id': jobs.id})
|
|
return action
|