<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- Routings Workcenter -->
        <record id="mrp_routing_workcenter_tree_view" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.tree</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="arch" type="xml">
                <tree string="Routing Work Centers">
                    <field name="sequence" widget="handle"/>
                    <field name="name"/>
                    <field name="workcenter_id"/>
                    <field name="time_cycle" widget="float_time"/>
                    <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
                </tree>
            </field>
        </record>
        <record id="mrp_routing_workcenter_form_view" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.form</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="arch" type="xml">
                <form string="Routing Work Centers">
                    <sheet>
                        <group>
                            <group name="description">
                                <field name="name"/>
                                <field name="workcenter_id"/>
                                <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
                                <field name="sequence" groups="base.group_no_one"/>
                            </group><group name="workorder">
                                <field name="workorder_count" invisible="1"/>
                                <field name="time_mode" widget="radio"/>
                                <label for="time_mode_batch" attrs="{'invisible': [('time_mode', '=', 'manual')]}"/>
                                <div attrs="{'invisible': [('time_mode', '=', 'manual')]}">
                                    last
                                    <field name="time_mode_batch" class="oe_inline"/>
                                    work orders
                                </div>
                                <label for="time_cycle_manual" attrs="{'invisible': [('time_mode', '=', 'auto'), ('workorder_count', '!=' , 0)]}" string="Default Duration"/>
                                <div attrs="{'invisible':  [('time_mode', '=', 'auto'), ('workorder_count', '!=' , 0)]}">
                                    <field name="time_cycle_manual" widget="float_time" class="oe_inline"/> minutes
                                </div>
                                <field name="time_cycle" invisible="1"/>
                            </group>
                        </group>
                        <notebook>
                            <page string="Description">
                                <field name="note"/>
                            </page>
                            <page string="Work Sheet">
                                <field name="worksheet" widget="pdf_viewer"/>
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>


        <!-- Routings -->
        <record id="mrp_routing_form_view" model="ir.ui.view">
            <field name="name">mrp.routing.form</field>
            <field name="model">mrp.routing</field>
            <field name="arch" type="xml">
                <form string="Routing">
                    <sheet>
                        <div class="oe_button_box" name="button_box">
                            <button name="%(action_mrp_routing_time)d" type="action" class="oe_stat_button" icon="fa-clock-o">
                                <div class="o_field_widget o_stat_info">
                                    <span class="o_stat_text">Time<br/> Analysis</span>
                                </div>
                            </button>
                            <button class="oe_stat_button" name="toggle_active" type="object" icon="fa-archive">
                                <field name="active" widget="boolean_button"
                                    options='{"terminology": "archive"}'/>
                            </button>
                        </div>
                        <div class="oe_title">
                            <h1>
                                <field name="code"/>
                            </h1>
                        </div>
                        <group>
                            <group>
                                <field name="name"/>
                            </group>
                            <group>
                                <field name="location_id" groups="stock.group_adv_location" domain="[('usage', '!=', 'view')]"/>
                                <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
                           </group>
                        </group>
                        <notebook>
                            <page string="Work Center Operations">
                                <field name="operation_ids"/>
                            </page>
                            <page string="Notes">
                                <field name="note"/>
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>
        <record id="mrp_routing_tree_view" model="ir.ui.view">
            <field name="name">mrp.routing.tree</field>
            <field name="model">mrp.routing</field>
            <field name="arch" type="xml">
                <tree string="Routing">
                    <field name="code"/>
                    <field name="name"/>
                    <field name="active" invisible="1"/>
                    <field name="location_id" groups="stock.group_adv_location"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                </tree>
            </field>
        </record>

        <record id="mrp_routing_kanban_view" model="ir.ui.view">
            <field name="name">mrp.routing.kanban</field>
            <field name="model">mrp.routing</field>
            <field name="arch" type="xml">
                <kanban class="o_kanban_mobile">
                    <field name="code"/>
                    <field name="name"/>
                    <templates>
                        <t t-name="kanban-box">
                            <div t-attf-class="oe_kanban_card oe_kanban_global_click">
                                <div class="o_kanban_record_top">
                                    <div class="o_kanban_record_headings mt4">
                                        <strong class="o_kanban_record_title"><span><t t-esc="record.name.value"/></span></strong>
                                    </div>
                                    <span class="badge badge-pill"><field name="code"/></span>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="mrp_routing_search_view" model="ir.ui.view">
            <field name="name">mrp.routing.search</field>
            <field name="model">mrp.routing</field>
            <field name="arch" type="xml">
                <search string="Routing">
                    <field name="name" string="Routing" filter_domain="['|',('name','ilike',self),('code','ilike',self)]"/>
                    <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                    <field name="location_id"/>
                    <field name="company_id" groups="base.group_multi_company"/>
                    <group expand="0" string="Group By...">
                        <filter string="Production Location" name="production_location" domain="[]" context="{'group_by':'location_id'}"/>
                    </group>
                </search>
            </field>
        </record>
        <record id="mrp_routing_action" model="ir.actions.act_window">
            <field name="name">Routings</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">mrp.routing</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,kanban,form</field>
            <field name="view_id" ref="mrp_routing_tree_view"/>
            <field name="search_view_id" ref="mrp_routing_search_view"/>
            <field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                Create a new routing
              </p><p>
                Routings define the successive operations that need to be
                done to realize a Manufacturing Order. Each operation from
                a Routing is done at a specific Work Center and has a specific duration.
              </p>
            </field>
        </record>
        <menuitem id="menu_mrp_routing_action"
          action="mrp_routing_action"
          parent="menu_mrp_bom"
          groups="group_mrp_routings"
          sequence="50"/>
    </data>
</odoo>
