<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="0">

        <record id="view_queue_job_form" model="ir.ui.view">
            <field name="name">queue.job.form</field>
            <field name="model">queue.job</field>
            <field name="arch" type="xml">
                <form string="Jobs" create="false"
                        delete="false" version="7.0">
                    <header>
                        <button name="requeue"
                            states="failed"
                            class="oe_highlight"
                            string="Requeue Job"
                            type="object"
                            groups="connector.group_connector_manager"/>
                        <button name="button_done"
                            states="pending,enqueued,failed"
                            class="oe_highlight"
                            string="Set to 'Done'"
                            type="object"
                            groups="connector.group_connector_manager"/>
                        <button name="open_related_action"
                            string="Related"
                            type="object"
                            />
                        <field name="state"
                            widget="statusbar"
                            statusbar_visible="pending,enqueued,started,done"
                            statusbar_colors='{"failed":"red","done":"green"}'/>
                    </header>
                    <sheet>
                        <h1>
                            <field name="name" class="oe_inline"/>
                        </h1>
                        <group>
                            <field name="uuid"/>
                            <field name="func_string"/>
                            <field name="job_function_id"/>
                            <field name="channel"/>
                        </group>
                        <group>
                            <group>
                                <field name="priority"/>
                                <field name="eta"/>
                                <field name="company_id" groups="base.group_multi_company"/>
                                <field name="user_id"/>
                            </group>
                            <group>
                                <field name="date_created"/>
                                <field name="date_enqueued"/>
                                <field name="date_started"/>
                                <field name="date_done"/>
                            </group>
                        </group>
                        <group colspan="4">
                            <div>
                                <label for="retry" string="Current try / max. retries" />
                                <field name="retry" class="oe_inline"/> /
                                <field name="max_retries" class="oe_inline"/>
                                <span class="oe_grey oe_inline"> If the max. retries is 0, the number of retries is infinite.</span>
                            </div>
                        </group>
                        <group name="result" string="Result" attrs="{'invisible': [('result', '=', False)]}">
                            <field nolabel="1" name="result"/>
                        </group>
                        <group name="exc_info" string="Exception Information" attrs="{'invisible': [('exc_info', '=', False)]}">
                            <field nolabel="1" name="exc_info"/>
                        </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>

        <record id="view_queue_job_tree" model="ir.ui.view">
            <field name="name">queue.job.tree</field>
            <field name="model">queue.job</field>
            <field name="arch" type="xml">
                <tree string="Jobs" create="false"
                        delete="false"
                        colors="red:state == 'failed';gray:state == 'done'">
                    <field name="name"/>
                    <field name="model_name"/>
                    <field name="state"/>
                    <field name="eta"/>
                    <field name="date_created"/>
                    <field name="date_done"/>
                    <field name="uuid"/>
                    <field name="channel"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                </tree>
            </field>
        </record>

        <record id="view_queue_job_search" model="ir.ui.view">
            <field name="name">queue.job.search</field>
            <field name="model">queue.job</field>
            <field name="arch" type="xml">
                <search string="Jobs">
                    <field name="uuid"/>
                    <field name="name"/>
                    <field name="func_string"/>
                    <field name="channel"/>
                    <field name="job_function_id"/>
                    <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                    <filter name="pending" string="Pending"
                        domain="[('state', '=', 'pending')]"/>
                    <filter name="enqueued" string="Enqueued"
                        domain="[('state', '=', 'enqueued')]"/>
                    <filter name="started" string="Started"
                        domain="[('state', '=', 'started')]"/>
                    <filter name="done" string="Done"
                        domain="[('state', '=', 'done')]"/>
                    <filter name="failed" string="Failed"
                        domain="[('state', '=', 'failed')]"/>
                    <filter name="created_last_24h" string="Created Last 24h"
                            domain="[('date_created','&gt;', (context_today() - datetime.timedelta(days=1)).strftime('%%Y-%%m-%%d') )]"/>
                    <group expand="0" string="Group By">
                        <filter string="Channel" context="{'group_by': 'channel'}" />
                        <filter string="Job Function" context="{'group_by': 'job_function_id'}" />
                        <filter string="State" context="{'group_by': 'state'}" />
                    </group>
                </search>
            </field>
        </record>

        <record id="action_queue_job" model="ir.actions.act_window">
            <field name="name">Jobs</field>
            <field name="res_model">queue.job</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{'search_default_pending': 1,
                                   'search_default_enqueued': 1,
                                   'search_default_started': 1,
                                   'search_default_failed': 1}</field>
            <field name="view_id" ref="view_queue_job_tree"/>
            <field name="search_view_id" ref="view_queue_job_search"/>
        </record>

        <record id="action_button_done_queue_job" model="ir.actions.server">
            <field name="name">Set to 'Done'</field>
            <field name="model_id" ref="model_queue_job"/>
            <field name="state">code</field>
            <field name="code"><![CDATA[
self.button_done(cr, uid, context['active_ids'], context=context)
]]></field>
        </record>

        <record model="ir.values" id="button_done_queue_job">
            <field name="name">Set to 'Done'</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.server,%d'%action_button_done_queue_job"/>
            <field name="model">queue.job</field>
        </record>

        <record id="view_requeue_job" model="ir.ui.view">
            <field name="name">Requeue Jobs</field>
            <field name="model">queue.requeue.job</field>
            <field name="arch" type="xml">
                <form string="Requeue Jobs" version="7.0">
                    <group string="The selected jobs will be requeued.">
                        <field name="job_ids" nolabel="1"/>
                    </group>
                    <footer>
                        <button name="requeue" string="Requeue" type="object" class="oe_highlight"/>
                        or
                        <button string="Cancel" class="oe_link" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>

        <record id="action_requeue_job" model="ir.actions.act_window">
            <field name="name">Requeue Jobs</field>
            <field name="res_model">queue.requeue.job</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_requeue_job"/>
            <field name="target">new</field>
        </record>

        <record id="action_requeue_job_values" model="ir.values">
            <field name="model_id" ref="model_queue_job" />
            <field name="name">Requeue Jobs</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.act_window,' + str(ref('action_requeue_job'))"/>
            <field name="key">action</field>
            <field name="model">queue.job</field>
        </record>

        <record id="view_queue_job_channel_form" model="ir.ui.view">
            <field name="name">queue.job.channel.form</field>
            <field name="model">queue.job.channel</field>
            <field name="arch" type="xml">
                <form string="Channels" version="7.0">
                    <group>
                        <field name="name" attrs="{'required': [('name', '!=', 'root')], 'readonly': [('name', '=', 'root')]}"/>
                        <field name="parent_id" attrs="{'required': [('name', '!=', 'root')], 'readonly': [('name', '=', 'root')]}"/>
                        <field name="complete_name"/>
                    </group>
                    <group>
                      <field name="job_function_ids" widget="many2many_tags"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="view_queue_job_channel_tree" model="ir.ui.view">
            <field name="name">queue.job.channel.tree</field>
            <field name="model">queue.job.channel</field>
            <field name="arch" type="xml">
                <tree string="Channels" version="7.0">
                    <field name="complete_name"/>
                </tree>
            </field>
        </record>

        <record id="view_queue_job_channel_search" model="ir.ui.view">
            <field name="name">queue.job.channel.search</field>
            <field name="model">queue.job.channel</field>
            <field name="arch" type="xml">
                <search string="Channels">
                    <field name="name"/>
                    <field name="complete_name"/>
                    <field name="parent_id"/>
                </search>
            </field>
        </record>

        <record id="action_queue_job_channel" model="ir.actions.act_window">
            <field name="name">Channels</field>
            <field name="res_model">queue.job.channel</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{}</field>
            <field name="view_id" ref="view_queue_job_channel_tree"/>
        </record>

        <record id="view_queue_job_function_form" model="ir.ui.view">
            <field name="name">queue.job.function.form</field>
            <field name="model">queue.job.function</field>
            <field name="arch" type="xml">
                <form string="Job Functions" create="false" delete="false" version="7.0">
                    <group>
                        <field name="name" readonly="1"/>
                        <field name="channel_id"/>
                    </group>
                </form>
            </field>
        </record>

        <record id="view_queue_job_function_tree" model="ir.ui.view">
            <field name="name">queue.job.function.tree</field>
            <field name="model">queue.job.function</field>
            <field name="arch" type="xml">
                <tree string="Job Functions" create="false" delete="false" version="7.0">
                    <field name="name"/>
                    <field name="channel_id"/>
                </tree>
            </field>
        </record>

        <record id="view_queue_job_function_search" model="ir.ui.view">
            <field name="name">queue.job.function.search</field>
            <field name="model">queue.job.function</field>
            <field name="arch" type="xml">
                <search string="Job Functions">
                    <field name="name"/>
                    <field name="channel_id"/>
                    <group expand="0" string="Group By">
                        <filter string="Channel" context="{'group_by': 'channel_id'}" />
                    </group>
                </search>
            </field>
        </record>

        <record id="action_queue_job_function" model="ir.actions.act_window">
            <field name="name">Job Functions</field>
            <field name="res_model">queue.job.function</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="context">{}</field>
            <field name="view_id" ref="view_queue_job_function_tree"/>
        </record>

    </data>
</openerp>
