<?xml version="1.0"?>

<!--
SPDX-FileCopyrightText: 2008-2026 Luis Falcón <falcon@gnuhealth.org>
SPDX-FileCopyrightText: 2011-2026 GNU Solidario <health@gnusolidario.org>

SPDX-License-Identifier: GPL-3.0-or-later
-->

<tryton>
    <data>


<!-- Add other relevant icons -->
        <record model="ir.ui.icon" id="gnuhealth_services_icon">
            <field name="name">gnuhealth-services</field>
            <field name="path">icons/folder-documents.svg</field>
        </record>



<!-- Replace icons -->

        <record model="ir.ui.icon" id="financial_icon">
            <field name="name">gnuhealth-financial</field>
            <field name="path">icons/tryton-financial.svg</field>
        </record>
        <menuitem name="Financial" id="account.menu_account" sequence="2"
            icon="gnuhealth-financial"/>

<!-- Health Services Menu -->

        <menuitem name="Health Services" id="gnuhealth_services_menu"
            parent="health.gnuhealth_menu" sequence="997" icon="gnuhealth-services"/>


<!-- Health service -->

        <record model="ir.ui.view" id="gnuhealth_health_service_view">
            <field name="model">gnuhealth.health_service</field>
            <field name="type">form</field>
            <field name="name">gnuhealth_health_service</field>
        </record>

        <record model="ir.ui.view" id="gnuhealth_health_service_tree">
            <field name="model">gnuhealth.health_service</field>
            <field name="type">tree</field>
            <field name="name">gnuhealth_health_service_tree</field>
        </record>


        <record model="ir.ui.view" id="gnuhealth_health_service_line_view">
            <field name="model">gnuhealth.health_service.line</field>
            <field name="type">form</field>
            <field name="name">gnuhealth_health_service_line</field>
        </record>


        <record model="ir.ui.view" id="gnuhealth_health_service_line_tree">
            <field name="model">gnuhealth.health_service.line</field>
            <field name="type">tree</field>
            <field name="name">gnuhealth_health_service_line_tree</field>
        </record>



        <record model="ir.action.act_window" id="gnuhealth_action_health_service">
            <field name="name">Health services</field>
            <field name="res_model">gnuhealth.health_service</field>
        </record>

        <record model="ir.action.act_window.view" id="act_health_service_list_view">
            <field name="sequence" eval="10"/>
            <field name="view" ref="gnuhealth_health_service_tree"/>
            <field name="act_window" ref="gnuhealth_action_health_service"/>
        </record>

        <record model="ir.action.act_window.view" id="act_health_service_form_view">
            <field name="sequence" eval="20"/>
            <field name="view" ref="gnuhealth_health_service_view"/>
            <field name="act_window" ref="gnuhealth_action_health_service"/>
        </record>


        <menuitem parent="gnuhealth_services_menu"
            action="gnuhealth_action_health_service"
            id="gnuhealth_health_service_menu" icon="gnuhealth-list"/>

<!-- Simple view of created health service invoices in the last month -->

        <record model="ir.action.act_window" id="gnuhealth_action_health_service_invoices">
            <field name="name">Service invoices (last month)</field>
            <field name="res_model">account.invoice</field>
            <field name="domain" eval="[('type', '=', 'out'), ('health_service', '!=', None), ('invoice_date', '>=', Date(delta_months=-1))]" pyson="1"/>
        </record>

        <menuitem parent="gnuhealth_services_menu"
            action="gnuhealth_action_health_service_invoices"
            id="gnuhealth_health_service_invoices_menu" icon="gnuhealth-list"/>

<!-- Shortcut to created invoice from health services -->

        <record model="ir.action.act_window" id="act_invoice_related_form1">
            <field name="name">Related Invoice</field>
            <field name="res_model">account.invoice</field>
            <field name="domain" eval="[('health_service', '=', Eval('active_id'))]" pyson="1"/>
        </record>
        <record model="ir.action.keyword"
                id="act_open_invoice_related_keyword1">
            <field name="keyword">form_relate</field>
            <field name="model">gnuhealth.health_service,-1</field>
            <field name="action" ref="act_invoice_related_form1"/>
        </record>

        
<!-- Window domains for Draft and Invoiced Documents -->

        <record model="ir.action.act_window.domain" id="act_gnuhealth_service_domain_draft">
            <field name="name">Draft</field>
            <field name="sequence" eval="10"/>
            <field name="domain" eval="[('state', '=', 'draft')]" pyson="1"/>
            <field name="act_window" ref="gnuhealth_action_health_service"/>
        </record>

        <record model="ir.action.act_window.domain" id="act_gnuhealth_service_domain_invoiced">
            <field name="name">Invoiced</field>
            <field name="sequence" eval="20"/>
            <field name="domain" eval="[('state', '=', 'invoiced')]" pyson="1"/>
            <field name="act_window" ref="gnuhealth_action_health_service"/>
        </record>

        <record model="ir.action.act_window.domain" id="act_gnuhealth_service_domain_all">
            <field name="name">All</field>
            <field name="sequence" eval="100"/>
<!--            <field name="domain"></field>/> -->
            <field name="act_window" ref="gnuhealth_action_health_service"/>
        </record>

<!-- Shortcut to services from the patient -->

        <record model="ir.action.act_window" id="act_service_form1">
            <field name="name">Services</field>
            <field name="res_model">gnuhealth.health_service</field>
            <field name="domain" eval="[('patient', '=', Eval('active_id'))]" pyson="1"/>
        </record>
        <record model="ir.action.keyword" id="act_open_service_keyword1">
            <field name="keyword">form_relate</field>
            <field name="model">gnuhealth.patient,-1</field>
            <field name="action" ref="act_service_form1"/>
        </record>


<!-- Extend prescription view to include the service -->

        <record model="ir.ui.view" id="view_prescription_form">
            <field name="model">gnuhealth.prescription.order</field>
            <field name="inherit" ref="health.gnuhealth_prescription_view" />
            <field name="name">gnuhealth_prescription</field>
        </record> 

<!-- Extend patient evaluation view to include the service -->

        <record model="ir.ui.view" id="view_evaluation_form">
            <field name="model">gnuhealth.patient.evaluation</field>
            <field name="inherit" ref="health.gnuhealth_patient_evaluation_view" />
            <field name="name">gnuhealth_patient_evaluation</field>
        </record>

        <!-- Buttons -->
        <record model="ir.model.button" id="servicepresc_update_button">
            <field name="name">update_service</field>
            <field name="string">Update Services</field>
            <field name="model" search="[('model', '=', 'gnuhealth.prescription.order')]"/>
        </record>

        <record model="ir.model.button" id="service_draft_button">
            <field name="name">button_set_to_draft</field>
            <field name="string">Set to Draft</field>
            <field name="model" search="[('model', '=', 'gnuhealth.health_service')]"/>
        </record>

        <record model="ir.model.button" id="serviceevaluation_update_button">
            <field name="name">update_service</field>
            <field name="string">Update Services</field>
            <field name="model" search="[('model', '=', 'gnuhealth.patient.evaluation')]"/>
        </record>

    </data>
</tryton>
