<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- WINDOW ACTIONS (must be before menus) -->
    <!-- ================================================================= -->

    <!-- Bills from Email -->
    <record id="action_bills_from_email" model="ir.actions.act_window">
        <field name="name">Bills from Email</field>
        <field name="res_model">account.move</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('move_type', '=', 'in_invoice'), ('x_fa_created_from_email', '=', True)]</field>
        <field name="context">{'default_move_type': 'in_invoice'}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No bills from email yet
            </p>
            <p>
                Bills will appear here when incoming emails create vendor bills automatically.
            </p>
        </field>
    </record>

    <!-- All Vendor Bills -->
    <record id="action_all_vendor_bills" model="ir.actions.act_window">
        <field name="name">All Vendor Bills</field>
        <field name="res_model">account.move</field>
        <field name="view_mode">list,form</field>
        <field name="domain">[('move_type', '=', 'in_invoice')]</field>
        <field name="context">{'default_move_type': 'in_invoice'}</field>
    </record>

    <!-- Blocked Vendors -->
    <record id="action_blocked_vendors" model="ir.actions.act_window">
        <field name="name">Blocked Vendors</field>
        <field name="res_model">res.partner</field>
        <field name="view_mode">list,form</field>
        <field name="view_id" ref="view_partner_list_fusion_accounts"/>
        <field name="domain">[('x_fa_block_email_bill', '=', True)]</field>
        <field name="context">{'default_x_fa_block_email_bill': True}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No blocked vendors
            </p>
            <p>
                Vendors blocked from automatic email bill creation will appear here.
                Block vendors whose bills should be created through Purchase Orders instead.
            </p>
        </field>
    </record>

    <!-- Vendors with Active POs -->
    <record id="action_vendors_with_po" model="ir.actions.act_window">
        <field name="name">Vendors with Active POs</field>
        <field name="res_model">res.partner</field>
        <field name="view_mode">list,form</field>
        <field name="view_id" ref="view_partner_list_fusion_accounts"/>
        <field name="domain">[('purchase_line_ids', '!=', False), ('supplier_rank', '>', 0)]</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No vendors with purchase orders
            </p>
            <p>
                Vendors with Purchase Orders appear here.
                Consider blocking these vendors from automatic email bill creation.
            </p>
        </field>
    </record>

    <!-- All Vendors -->
    <record id="action_all_vendors" model="ir.actions.act_window">
        <field name="name">All Vendors</field>
        <field name="res_model">res.partner</field>
        <field name="view_mode">list,form</field>
        <field name="view_id" ref="view_partner_list_fusion_accounts"/>
        <field name="domain">[('supplier_rank', '>', 0)]</field>
    </record>

    <!-- Activity Log -->
    <record id="action_fusion_accounts_log" model="ir.actions.act_window">
        <field name="name">Activity Log</field>
        <field name="res_model">fusion.accounts.log</field>
        <field name="view_mode">list,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No activity logged yet
            </p>
            <p>
                Email processing activity will be logged here automatically.
            </p>
        </field>
    </record>

    <!-- Settings -->
    <record id="action_fusion_accounts_settings" model="ir.actions.act_window">
        <field name="name">Fusion Accounts Settings</field>
        <field name="res_model">res.config.settings</field>
        <field name="view_mode">form</field>
        <field name="target">current</field>
        <field name="context">{'module': 'fusion_accounts'}</field>
    </record>

    <!-- ================================================================= -->
    <!-- TOP-LEVEL APP MENU -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_root"
              name="Fusion Accounts"
              web_icon="fusion_accounts,static/description/icon.png"
              sequence="35"
              groups="group_fusion_accounts_user"/>

    <!-- ================================================================= -->
    <!-- DASHBOARD -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_dashboard"
              name="Dashboard"
              parent="menu_fusion_accounts_root"
              action="action_fusion_accounts_dashboard"
              sequence="10"/>

    <!-- ================================================================= -->
    <!-- BILLS -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_bills"
              name="Bills"
              parent="menu_fusion_accounts_root"
              sequence="20"/>

    <menuitem id="menu_fusion_accounts_bills_email"
              name="Bills from Email"
              parent="menu_fusion_accounts_bills"
              action="action_bills_from_email"
              sequence="10"/>

    <menuitem id="menu_fusion_accounts_bills_all"
              name="All Vendor Bills"
              parent="menu_fusion_accounts_bills"
              action="action_all_vendor_bills"
              sequence="20"/>

    <!-- ================================================================= -->
    <!-- VENDORS -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_vendors"
              name="Vendors"
              parent="menu_fusion_accounts_root"
              sequence="30"/>

    <menuitem id="menu_fusion_accounts_vendors_blocked"
              name="Blocked Vendors"
              parent="menu_fusion_accounts_vendors"
              action="action_blocked_vendors"
              sequence="10"/>

    <menuitem id="menu_fusion_accounts_vendors_with_po"
              name="Vendors with Active POs"
              parent="menu_fusion_accounts_vendors"
              action="action_vendors_with_po"
              sequence="15"/>

    <menuitem id="menu_fusion_accounts_vendors_all"
              name="All Vendors"
              parent="menu_fusion_accounts_vendors"
              action="action_all_vendors"
              sequence="20"/>

    <!-- ================================================================= -->
    <!-- ACTIVITY LOG -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_logs"
              name="Activity Log"
              parent="menu_fusion_accounts_root"
              action="action_fusion_accounts_log"
              sequence="40"/>

    <!-- ================================================================= -->
    <!-- CONFIGURATION -->
    <!-- ================================================================= -->
    <menuitem id="menu_fusion_accounts_config"
              name="Configuration"
              parent="menu_fusion_accounts_root"
              sequence="90"
              groups="group_fusion_accounts_manager"/>

    <menuitem id="menu_fusion_accounts_settings"
              name="Settings"
              parent="menu_fusion_accounts_config"
              action="action_fusion_accounts_settings"
              sequence="10"/>
</odoo>
