<?xml version="1.0" encoding="utf-8" ?>
<!--
  Copyright 2017-2021 Akretion France (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>
    <record id="view_production_lot_form" model="ir.ui.view">
        <field name="name">product_expiry_simple.stock.lot.form</field>
        <field name="model">stock.lot</field>
        <field name="inherit_id" ref="stock.view_production_lot_form" />
        <field name="arch" type="xml">
            <field name="ref" position="before">
                <field
                    name="expiry_date"
                    attrs="{'invisible': [('use_expiry_date', '!=', True)], 'required': [('use_expiry_date', '=', True)]}"
                />
                <field name="expired" invisible="1" />
                <field name="use_expiry_date" invisible="1" />
            </field>
            <xpath expr="//div[hasclass('oe_title')]" position="inside">
                <span
                    class="badge text-bg-danger"
                    attrs="{'invisible': [('expired', '=', False)]}"
                >Expired</span>
            </xpath>
        </field>
    </record>

    <record id="view_production_lot_tree" model="ir.ui.view">
        <field name="name">product_expiry_simple.stock.lot.tree</field>
        <field name="model">stock.lot</field>
        <field name="inherit_id" ref="stock.view_production_lot_tree" />
        <field name="arch" type="xml">
            <field name="name" position="after">
                <field name="expiry_date" optional="show" />
            </field>
            <xpath expr="/tree" position="attributes">
                <attribute
                    name="decoration-danger"
                >expiry_date and expiry_date &lt; current_date</attribute>
            </xpath>
        </field>
    </record>
    <record id="search_product_lot_filter" model="ir.ui.view">
        <field name="name">product_expiry_simple.stock.lot.search</field>
        <field name="model">stock.lot</field>
        <field name="inherit_id" ref="stock.search_product_lot_filter" />
        <field name="arch" type="xml">
            <field name="product_id" position="after">
                <separator />
                <filter string="Expiry Date" name="expiry_date" date="expiry_date" />
                <separator />
                <filter
                    domain="[('expiry_date', '&lt;', context_today().strftime('%Y-%m-%d'))]"
                    name="expired"
                    string="Expired"
                />
                <filter
                    domain="[('expiry_date', '&gt;=', context_today().strftime('%Y-%m-%d'))]"
                    name="no-expired"
                    string="Not Expired"
                />
                <separator />
            </field>
            <filter name="group_by_product" position="after">
                <filter
                    context="{'group_by': 'expiry_date:month'}"
                    name="expiry_date_groupby"
                    string="Expiry Date"
                />
            </filter>
        </field>
    </record>
</odoo>
