<odoo>
    <record id="stock_valuation_layer_form" model="ir.ui.view">
        <field name="name">stock.valuation.layer.form</field>
        <field name="model">stock.valuation.layer</field>
        <field name="arch" type="xml">
            <form edit="0" create="0">
                <sheet>
                    <group>
                        <group>
                            <field name="create_date" string="Date" />
                            <field name="product_id" />
                            <field name="lot_id" invisible="not lot_id"/>
                            <field name="stock_move_id" invisible="not stock_move_id" />
                        </group>
                    </group>
                    <notebook>
                        <page string="Valuation" name="valuation">
                            <group>
                                <field name="quantity" />
                                <field name="uom_id" groups="uom.group_uom" />
                                <field name="currency_id" invisible="1" />
                                <field name="unit_cost" />
                                <field name="value" />
                                <field name="remaining_qty" />
                            </group>
                        </page>
                        <page string="Other Info" name="other_info">
                            <group>
                                <field name="description" />
                                <field name="account_move_id" groups="account.group_account_invoice" invisible="not account_move_id" />
                                <field name="company_id" groups="base.group_multi_company" />
                                <field name="stock_valuation_layer_id" invisible="not stock_valuation_layer_id" />
                            </group>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="stock_valuation_layer_tree" model="ir.ui.view">
        <field name="name">stock.valuation.layer.list</field>
        <field name="model">stock.valuation.layer</field>
        <field name="arch" type="xml">
            <list default_order="id desc" create="0"
                  import="0" js_class="inventory_report_list"
                  action="action_open_reference" type="object" duplicate="0">
                <header>
                    <button name="action_valuation_at_date" string="Valuation at Date" type="object"
                            invisible="((context.get('inventory_mode') and not context.get('inventory_report_mode')) or context.get('no_at_date'))"
                            class="btn-primary ms-1"
                            display="always"/>
                </header>
                <field name="create_date" string="Date" />
                <field name="reference"/>
                <field name="account_move_id" optional="hide" groups="account.group_account_user"/>
                <button name="action_open_journal_entry" groups="account.group_account_user" type="object" title="Journal Entry" icon="fa-book" invisible="not account_move_id"/>
                <field name="product_id" />
                <field name="lot_id" optional="hide"/>
                <field name="company_id" groups="base.group_multi_company" optional="hide"/>
                <field name="quantity" string="Quantity" optional="show" sum="Total Moved Quantity"/>
                <field name="remaining_qty" type="measure" optional="hide" sum="Total Remaining Quantity"/>
                <field name="unit_cost" optional="hide"/>
                <field name="uom_id" string="Unit" groups="uom.group_uom" optional="hide"/>
                <field name="currency_id" column_invisible="True" />
                <field name="value" sum="Total Value" optional="show"/>
                <field name="description" optional="hide"/>
                <field name="remaining_value" type="measure" optional="hide" sum="Total Remaining Value"/>
                <groupby name="product_id">
                    <field name="cost_method" invisible="1"/>
                    <field name="quantity_svl" invisible="1"/>
                    <button name="action_revaluation" icon="fa-plus" title="Add Manual Valuation" type="object" invisible="cost_method == 'standard' or quantity_svl &lt;= 0" />
                </groupby>
                <groupby name="lot_id">
                    <button name="action_revaluation" icon="fa-plus" title="Add Manual Valuation" type="object"/>
                </groupby>
            </list>
        </field>
    </record>

    <record id="stock_valuation_layer_valuation_at_date_tree_inherited" model="ir.ui.view">
        <field name="name">inventory.aging.list</field>
        <field name="model">stock.valuation.layer</field>
        <field name="inherit_id" ref="stock_valuation_layer_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='remaining_qty']" position="attributes">
                <attribute name="optional">show</attribute>
            </xpath>
        </field>
    </record>

    <record id="stock_valuation_layer_pivot" model="ir.ui.view">
        <field name="name">stock.valuation.layer.pivot</field>
        <field name="model">stock.valuation.layer</field>
        <field name="arch" type="xml">
            <pivot>
                <field name="quantity" type="measure"/>
                <field name="value" type="measure"/>
            </pivot>
        </field>
    </record>

    <record id="stock_valuation_layer_graph" model="ir.ui.view">
        <field name="name">inventory.aging.graph</field>
        <field name="model">stock.valuation.layer</field>
        <field name="arch" type="xml">
            <graph string="valuation graph" type="line" cumulated="1" >
                <field name="create_date" type="row"/>
                <field name="value" type="measure"/>
            </graph>
        </field>
    </record>

    <record id="stock_valuation_layer_action" model="ir.actions.act_window">
        <field name="name">Stock Valuation</field>
        <field name="res_model">stock.valuation.layer</field>
        <field name="path">stock-valuation</field>
        <field name="view_mode">list,form,pivot,graph</field>
        <field name="view_id" ref="stock_valuation_layer_tree"/>
        <field name="domain">[('product_id.is_storable', '=', True)]</field>
        <field name="context">{
            'pivot_column_groupby': ['create_date:month'],
            'pivot_row_groupby': ['categ_id'],
            'pivot_measures': ['remaining_qty', 'remaining_value'],
            'graph_groupbys': ['create_date:day'],
            }</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face"/>
            <p>
                There are no valuation layers. Valuation layers are created when there are product moves that impact the valuation of the stock.
            </p>
        </field>
    </record>

    <record id="view_inventory_valuation_search" model="ir.ui.view">
        <field name="name">Inventory Valuation</field>
        <field name="model">stock.valuation.layer</field>
        <field name="arch" type="xml">
            <search string="Inventory Valuation">
                <field name="product_id"/>
                <field name="reference"/>
                <field name="categ_id" />
                <field name="product_tmpl_id" />
                <field name="warehouse_id" groups="stock.group_stock_multi_warehouses"/>
                <field name="company_id" groups="base.group_multi_company"/>
                <separator/>
                <filter string="Incoming" name="incoming" domain="[('stock_move_id.location_id.usage', 'not in', ('internal', 'transit')), ('stock_move_id.location_dest_id.usage', 'in', ('internal', 'transit'))]"/>
                <filter string="Outgoing" name="outgoing" domain="[('stock_move_id.location_id.usage', 'in', ('internal', 'transit')), ('stock_move_id.location_dest_id.usage', 'not in', ('internal', 'transit'))]"/>
                <separator/>
                <filter string="Has Remaining Qty" name="has_remaining_qty" domain="[('remaining_qty', '>', 0)]"/>
                <group expand='0' string='Group by...'>
                    <filter string='Product' name="group_by_product_id" context="{'group_by': 'product_id'}"/>
                    <filter string='Lot/Serial Number' name="group_by_lot_id" context="{'group_by': 'lot_id'}"/>
                    <filter string='Product Category' name="group_by_categ_id" context="{'group_by': 'categ_id'}"/>
                    <filter string='Date' name="group_by_created_date" context="{'group_by': 'create_date'}"/>
                    <filter string='Company' name="group_by_company_id" context="{'group_by': 'company_id'}" groups="base.group_multi_company"/>
                </group>
            </search>
        </field>
    </record>

    <!-- reporting view -->
    <record id="stock_valuation_layer_report_tree" model="ir.ui.view">
        <field name="name">stock.valuation.layer.report.list</field>
        <field name="model">stock.valuation.layer</field>
        <field name="inherit_id" ref="stock_valuation_layer_tree"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">
            <field name="quantity" position="attributes">
                <attribute name="invisible">1</attribute>
            </field>
            <field name="unit_cost" position="after">
                <field name="remaining_qty" sum="Total Remaining Quantity"/>
            </field>
            <field name="value" position="before">
                <field name="remaining_value" sum="Total Remaining Value"/>
            </field>
        </field>
    </record>

    <record id="stock_valuation_layer_report_action" model="ir.actions.act_window">
        <field name="name">Stock Valuation</field>
        <field name="res_model">stock.valuation.layer</field>
        <field name="view_mode">list,form,pivot</field>
        <field name="view_id" ref="stock_valuation_layer_report_tree"/>
        <field name="context">{'search_default_has_remaining_qty': 1}</field>
        <field name="domain">[('product_id.is_storable', '=', True)]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face"/>
            <p>
                There are no valuation layers. Valuation layers are created when there are product moves that impact the valuation of the stock.
            </p>
        </field>
    </record>

    <menuitem id="menu_valuation" name="Valuation" parent="stock.menu_warehouse_report" sequence="250" action="stock_valuation_layer_action"/>

    <record id="stock_valuation_layer_picking" model="ir.ui.view">
        <field name="name">stock.valuation.layer.picking</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_form" />
        <field name="arch" type="xml">
            <xpath expr="//div[@name='button_box']" position="inside">
                <button type="object"
                    name="action_view_stock_valuation_layers"
                    class="oe_stat_button" icon="fa-dollar" groups="base.group_no_one"
                    invisible="state != 'done'" >
                    <div class="o_stat_info">
                        <span class="o_stat_text">Valuation</span>
                    </div>
                </button>
            </xpath>
        </field>
    </record>

</odoo>