<?xml version="1.0"?>
<openerp>
    <data>

        <menuitem  id="menu_project_confi" name="Issues" parent="base.menu_definitions" sequence="2"/>

        <record model="ir.ui.view" id="project_issue_version_search_view">
            <field name="name">Issue Version</field>
            <field name="model">project.issue.version</field>
            <field name="arch" type="xml">
                <search string="Issue Version">
                    <field name="name" string="Issue Version"/>
                    <field name="active"/>
                </search>
            </field>
        </record>
        <record model="ir.ui.view" id="project_issue_version_form_view">
            <field name="name">Issue Version</field>
            <field name="model">project.issue.version</field>
            <field name="arch" type="xml">
                <form string="Issue Version" version="7.0">
                    <group col="2">
                        <field name="name"/>
                        <field name="active"/>
                    </group>
                </form>
            </field>
        </record>
        <record id="project_issue_version_action" model="ir.actions.act_window">
            <field name="name">Versions</field>
            <field name="res_model">project.issue.version</field>
            <field name="view_type">form</field>
            <field name="help" type="html">
              <p class="oe_view_nocontent_create">
                Click to add a new version.
              </p><p>
                Define here the different versions of your products on which
                you can work on issues.
              </p>
            </field>
        </record>
        <menuitem action="project_issue_version_action" id="menu_project_issue_version_act" parent="menu_project_confi" groups="base.group_no_one"/>


        <record model="ir.ui.view" id="project_issue_form_view">
            <field name="name">Project Issue Tracker Form</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <form string="Issue" version="7.0">
                <header>
                    <button name="case_close" string="Done" type="object"
                            states="open" groups="base.group_user"/>
                    <button name="case_close" string="Done" type="object"
                            states="draft,pending" groups="base.group_user"/>
                    <button name="case_cancel" string="Cancel Issue" type="object"
                            states="draft,open,pending" groups="base.group_user"/>
                    <field name="stage_id" widget="statusbar" clickable="True"/>
                </header>
                <sheet string="Issue">
                    <label for="name" class="oe_edit_only"/>
                    <h1><field name="name"/></h1>
                    <label for="categ_ids" class="oe_edit_only"/>
                    <field name="categ_ids" widget="many2many_tags"/>
                    <group>
                        <group groups="base.group_user">
                            <field name="user_id"/>
                            <field name="partner_id"  on_change="onchange_partner_id(partner_id, email_from)"/>
                            <field name="email_from"/>
                            <label for="project_id" groups="base.group_user"/>
                            <div groups="base.group_user">
                                <field name="project_id" on_change="on_change_project(project_id)" class="oe_inline" context="{'default_use_issues':1}"/>
                                <button name="case_escalate" string="⇒ Escalate" type="object" states="draft,open,pending" class="oe_link"/>
                            </div>
                        </group>
                        <group>
                            <field name="id"/>
                            <field name="version_id" groups="base.group_user"/>
                            <field name="priority" groups="base.group_user"/>
                            <label for="task_id" groups="base.group_user"/>
                            <div groups="base.group_user">
                                <field name="task_id" on_change="onchange_task_id(task_id)" class="oe_inline" context="{'default_project_id':project_id}"/>
                                <field name="progress" widget="progressbar" attrs="{'invisible':[('task_id','=',False)]}" class="oe_inline"/>
                            </div>
                        </group>
                    </group>
                    <notebook>
                        <page string="Description">
                            <field name="description" placeholder="Add an internal note..." groups="base.group_user"/>
                        </page>
                        <page string="Extra Info" groups="project.group_project_manager">
                            <group string="Statistics">
                                <field name="day_open"/>
                                <field name="day_close"/>
                                <field name="working_hours_open" widget="float_time"/>
                                <field name="working_hours_close" widget="float_time"/>
                                <field name="inactivity_days"/>
                                <field name="days_since_creation"/>
                            </group>
                            <group string="Status" groups="base.group_no_one">
                                <field name="active"/>
                                <field name="state" string="Status"/>
                            </group>
                        </page>
                    </notebook>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="project_issue_tree_view">
            <field name="name">Project Issue Tracker Tree</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <tree string="Issue Tracker Tree" fonts="bold:message_unread==True" colors="black:state=='open';blue:state=='pending';grey:state in ('cancel', 'done')">
                    <field name="message_unread" invisible="1"/>
                    <field name="id"/>
                    <field name="name"/>
                    <field name="partner_id"/>
                    <field name="project_id"/>
                    <field name="priority" string="Priority" groups="base.group_user"/>
                    <field name="create_date"/>
                    <field name="version_id" widget="selection"/>
                    <field name="user_id"/>
                    <field name="progress" widget="progressbar" attrs="{'invisible':[('task_id','=',False)]}"/>
                    <field name="stage_id" widget="selection" readonly="1"/>
                    <field name="state" invisible="1"/>
                    <field name="categ_ids" invisible="1"/>
                    <field name="task_id" invisible="1"/>
                </tree>
            </field>
        </record>

        <record id="view_project_issue_filter" model="ir.ui.view">
            <field name="name">Project Issue Tracker Search</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <search string="Issue Tracker Search">
                    <field name="name" string="Issue" filter_domain="['|', '|',('partner_id','child_of',self),('email_from','ilike',self),('name','ilike',self)]"/>
                    <field name="id"/>
                    <filter icon="terp-mail-message-new" string="Unread Messages" name="message_unread" domain="[('message_unread','=',True)]"/>
                    <separator/>
                    <filter string="New" icon="terp-document-new" domain="[('state','=','draft')]" help="New Issues"/>
                    <filter string="To Do" domain="[('state','=','open')]" help="To Do Issues" icon="terp-check"/>
                    <separator/>
                    <filter string="Unassigned Issues" domain="[('user_id','=',False)]"  help="Unassigned Issues" icon="terp-personal-"/>
                    <field name="user_id"/>
                    <field name="project_id"/>
                    <field name="categ_ids"/>
                    <field name="partner_id" operator="child_of"/>
                    <group expand="0" string="Group By..." >
                        <filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
                        <filter string="Contact" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}"/>
                        <filter string="Project"  icon="terp-folder-violet" domain="[]" context="{'group_by':'project_id'}"/>
                        <filter string="Version" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'version_id'}"/>
                        <filter string="Priority" icon="terp-rating-rated" domain="[]" context="{'group_by':'priority'}"/>
                        <filter string="Stage" icon="terp-stage" domain="[]" context="{'group_by':'stage_id'}"/>
                        <filter string="Month" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}" help="Creation Month"/>
                    </group>
                </search>
            </field>
        </record>

        <record model="ir.ui.view" id="project_issue_calendar_view">
            <field name="name">Project Issue Tracker Calendar</field>
            <field name="model">project.issue</field>
            <field name="priority" eval="2"/>
            <field name="arch" type="xml">
                <calendar string="Issues" date_start="date" color="user_id" date_delay="duration">
                    <field name="name"/>
                    <field name="partner_id"/>
                </calendar>
            </field>
        </record>


        <!-- Project Issue Karban View-->

        <record model="ir.ui.view" id="project_issue_kanban_view">
            <field name="name">Project Issue Kanban</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <kanban default_group_by="stage_id">
                    <field name="stage_id"/>
                    <field name="color"/>
                    <field name="priority"/>
                    <field name="user_email"/>
                    <field name="user_id"/>
                    <field name="date_deadline"/>
                    <field name="kanban_state"/>
                    <field name="message_summary"/>
                    <templates>
                        <t t-name="kanban-tooltip">
                           <ul class="oe_kanban_tooltip">
                              <li><b>Project:</b> <field name="project_id"/></li>
                              <li><b>Category:</b> <field name="categ_ids"/></li>
                           </ul>
                        </t>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_semantic_html_override">
                                <div class="oe_dropdown_toggle oe_dropdown_kanban" groups="base.group_user">
                                    <span class="oe_e">i</span>
                                    <ul class="oe_dropdown_menu">
                                        <t t-if="widget.view.is_action_enabled('edit')"><li><a type="edit">Edit...</a></li></t>
                                        <t t-if="widget.view.is_action_enabled('delete')"><li><a type="delete">Delete</a></li></t>
                                        <li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
                                    </ul>
                                </div>
                                <div class="oe_kanban_content" tooltip="kanban-tooltip">
                                    <div>
                                        <b><field name="name"/></b> <br/>
                                        <field name="partner_id"/> <br/>
                                        <field name="version_id"/>
                                    </div>
                                    <div class="oe_kanban_footer_left">
                                        <field name="categ_ids"/>
                                        <div class="oe_right">
                                            <span class="oe_kanban_highlight" groups="base.group_user">
                                                <a t-if="record.kanban_state.raw_value === 'normal'" type="object" string="In Progress" name="set_kanban_state_done" class="oe_kanban_status"> </a>
                                                <a t-if="record.kanban_state.raw_value === 'done'" type="object" string="Ready for next stage" name="set_kanban_state_blocked" class="oe_kanban_status oe_kanban_status_green"> </a>
                                                <a t-if="record.kanban_state.raw_value === 'blocked'" type="object" string="Blocked" name="set_kanban_state_normal" class="oe_kanban_status oe_kanban_status_red"> </a>
                                                <t t-set="priority" t-value="record.priority.raw_value || 5"/>
                                                <a type="object" name="set_priority" args="['3']" t-if="priority gt 3" title="Normal Priority">
                                                   <img src="/web/static/src/img/icons/star-off.png" width="16" height="16"/>
                                                </a>
                                                <a type="object" name="set_priority" args="['5']" t-if="priority lte 3" title="Normal Priority">
                                                   <img t-attf-src="/web/static/src/img/icons/star-#{priority lte 3 ? 'on' : 'off'}.png" width="16" height="16"/>
                                                </a>
                                                <a type="object" name="set_priority" args="['2']" title="High Priority">
                                                   <img t-attf-src="/web/static/src/img/icons/star-#{priority lte 2 ? 'on' : 'off'}.png" width="16" height="16"/>
                                                </a>
                                                <a type="object" name="set_priority" args="['1']" title="Highest Priority">
                                                   <img t-attf-src="/web/static/src/img/icons/star-#{priority == 1 ? 'on' : 'off'}.png" width="16" height="16"/>
                                                </a>
                                            </span>
                                            <t t-if="record.date_deadline.raw_value and record.date_deadline.raw_value lt (new Date())">
                                                <span t-attf-class="oe_kanban_status oe_kaban_status_red"> </span>
                                            </t>
                                            <img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" t-att-title="record.user_id.value" width="24" height="24" class="oe_kanban_avatar"/>
                                        </div>
                                    </div>
                                    <div class="oe_kanban_footer_left">
                                        <t t-raw="record.message_summary.raw_value"/>
                                    </div>
                                </div>
                                <div class="oe_clear"></div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>


        <!-- Feature Requests -->
        <record model="ir.ui.view" id="project_feature_tree_view">
            <field name="name">Project Issue- Feature Tracker Tree</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <tree string="Feature Tracker Tree" fonts="bold:message_unread==True" colors="red:state=='open';black:state in ('draft', 'cancel','done','pending')">
                    <field name="id"/>
                    <field name="message_unread" invisible="1"/>
                    <field name="name" string="Feature description"/>
                    <field name="partner_id"/>
                    <field name="priority" string="Priority"/>
                    <field name="version_id"/>
                    <field name="user_id"/>
                    <field name="stage_id" widget="selection" readonly="1"/>
                    <field name="state" groups="base.group_no_one"/>
                </tree>
            </field>
        </record>

        <record id="view_project_feature_filter" model="ir.ui.view">
            <field name="name">Project Issue - Feature Tracker Search</field>
            <field name="model">project.issue</field>
            <field name="arch" type="xml">
                <search string="Feature Tracker Search">
                    <field name="name" string="Feature description"/>
                    <field name="date"/>
                    <field name="state" groups="base.group_no_one"/>
                    <filter icon="terp-check" domain="[('state','in',('open','draft'))]" help="Current Features" name="current_feature"/>
                    <filter icon="terp-camera_test" domain="[('state','=','open')]" help="Open Features"/>
                    <field name="user_id"/>
                    <field name="project_id" string="Project"/>
                </search>
            </field>
        </record>

        <record id="act_project_project_2_project_issue_all" model="ir.actions.act_window">
            <field name="res_model">project.issue</field>
            <field name="view_type">form</field>
            <field name="name">Issues</field>
            <field name="view_mode">kanban,tree,form,calendar,graph</field>
            <field name="context">{'search_default_project_id': [active_id], 'default_project_id': active_id}</field>
        </record>

        <!-- Project -->
        <record id="view_project_form_inherited" model="ir.ui.view">
            <field name="name">project.project.form.inherited</field>
            <field name="model">project.project</field>
            <field name="inherit_id" ref="project.edit_project"/>
            <field name="arch" type="xml">
                <xpath expr='//div[@name="options_active"]' position='inside'>
                    <field name="use_issues" class="oe_inline"/>
                    <label for="use_issues"/>
                </xpath>
                <xpath expr='//div[@name="buttons"]' position='inside'>
                    <button name="%(act_project_project_2_project_issue_all)d" string="Issues" type="action" attrs="{'invisible':[('use_issues','=', 0)]}"/>
                </xpath>
                <xpath expr='//page[@name="project_stages"]' position="attributes">
                    <attribute name="attrs">{'invisible': [('use_tasks', '=', False),('use_issues','=',False)]}</attribute>
                </xpath>
                <field name="priority" position="before">
                    <field name="project_escalation_id"/>
                </field>
                <field name="alias_domain" position="after">
                    <label for="alias_model" class="oe_edit_only" string="creates"/><field name="alias_model" class="oe_edit_only oe_inline"/>
                </field>
            </field>
       </record>

        <record id="view_project_kanban_inherited" model="ir.ui.view">
            <field name="name">project.project.kanban.inherited</field>
            <field name="model">project.project</field>
            <field name="inherit_id" ref="project.view_project_kanban"/>
            <field name="arch" type="xml">
                <field name="use_tasks" position="after">
                    <field name="use_issues"/>
                    <field name="issue_count" invisible="1"/>
                </field>
                <xpath expr="//div[contains(@class, 'oe_kanban_project_list')]" position="inside">
                    <a t-if="record.use_issues.raw_value" style="margin-right: 10px"
                        name="%(act_project_project_2_project_issue_all)d" type="action">
                        <span t-if="record.issue_count.raw_value gt 1"><field name="issue_count"/> Issues</span>
                        <span t-if="record.issue_count.raw_value lt 2"><field name="issue_count"/> Issue</span>
                    </a>
                </xpath>
            </field>
        </record>

        <record id="analytic_account_inherited_issue_form" model="ir.ui.view">
            <field name="name">account.analytic.account.issue.form.inherit</field>
            <field name="model">account.analytic.account</field>
            <field name="inherit_id" ref="project.analytic_account_inherited_form"/>
            <field eval="18" name="priority"/>
            <field name="arch" type="xml">
                <xpath expr='//div[@name="project"]' position='inside'>
                    <field name="use_issues"/>
                    <label for="use_issues"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>
