<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record id="pos_config_view_form" model="ir.ui.view">
        <field name="name">pos.config.form.view</field>
        <field name="model">pos.config</field>
        <field name="arch" type="xml">
            <form string="Point of Sale Configuration">
                <sheet>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <field name="active" invisible="1"/>
                    <field name="company_has_template" invisible="1"/>
                    <field name="has_active_session" invisible="1"/>
                    <field name="other_devices" invisible="1"/>
                    <field name="module_pos_hr" invisible="1"/>

                    <div class="oe_title" id="title">
                        <label for="name"/>
                        <h1><field name="name" placeholder="e.g. NYC Shop"/></h1>
                    </div>
                    <!-- HIDE this div in create_mode (when '+ New Shop' is clicked in the general settings.) -->
                    <div invisible="context.get('pos_config_create_mode', False)">
                        <div class="o_notification_alert alert alert-warning" invisible="not has_active_session" role="alert">
                            A session is currently opened for this PoS. Some settings can only be changed after the session is closed.
                            <button class="btn" style="padding:0" name="close_ui" type="object">Click here to close the session</button>
                        </div>
                        <div class="o_notification_alert alert alert-warning" invisible="company_has_template" role="alert">
                            There is no Chart of Accounts configured on the company. Please go to the invoicing settings to install a Chart of Accounts.
                        </div>
                    </div>

                    <!-- SHOW this div in create_mode (when '+ New Shop' is clicked in the general settings.) -->
                    <div id="restaurant_on_create" class="row mt16 o_settings_container" invisible="not context.get('pos_config_create_mode', False)">
                        <setting>
                                <field name="module_pos_restaurant" />
                        </setting>
                    </div>

                    <!-- HIDE this div in create_mode (when '+ New Shop' is clicked in the general settings.) -->
                    <div invisible="context.get('pos_config_create_mode', False)">
                        <notebook>
                            <page string="Configuration" name="configuration">
                                <div class="row mt16 o_settings_container">
                                    <setting id = "multiple_employee_session"
                                            title="Employees can scan their badge or enter a PIN to log in to a PoS session. These credentials are configurable in the *HR Settings* tab of the employee form."
                                            string="Log in with Employees"
                                            help="Allow to log and switch between selected Employees">
                                        <field name="module_pos_hr" readonly="has_active_session" />
                                        <div class="content-group mt16" invisible="not module_pos_hr">
                                            <div class="text-warning" id="warning_text_employees">
                                                Save this page and come back here to set up the feature.
                                            </div>
                                        </div>
                                    </setting>
                                    <setting id="other_devices" string="Receipt Printers" help="Connect printers to your PoS">
                                        <field name="other_devices" />
                                        <div class="content-group" invisible="not other_devices">
                                            <div class="row mb-2">
                                                <div class="col-lg-2 o_light_label">
                                                    <label string="Available" for="receipt_printer_ids"/>
                                                </div>
                                                <div class="col-lg-5">
                                                    <field name="receipt_printer_ids"
                                                        class="w-100 pt-1"
                                                        widget="many2many_tags"
                                                        context="{'default_use_type': 'receipt'}"
                                                        options="{'no_quick_create': True}"/>
                                                </div>
                                                <div class="col-lg-5">
                                                    <widget name="point_of_sale_test_epos"/>
                                                </div>
                                                <div class="col-lg-2 o_light_label">
                                                    <label string="Default" for="default_receipt_printer_id"/>
                                                </div>
                                                <div class="col-lg-10">
                                                    <field name="default_receipt_printer_id" domain="[('id', 'in', receipt_printer_ids)]" required="other_devices" options="{'no_quick_create': True}"/>
                                                </div>
                                                <div class="col-lg-6 o_light_label">
                                                    <label string="Link Cashdrawer" for="iface_cashdrawer"/>
                                                </div>
                                                <div class="col-lg-6">
                                                    <field name="iface_cashdrawer"/>
                                                </div>
                                            </div>
                                        </div>
                                    </setting>
                                    <setting id="preparation_devices" string="Preparation Printers" help="Connect preparation printers to your PoS">
                                        <field name="preparation_devices"/>
                                        <div class="content-group" invisible="not preparation_devices">
                                            <div class="row mb-2">
                                                <div class="col-lg-2 o_light_label">
                                                    <label string="Available" for="preparation_printer_ids"/>
                                                </div>
                                                <div class="col-lg-5">
                                                    <field name="preparation_printer_ids"
                                                        class="w-100 pt-1"
                                                        widget="many2many_tags"
                                                        context="{'default_use_type': 'preparation'}"
                                                        options="{'no_quick_create': True}"/>
                                                </div>
                                            </div>
                                        </div>
                                    </setting>
                                </div>
                            </page>
                            <page name="checklist" string="Check list">
                                <widget name="lna_checklist" />
                            </page>
                        </notebook>
                        <div groups="base.group_system">
                            <p>
                                More settings: <a href="#" name="%(action_pos_configuration)d" type="action" class="btn-link o_form_uri" role="button">Configurations > Settings</a>
                            </p>
                        </div>
                    </div>
                </sheet>

                <!-- Replace the default save/discard buttons so that when any of the buttons is clicked, the modal immediately closes. -->
                <footer invisible="not context.get('pos_config_open_modal', False)">
                    <button string="Save" special="save" class="btn-primary"/>
                    <button class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="view_pos_config_tree" model="ir.ui.view">
        <field name="name">pos.config.list.view</field>
        <field name="model">pos.config</field>
        <field name="arch" type="xml">
            <list string="Point of Sale Configuration">
                <field name="name" />
                <field name="company_id"  options="{'no_create': True}" groups="base.group_multi_company"/>
                <field name="last_session_closing_date" string="Closing"/>
                <field name="currency_id" column_invisible="True"/>
                <field name="last_session_closing_cash" widget="monetary" string="Balance"/>
            </list>
        </field>
    </record>

    <record id="view_pos_config_search" model="ir.ui.view">
        <field name="name">pos.config.search.view</field>
        <field name="model">pos.config</field>
        <field name="arch" type="xml">
            <search string="Point of Sale Config">
                <field name="name"/>
                <field name="picking_type_id" />
                <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
            </search>
        </field>
    </record>

    <record id="action_pos_config_kanban" model="ir.actions.act_window">
        <field name="name">Point of Sale</field>
        <field name="path">point-of-sale</field>
        <field name="res_model">pos.config</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="domain"></field>
        <field name="search_view_id" ref="view_pos_config_search" />
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new PoS
            </p><p>
                Configure at least one Point of Sale.
            </p>
        </field>
    </record>

    <record id="action_pos_config_tree" model="ir.actions.act_window">
        <field name="name">Point of Sale List</field>
        <field name="res_model">pos.config</field>
        <field name="view_mode">list,form</field>
        <field name="domain"></field>
        <field name="search_view_id" ref="view_pos_config_search" />
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new PoS
            </p><p>
                Configure at least one Point of Sale.
            </p>
        </field>
    </record>

    <!-- Products sub Category -->
    <menuitem id="menu_products_pos_category"
        action="point_of_sale.product_pos_category_action"
        parent="point_of_sale.pos_menu_products_configuration"
        sequence="1"/>
    <menuitem id="pos_menu_products_attribute_action"
        action="product.attribute_action"
        parent="point_of_sale.pos_menu_products_configuration"  groups="product.group_product_variant" sequence="2"/>

    <menuitem id="menu_pos_dashboard" action="action_pos_config_kanban" parent="menu_point_root" name="Dashboard" sequence="1"/>

</odoo>
