<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright 2014-2020 Akretion (http://www.akretion.com/)
  @author Alexis de Lattre <alexis.delattre@akretion.com>
  License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo>


<!-- Display advanced fields in stock moves form view -->
<record id="view_move_form" model="ir.ui.view">
    <field name="name">stock.usability.stock.move.form</field>
    <field name="model">stock.move</field>
    <field name="inherit_id" ref="stock.view_move_form" />
    <field name="arch" type="xml">
        <!--
        <field name="state" position="before">
            <button type="object" name="button_do_unreserve" string="Unreserve"
                groups="stock.group_stock_user"
                attrs="{'invisible': [('reserved_quant_ids', '=', [])]}"/>
        </field>  -->
        <field name="origin" position="after">
            <field name="picking_id" readonly="1" string="Picking"/>
            <field name="inventory_id" readonly="1"/>
        </field>
        <group name="origin_grp" position="after">
            <group name="advanced" string="Advanced" groups="stock.group_stock_manager">
                <field name="warehouse_id" readonly="1"/>
                <field name="route_ids" widget="many2many_tags" readonly="1"/>
                <field name="rule_id" readonly="1"/>
                <field name="propagate_cancel" readonly="1"/>
                <field name="price_unit" readonly="1"/>
                <field name="partner_id" readonly="1"/>
                <field name="restrict_partner_id" readonly="1"/>
            </group>
        </group>
    </field>
</record>

<!-- By default, stock.move have:
     _order = 'sequence, id'
     I don't know if they have a good reason to choose this order,
     but, when you open tree view of move lines from product, you want
     the most recent moves at the top, so we change the default
     order in the tree view (lower impact than changing _order -->
<record id="view_move_tree" model="ir.ui.view">
    <field name="name">stock_usability.move.tree.better.order</field>
    <field name="model">stock.move</field>
    <field name="inherit_id" ref="stock.view_move_tree" />
    <field name="arch" type="xml">
        <tree position="attributes">
            <attribute name="default_order">date desc, picking_id, sequence</attribute>
        </tree>
        <field name="state" position="after">
            <button type="object" name="button_do_unreserve" string="Unreserve"
                groups="stock.group_stock_user"
                states="partially_available,assigned"
                icon="fa-ban"/>
        </field>
        <field name="product_id" position="after">
            <field name="product_barcode" optional="hide"/>
        </field>
        <field name="reference" position="after">
            <field name="origin" optional="hide"/>
            <field name="partner_id" optional="hide"/>
        </field>
    </field>
</record>

<record id="stock.stock_move_action" model="ir.actions.act_window">
    <!-- Remove from context 'search_default_groupby_location_id': 1 -->
    <field name="context">{'search_default_done': 1}</field>
</record>

<record id="view_move_line_form" model="ir.ui.view">
    <field name="name">stock_usability.stock.move.line.form</field>
    <field name="model">stock.move.line</field>
    <field name="inherit_id" ref="stock.view_move_line_form" />
    <field name="arch" type="xml">
        <field name="reference" position="before">
            <field name="picking_id" attrs="{'invisible': [('picking_id', '=', False)]}"/>
        </field>
    </field>
</record>
 
<record id="view_move_line_tree" model="ir.ui.view">
    <field name="name">stock_usability.stock.move.line.tree</field>
    <field name="model">stock.move.line</field>
    <field name="inherit_id" ref="stock.view_move_line_tree" />
    <field name="arch" type="xml">
        <field name="qty_done" position="before">
            <field name="product_qty" sum="1" string="Reserved Qty"/>
        </field>
        <field name="qty_done" position="attributes">
            <attribute name="sum">1</attribute>
        </field>
        <field name="state" position="after">
            <button type="object" name="button_do_unreserve" string="Unreserve"
                groups="stock.group_stock_user"
                states="partially_available,assigned"
                icon="fa-ban"/>
        </field>
        <field name="product_id" position="after">
            <field name="product_barcode" optional="hide"/>
        </field>
    </field>
</record>

<!-- View embedded in picking -->
<record id="view_stock_move_line_detailed_operation_tree" model="ir.ui.view">
    <field name="model">stock.move.line</field>
    <field name="inherit_id" ref="stock.view_stock_move_line_detailed_operation_tree" />
    <field name="arch" type="xml">
        <field name="product_id" position="after">
            <field name="product_barcode" optional="hide"/>
        </field>
        <field name="qty_done" position="attributes">
            <attribute name="sum">1</attribute>
        </field>
        <field name="product_uom_qty" position="attributes">
            <attribute name="sum">1</attribute>
        </field>
    </field>
</record>

<record id="stock_move_line_view_search" model="ir.ui.view">
    <field name="model">stock.move.line</field>
    <field name="inherit_id" ref="stock.stock_move_line_view_search"/>
    <field name="arch" type="xml">
        <field name="location_dest_id" position="after">
            <field name="lot_id"/>
        </field>
    </field>
</record>

<record id="stock.stock_move_line_action" model="ir.actions.act_window">
    <!-- remove from context 'search_default_groupby_product_id': 1 -->
    <field name="context">{'search_default_done': 1, 'create': 0}</field>
</record>

</odoo>
