<?xml version="1.0" encoding="utf-8" ?>
<!--
    Copyright 2017-19 Tecnativa - David Vidal
    Copyright 2021 Moka Tourisme (https://www.mokatourisme.fr)
    License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
    <record id="sale_order_view_form" model="ir.ui.view">
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="event_sale.sale_order_view_form" />
        <field name="arch" type="xml">
            <xpath
                expr="//field[@name='order_line']//form//field[@name='event_id']"
                position="after"
            >
                <field name="event_use_sessions" invisible="1" />
                <field
                    name="event_session_id"
                    domain="[
                        ('event_id', '=', event_id),
                        ('date_end', '&gt;=', time.strftime('%Y-%m-%d 00:00:00')),
                    ]"
                    attrs="{
                       'invisible': [('event_use_sessions', '=', False)],
                       'required': [('event_use_sessions', '=', True)],
                    }"
                    options="{'no_open': True, 'no_create': True}"
                />
            </xpath>
            <xpath
                expr="//field[@name='order_line']//tree//field[@name='event_id']"
                position="after"
            >
                <field name="event_use_sessions" invisible="1" />
                <field
                    name="event_session_id"
                    domain="[
                        ('event_id', '=', event_id),
                        ('date_end', '&gt;=', time.strftime('%Y-%m-%d 00:00:00')),
                    ]"
                    attrs="{
                       'invisible': [('event_use_sessions', '=', False)],
                       'required': [('event_use_sessions', '=', True)],
                    }"
                    options="{'no_open': True, 'no_create': True}"
                    optional="hide"
                />
            </xpath>
        </field>
    </record>
</odoo>
