<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="product_template_search_view_inherit_sale_subscription" model="ir.ui.view">
        <field name="name">product.template.search.inherit</field>
        <field name="model">product.template</field>
        <field name="mode">primary</field>
        <field name="inherit_id" ref="product.product_template_search_view"/>
        <field name="arch" type="xml">
            <xpath expr="//filter[@name='consumable']" position="after">
                <filter name="filter_recurring" string="Subscription Products" domain="[('recurring_invoice', '=', True)]"/>
            </xpath>
        </field>
    </record>

    <record id="product_template_view_form_recurring" model="ir.ui.view">
        <field name="name">sale.subscription.product.template.form.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="sale.product_template_form_view_invoice_policy"/>
        <field name="arch" type="xml">
            <page name="sales" position="attributes">
                <attribute name="attrs">{'invisible': [('sale_ok', '=', False), ('recurring_invoice', '=', False)]}</attribute>
                <attribute name="class">page_sales</attribute>
            </page>
            <xpath expr="//group[@name='invoicing']" position="after">
                <group name="subscription" string="Subscriptions">
                    <field name="recurring_invoice" />
                    <field name="subscription_template_id" class="field_sub_template_id" attrs="{'invisible': [('recurring_invoice', '=', False)]}"/>
                </group>
            </xpath>
        </field>
    </record>

    <record id="product_action_subscription" model="ir.actions.act_window">
        <field name="name">Subscription Products</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.template</field>
        <field name="view_mode">kanban,tree,form,activity</field>
        <field name="context">{"default_recurring_invoice": True, "search_default_filter_recurring": True, "default_type": "service"}</field>
        <field name="view_id" ref="product.product_template_tree_view"/>
        <field name="search_view_id" ref="product_template_search_view_inherit_sale_subscription"/>
        <field name="help" type="html">
          <p class="o_view_nocontent_smiling_face">
            Create a new product
          </p><p>
            You must define a product for everything you sell or purchase,
            whether it's a storable product, a consumable or a service.
          </p>
        </field>
    </record>

    <record id="product_template_action_subscription" model="ir.actions.act_window">
        <field name="name">Products</field>
        <field name="res_model">product.template</field>
        <field name="view_mode">kanban,tree,form</field>
        <field name="view_id" ref="product_template_search_view_inherit_sale_subscription"/>
        <field name="domain">[('subscription_template_id', '=', active_id)]</field>
        <field name="context">{"default_type": "service", "default_recurring_invoice": True, "default_subscription_template_id": active_id}</field>
        <field name="help" type="html">
          <p class="o_view_nocontent_empty_folder">
            No product found
          </p><p>
            You will find here all the products related to this subscription template.
          </p>
        </field>
    </record>

</odoo>
