<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
  <data>
    <!-- Trees -->
    <record model="ir.ui.view" id="golem_resource_pack_view_tree">
      <field name="name">GOLEM Resource Pack Tree</field>
      <field name="model">golem.resource.pack</field>
      <field name="arch" type="xml">
        <tree colors="black: state=='draft'; blue: state=='validated'; green : state=='validated'; grey: state=='canceled'; orange: state=='rejected'">
          <field name="name" />
          <field name="partner_id" />
          <field name="state" />
          <field name="reservation_count" />
        </tree>
      </field>
    </record>

    <!-- Forms -->
    <record model="ir.ui.view" id="golem_resource_pack_view_form">
      <field name="name">GOLEM Resource Pack Form</field>
      <field name="model">golem.resource.pack</field>
      <field name="arch" type="xml">
        <form>
          <header>
            <button name="state_confirm" type="object" string="Confirm" class="oe_highlight"
              attrs="{'invisible': ['|', ('state', 'not in', 'draft'), ('id', '=', False)]}" />
            <button name="state_canceled" type="object"
              string="Cancel" states="confirmed,validated" />
            <button name="state_draft" type="object" string="Set to draft"
              states="canceled,confirmed,validated,rejected" />
            <button name="state_validated" type="object" string="Validate"
              states="confirmed" class="oe_highlight"
              groups="golem_base.group_golem_manager" />
            <button name="state_rejected" type="object" string="Reject"
              states="confirmed" class="oe_highlight"
              groups="golem_base.group_golem_manager" />
            <field name="state" widget="statusbar" />
          </header>
          <sheet>
            <group>
              <group name="general" string="Pack" colspan="2">
                <field name="id" invisible="1"/>
                <field name="name" />
                <field name="user_id" />
                <field name="partner_id" />
                <field name="note" />

                <field name="rejection_reason"
                  attrs="{'invisible': [('state', '!=', 'rejected')]}"/>

              </group>
              <group>
                <button name="quick_reservation" type="object"
                  string="Quick Reservation" states="draft" class="oe_highlight" />
              </group>
              <group colspan="2" name="reservations">
                <field name="reservation_ids" widget="many2many"
                   context="{'default_partner_id' : partner_id, 'default_pack_id': active_id, 'search_default_state_draft': 1, 'search_default_partner_id': partner_id}" />
              </group>
            </group>
          </sheet>
          <div class="oe_chatter">
              <field name="message_follower_ids" widget="mail_followers" />
              <field name="message_ids" widget="mail_thread" />
          </div>
        </form>
      </field>
    </record>

    <!-- Actions -->
    <act_window id="golem_resource_pack_action" name="Reservation Pack"
      res_model="golem.resource.pack" view_mode="tree,form" />

    <!-- Menus -->
    <menuitem id="golem_resource_packs_menu" name="Reservation Packs"
      parent="golem_resource.golem_resource_menu" action="golem_resource_pack_action"
      sequence="20" />

  </data>
</odoo>