<?xml version="1.0" encoding="UTF-8"?>

<!--

    Copyright (c) 2017-2019 MuK IT GmbH.

    This file is part of MuK Autovacuum 
    (see https://mukit.at).

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.

  -->

<odoo>

<record id="view_autovacuum_rule_search" model="ir.ui.view">
	<field name="name">muk_autovacuum_rules.search</field>
	<field name="model">muk_autovacuum.rules</field>
    <field name="arch" type="xml">
        <search string="Auto Vacuum Rules">
            <field name="name" filter_domain="[('name', 'ilike', self)]" />
            <field name="model" />
			<field name="state" />
            <field name="active" />
            <filter string="All" name="all" domain="['|', ('active', '=', False), ('active', '=', True)]" />
            <group expand="0" name="group_by" string="Group By">
                <filter name="group_by_model" string="Model" domain="[]" context="{'group_by': 'model'}"/>
            </group>
        </search>
    </field>
</record>

<record id="view_autovacuum_rule_tree" model="ir.ui.view">
	<field name="name">muk_autovacuum_rules.tree</field>
	<field name="model">muk_autovacuum.rules</field>
	<field name="arch" type="xml">
		<tree string="Auto Vacuum Rules" decoration-muted="(not active)">
			<field name="sequence" widget="handle"/>
			<field name="name"/>
			<field name="model"/>
			<field name="state"/>
			<field name="active"/>
		</tree>
	</field>
</record>

<record id="view_autovacuum_rule_form" model="ir.ui.view">
	<field name="name">muk_autovacuum_rules.form</field>
	<field name="model">muk_autovacuum.rules</field>
	<field name="arch" type="xml">
		<form string="Auto Vacuum Rules">
        	<sheet>
			    <div class="oe_button_box" name="button_box">
			        <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-bell">
			            <field name="active" widget="boolean_button"/>
			        </button>
			    </div>
		        <div class="oe_title">
		            <label for="name" class="oe_edit_only"/>
		            <h1>
		            	<field name="name" placeholder="e.g. Delete Logs after 30 Days"/>
		            </h1>
		        </div>
		        <group>
		            <group>
		                <field name="sequence"/>
		                <field name="model"/>
		                <field name="model_name" invisible="1"/>
		                <field name="state"/>
		            </group>
		            <group>
		                <field name="protect_starred"/>
		                <field name="only_inactive"/>
		                <field name="only_attachments"/>
		            </group>
		        </group>
		        <notebook>
	                <page string="Time Settings" name='time' autofocus="autofocus"
	                    attrs="{'invisible': [('state', '!=', 'time')]}">
	                    <group>
			                <group>
				                <field name="time_field"/>
				            </group>
			                <group>
				                <field name="time_type"/>
				                <field name="time"/>
				            </group>
			            </group>
	                </page>
	                <page string="Size Settings" name='size' autofocus="autofocus"
	                    attrs="{'invisible': [('state', '!=', 'size')]}">
						<group>
			                <group>
				                <field name="size_type"/>
				            </group>
			                <group>
				                <field name="size_parameter" 
				                	attrs="{'invisible': [('size_type', '!=', 'parameter')]}"/>
				                <field name="size_parameter_value" 
				                	attrs="{'invisible': [('size_type', '!=', 'parameter')]}"/>
				                <field name="size" 
				                	attrs="{'invisible': [('size_type', '!=', 'fixed')]}"/>
				                <field name="size_order"/> 
				            </group>
			            </group>
	                </page>
	                <page string="Domain Settings" name='domain' autofocus="autofocus"
	                	attrs="{'invisible': [('state', '!=', 'domain')]}">
						<field name="domain" widget="domain" options="{'model': 'model_name'}" />
	                </page>
	                <page string="Code Settings" name='code' autofocus="autofocus"
	                	attrs="{'invisible': [('state', '!=', 'code')]}">
						<field name="code" widget="ace" options="{'mode': 'python'}" 
							placeholder="Enter Python code here. Help about Python expression is available in the help tab of this document."/>
	                </page>
	                <page string="Help" attrs="{'invisible': [('state', '!=', 'code')]}">
                        <group>
                            <div style="margin-top: 4px;">
                                <h3>Help with Python expressions</h3>
                                <p>Various fields may use Python code or Python expressions. The following variables can be used:</p>
                                <ul>
                                	<li><code>uid</code>, <code>user</code>: User on which the rule is triggered</li>
                                    <li><code>env</code>: Odoo Environment on which the rule is triggered</li>
                                    <li><code>model</code>: Odoo Model of the record on which the rule is triggered</li>
                                    <li><code>b64encode</code>, <code>b64decode</code>: Base64 converter</li>
                                    <li><code>time</code>, <code>datetime</code>, <code>dateutil</code>, <code>timezone</code>: useful Python libraries</li>
                                    <li><code>date_format</code>, <code>datetime_format</code>: server date and time formats</li>
                                    <li><code>logger.info(message)</code>: Python logging framework</li>
                                    <li><code>Warning</code>: Warning Exception to use with <code>raise</code></li>
                                </ul>
                            </div>
                        </group>
                    </page>
	        	</notebook>
	        </sheet>
		</form>
	</field>
</record>

<record id="action_autovacuum_rule" model="ir.actions.act_window">
	<field name="name">Auto Vacuum Rules</field>
	<field name="res_model">muk_autovacuum.rules</field>
	<field name="view_mode">tree,form</field>
	<field name="context">{'search_default_all': 1}</field>
</record>

<menuitem id="menu_autovacuum_rules" name="Auto Vacuum Rules" 
	 parent="base.menu_automation" action="action_autovacuum_rule"/>
	
</odoo>