<?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.list</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="arch" type="xml">
                <list string="Routing Work Centers" multi_edit="1">
                    <field name="active" column_invisible="True"/>
                    <field name="company_id" column_invisible="True"/>
                    <field name="name"/>
                    <field name="bom_id" column_invisible="context.get('bom_id_invisible', False)"/>
                    <field name="workcenter_id"/>
                    <field name="time_cycle" widget="float_time" string="Duration (minutes)"/>
                    <field name="time_total" widget="float_time" string="Total Duration (minutes)" optional="hide"/>
                    <field name="company_id" optional="hide" groups="base.group_multi_company"/>
                    <field name="possible_bom_product_template_attribute_value_ids" column_invisible="True"/>
                    <field name="bom_product_template_attribute_value_ids" optional="hide" widget="many2many_tags" options="{'no_create': True}" groups="product.group_product_variant"/>
                    <field name="blocked_by_operation_ids" widget="many2many_tags" optional="hide" groups="mrp.group_mrp_workorder_dependencies"/>
                </list>
            </field>
        </record>

        <record id="mrp_routing_workcenter_bom_tree_view" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.bom.list</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="inherit_id" ref="mrp_routing_workcenter_tree_view"/>
            <field name="priority">1000</field>
            <field name="mode">primary</field>
            <field name="arch" type="xml">
                <xpath expr="//list" position="inside">
                    <control>
                        <button name="action_open_operation_form" class="btn-link" type="object" string="Add a line" context="{'default_bom_id': parent.id}"/>
                        <button name="copy_existing_operations" class="btn-link" type="object" string="Copy Existing Operations" context="{'bom_id': parent.id}"/>
                    </control>
                </xpath>
                <xpath expr="//field[@name='name']" position="before">
                    <field name="sequence" widget="handle"/>
                </xpath>
                <xpath expr="//field[@name='bom_id']" position="replace"/>
                <xpath expr="//field[@name='time_total']" position="attributes">
                    <attribute name="sum">Total Duration</attribute>
                </xpath>
                <xpath expr="//field[@name='bom_product_template_attribute_value_ids']" position="attributes">
                    <attribute name="column_invisible">parent.product_id</attribute>
                </xpath>
                <xpath expr="//field[@name='blocked_by_operation_ids']" position="replace">
                </xpath>
                <xpath expr="//field[@name='name']" position="after">
                    <field name="bom_id" column_invisible="True"/>
                    <field name="blocked_by_operation_ids" widget="many2many_tags" optional="hide" column_invisible="not parent.allow_operation_dependencies"/>
                </xpath>
            </field>
        </record>

        <record id="mrp_routing_workcenter_copy_to_bom_tree_view" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.copy_to_bom.list</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="inherit_id" ref="mrp_routing_workcenter_tree_view"/>
            <field name="mode">primary</field>
            <field name="arch" type="xml">
                <xpath expr="//list" position="attributes">
                    <attribute name="create">0</attribute>
                    <attribute name="delete">0</attribute>
                    <attribute name="export_xlsx">0</attribute>
                    <attribute name="multi_edit">0</attribute>
                </xpath>
                <xpath expr="//field[@name='name']" position="before">
                    <header>
                        <button name="copy_to_bom" type="object" string="Copy selected operations"/>
                    </header>
                </xpath>
            </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" class="o_mrp_routing_form">
                    <sheet>
                        <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                        <div class="d-flex">
                            <h1 class="d-flex w-100">
                                <field name="name" options="{'line_breaks': False}" widget="text" class="o_task_name text-truncate w-md-75 w-100 pe-2" placeholder="Operation..."/>
                            </h1>
                        </div>
                        <group>
                            <group name="description">
                                <field name="active" invisible="1"/>
                                <field name="company_id" invisible="1"/>
                                <field name="bom_id" invisible="context.get('bom_id_invisible', False)" domain="[]" readonly="context.get('default_bom_id', False)"/>
                                <field name="workcenter_id"/>
                                <field name="possible_bom_product_template_attribute_value_ids" invisible="1"/>
                                <field name="bom_product_template_attribute_value_ids" widget="many2many_tags" options="{'no_create': True}" groups="product.group_product_variant"/>
                                <field name="cost_mode" widget="radio" options="{'horizontal': true}"/>
                                <field name="allow_operation_dependencies" invisible="1"/>
                                <field name="blocked_by_operation_ids" widget="many2many_tags" context="{'default_bom_id':bom_id}" invisible="not allow_operation_dependencies"/>
                            </group><group name="workorder">
                                <field name="workorder_count" invisible="1"/>
                                <field name="time_mode" widget="radio" options="{'horizontal': true}"/>
                                <label for="time_cycle_manual" string="Default Duration"/>
                                <div>
                                    <field name="time_cycle_manual" widget="float_time" class="oe_inline" invisible="time_mode == 'auto' and workorder_count != 0"/>
                                    <span invisible="time_mode == 'auto' and workorder_count != 0">minutes</span>
                                    <span invisible="time_mode == 'manual'"> / last </span>
                                    <field name="time_mode_batch" class="oe_inline o_small_integer" invisible="time_mode == 'manual'"/>
                                    <span invisible="time_mode == 'manual'">work orders</span>
                                </div>
                                <field name="cycle_number" class="oe_inline" invisible="cycle_number &lt; 2"/>
                                <field name="show_time_total" invisible="1"/>
                                <label for="time_total" string="Total Duration" invisible="not show_time_total"/>
                                <div invisible="not show_time_total">
                                    <field name="time_total" widget="float_time" class="oe_inline"/>
                                    <span>minutes</span>
                                </div>
                                <field name="company_id" groups="base.group_multi_company" />
                            </group>
                        </group>
                    </sheet>
                    <chatter/>
                </form>
            </field>
        </record>

        <record id="mrp_routing_workcenter_kanban_view" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.kanban</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="arch" type="xml">
                <kanban>
                    <templates>
                        <t t-name="card">
                            <div class="d-flex">
                                <field name="name" class="fw-bold fs-5 mb-1"/>
                            </div>
                            <footer class="pt-0">
                                <field name="workcenter_id"/>
                            </footer>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

        <record id="mrp_routing_action" model="ir.actions.act_window">
            <field name="name">Operations</field>
            <field name="res_model">mrp.routing.workcenter</field>
            <field name="view_mode">list,kanban,form</field>
            <field name="view_id" ref="mrp_routing_workcenter_tree_view"/>
            <field name="help" type="html">
                <div class="o_mrp_routing_image settings position-relative">
                    <img class="position-absolute" src="/mrp/static/img/routing_shopfloor.png" alt="Shop Floor"/>
                    <div class="separator position-relative"/>
                    <span class="o_annotation o_annotation_1 o_annotation_end position-absolute">Time Clock</span>
                    <span class="o_annotation o_annotation_2 o_annotation_end position-absolute">Quality Control</span>
                    <span class="o_annotation o_annotation_3 o_annotation_start position-absolute">Feedback Loop</span>
                    <span class="o_annotation o_annotation_4 o_annotation_start position-absolute">Register Materials</span>
                    <span class="o_annotation o_annotation_5 o_annotation_start position-absolute">Select Operator</span>
                    <div class="o_text position-absolute">
                        <p>
                            No Operations Yet !
                        </p>
                        <p>
                            Run your Shop Floor with work orders for each operation defined on your bill of material.
                        </p>
                        <p>
                            Each operation can have multiple steps (scan products, view instructions) or even quality checks.
                        </p>
                    </div>
                </div>
            </field>
            <field name="domain">['|', ('bom_id', '=', False), ('bom_id.active', '=', True)]</field>
        </record>

        <record id="mrp_routing_workcenter_filter" model="ir.ui.view">
            <field name="name">mrp.routing.workcenter.filter</field>
            <field name="model">mrp.routing.workcenter</field>
            <field name="arch" type="xml">
                <search string="Operations Search Filters">
                    <field name="name"/>
                    <field name="bom_id"/>
                    <field name="workcenter_id"/>
                    <filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
                    <group>
                        <filter string="Bill of Material" name="bom" context="{'group_by': 'bom_id'}"/>
                        <filter string="Workcenter" name="workcenter" context="{'group_by': 'workcenter_id'}"/>
                    </group>
                </search>
            </field>
        </record>

        <menuitem id="menu_mrp_routing_action"
          action="mrp_routing_action"
          parent="menu_mrp_configuration"
          groups="group_mrp_routings"
          sequence="100"/>

    </data>
</odoo>
