feat(configurator): Phase D batch 2 — active WOs stat button on SO form
D3 first half: x_fc_workorder_count computes live count of active MRP work orders linked to this SO (via mo.origin = so.name). Adds a 'Active WOs' smart button next to the existing PO / RFQ buttons on the sale.order form. Clicking opens a filtered mrp.workorder list grouped by MO. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,33 @@ class SaleOrder(models.Model):
|
||||
compute='_compute_margin',
|
||||
)
|
||||
|
||||
x_fc_workorder_count = fields.Integer(
|
||||
string='Active WOs',
|
||||
compute='_compute_workorder_count',
|
||||
)
|
||||
|
||||
def _compute_workorder_count(self):
|
||||
WO = self.env['mrp.workorder'].sudo()
|
||||
for rec in self:
|
||||
if not rec.name:
|
||||
rec.x_fc_workorder_count = 0
|
||||
continue
|
||||
rec.x_fc_workorder_count = WO.search_count([
|
||||
('production_id.origin', '=', rec.name),
|
||||
('state', 'not in', ('done', 'cancel')),
|
||||
])
|
||||
|
||||
def action_view_workorders(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Work Orders',
|
||||
'res_model': 'mrp.workorder',
|
||||
'view_mode': 'list,form',
|
||||
'domain': [('production_id.origin', '=', self.name)],
|
||||
'context': {'search_default_group_production_id': 1},
|
||||
}
|
||||
|
||||
@api.depends('commitment_date')
|
||||
def _compute_deadline_countdown(self):
|
||||
from datetime import datetime
|
||||
|
||||
Reference in New Issue
Block a user