Files

70 lines
2.9 KiB
XML
Raw Permalink Normal View History

2026-07-01 14:41:49 +07:00
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- 🔹 Server Action: Dynamic URL with selected survey ID -->
<record id="action_survey_dashboard_dynamic" model="ir.actions.server">
<field name="name">Open Survey Dashboard</field>
<field name="model_id" ref="survey.model_survey_survey"/>
<field name="state">code</field>
<field name="code"><![CDATA[
if records:
action = {
'type': 'ir.actions.act_url',
'url': f'/survey/dashboard/{records[0].id}',
'target': 'self',
}
else:
# Show survey selector - using VALID fields only
action = {
'type': 'ir.actions.act_window',
'res_model': 'survey.survey',
'view_mode': 'list,form',
'name': 'Select a Survey',
'domain': [
('active', '=', True),
('user_input_ids', '!=', False)
],
'context': {'search_default_finished': 1},
'help': "Select an active survey with responses to view its dashboard.",
}
]]></field>
</record>
<!-- 🔹 Top-Level Menu: Surveys -->
<menuitem id="menu_survey_root" name="Dashboard Surveys" sequence="10" web_icon="survey,static/description/icon.png"/>
<!-- 🔹 Sub-Menu: Dashboard -->
<menuitem id="menu_survey_dashboard"
name="📊 Survey Dashboard"
parent="menu_survey_root"
action="action_survey_dashboard_dynamic"
sequence="5"
groups="survey.group_survey_manager,survey.group_survey_user"/>
<!-- 🔹 Optional: Keep "See Results" button on form -->
<record id="survey_form_inherit_dashboard" model="ir.ui.view">
<field name="name">survey.survey.form.inherit.dashboard</field>
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_survey_view_form"/>
<field name="arch" type="xml">
<!-- Option A: Add button AFTER existing results button (safer) -->
<xpath expr="//button[@name='action_result_survey']" position="after">
<button name="%(dashboard_survey.action_survey_dashboard_dynamic)d"
type="action"
string="📊 Dashboard"
class="btn btn-secondary ms-2"
icon="fa-chart-bar"/>
</xpath>
<!-- Option B: Replace (uncomment if you want to replace) -->
<!--
<xpath expr="//button[@name='action_result_survey']" position="replace">
<button name="%(dashboard_survey.action_survey_dashboard_dynamic)d"
type="action"
string="📊 See Dashboard"
class="oe_stat_button"
icon="fa-dashboard"/>
</xpath>
-->
</field>
</record>
</odoo>