# -*- coding: utf-8 -*- # Copyright 2024-2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) from odoo import api, fields, models class FusionRepairIntakeTemplate(models.Model): """A reusable set of intake questions per medical equipment category. Each template contains an ordered list of questions; the intake wizard (and sales-rep / client portals) render these dynamically with conditional show/hide based on prior answers. """ _name = 'fusion.repair.intake.template' _description = 'Repair Intake Question Template' _order = 'sequence, name' name = fields.Char(string='Template Name', required=True, translate=True) code = fields.Char( string='Code', help='Optional stable identifier for referencing this template from code/data.', ) sequence = fields.Integer(string='Sequence', default=10) active = fields.Boolean(default=True) is_default = fields.Boolean( string='Default Fallback', help='Used when no template is explicitly configured for the selected category. ' 'Exactly one template should be flagged as default per company.', ) description = fields.Html(string='Description', translate=True) product_category_ids = fields.Many2many( 'fusion.repair.product.category', 'fusion_repair_intake_template_category_rel', 'template_id', 'category_id', string='Applies to Categories', help='Categories that automatically select this template during intake.', ) question_ids = fields.One2many( 'fusion.repair.intake.question', 'template_id', string='Questions', copy=True, ) question_count = fields.Integer( compute='_compute_question_count', string='Question Count', ) company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env.company, ) @api.depends('question_ids') def _compute_question_count(self): for tpl in self: tpl.question_count = len(tpl.question_ids) def action_view_questions(self): self.ensure_one() return { 'type': 'ir.actions.act_window', 'name': self.name, 'res_model': 'fusion.repair.intake.question', 'view_mode': 'list,form', 'domain': [('template_id', '=', self.id)], 'context': {'default_template_id': self.id}, }