This commit is contained in:
gsinghpal
2026-05-01 00:20:40 -04:00
parent bdcbd86db2
commit 1da27ed6bf
8 changed files with 117 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ to depend on the configurator. Any field that references a model defined
in configurator — like fp.pricing.rule, fp.part.catalog — must be
declared here.
"""
from odoo import fields, models
from odoo import api, fields, models, _
class FpProcessNode(models.Model):
@@ -73,3 +73,47 @@ class FpProcessNode(models.Model):
help='Friendly label shown in the variant picker '
'(e.g. "Standard ENP", "Selective Masking", "Rework").',
)
# ---- Linked Parts (cloned recipes) --------------------------------------
# On a shared template recipe, count + open all part-cloned recipe
# roots that were copied from this template (cloned_from_id == self).
# Only meaningful on shared templates (part_catalog_id IS NULL,
# node_type='recipe').
cloned_recipe_count = fields.Integer(
string='Linked Part Recipes',
compute='_compute_cloned_recipe_count',
)
def _compute_cloned_recipe_count(self):
Node = self.env['fusion.plating.process.node']
groups = Node._read_group(
domain=[
('cloned_from_id', 'in', self.ids),
('node_type', '=', 'recipe'),
('part_catalog_id', '!=', False),
],
groupby=['cloned_from_id'],
aggregates=['__count'],
)
counts = {src.id: count for src, count in groups}
for rec in self:
rec.cloned_recipe_count = counts.get(rec.id, 0)
def action_open_cloned_recipes(self):
"""Open the list of part-cloned recipe roots that came from this
template (i.e. cloned_from_id == self)."""
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Linked Parts — %s', self.name),
'res_model': 'fusion.plating.process.node',
'view_mode': 'list,form',
'domain': [
('cloned_from_id', '=', self.id),
('node_type', '=', 'recipe'),
('part_catalog_id', '!=', False),
],
'context': {
'search_default_group_part': 1,
},
}