<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <data>
		
		<!-- VIEW REQUESTS -->
        <record id="view_rgm_requests_view_tree" model="ir.ui.view">
            <field name="name">view.request.declaration.view.tree</field>
            <field name="model">view.request.declaration</field>
            <field name="priority" eval="8" />
            <field name="arch" type="xml">
                <tree string="RGM Requests" create="false">
                    <field name="process_number_display" string="Request Number" />
                    <field name="request_type_id" />
                    <field name="user_id" />
                    <field name="record_date" />
                    <field name="expiry_date" />
                    <field name="state" />
                </tree>
            </field>
        </record>
		
        <record id="view_rgm_requests_view_form" model="ir.ui.view">
            <field name="name">view.request.declaration.view.form</field>
            <field name="model">view.request.declaration</field>
            <field name="priority" eval="8" />
            <field name="arch" type="xml">
                <form string="RGM Request" create="false" edit="false">
                    <header>
                        <field name="state" widget="statusbar" statusbar_visible="draft,pending,active,expired,deleted"/>
                    </header>
                    <sheet>
						<field name="process_number" invisible="1"/>
						<group col="4" colspan="4" name="general_detail">
							<field name="process_number_display" string="Request Number" readonly="1" />
							<field name="declaration_id" />
							<field name="record_date" />
							<field name="expiry_date" />
							<field name="user_id" />
							<field name="request_type_id" />
						</group>
						<notebook>
							<page name="declaration_creditors" string="Creditors">
								<field name="creditors_line" colspan="4" nolabel="1">
									<tree string="Creditors">
										<field name="intervenor_id" />
										<field name="gender" />
										<field name="document_number" />
										<field name="tin" />
									</tree>
									<form string="Creditor">
										<group col="4">
											<field name="intervenor_id" />
											<field name="gender" />
											<field name="document_number" />
											<field name="tin" />
											<field name="birthday" />
										</group>
									</form>
								</field>
							</page>
							<page name="declaration_debtors" string="Debtors">
								<field name="debtors_line" colspan="4" nolabel="1">
									<tree string="Debtors">
										<field name="intervenor_id" />
										<field name="gender" />
										<field name="document_number" />
										<field name="tin" />
									</tree>
									<form string="Debtor">
										<group col="4">
											<field name="intervenor_id" />
											<field name="gender" />
											<field name="document_number" />
											<field name="tin" />
											<field name="birthday" />
										</group>
									</form>
								</field>
							</page>
							<page name="declaration_guarantors" string="Guarantors">
								<field name="guarantors_line" colspan="4" nolabel="1">
									<tree string="Guarantors">
										<field name="intervenor_id" />
										<field name="gender" />
										<field name="document_number" />
										<field name="tin" />
									</tree>
									<form string="Guarantor">
										<group col="4">
											<field name="intervenor_id" />
											<field name="gender" />
											<field name="document_number" />
											<field name="tin" />
											<field name="birthday" />
										</group>
									</form>
								</field>
							</page>
							<page name="declaration_applicants" string="Applicants">
								<field name="applicants_line" colspan="4" nolabel="1">
									<tree string="Applicants">
										<field name="intervenor_id" />
										<field name="gender" />
										<field name="document_number" />
										<field name="tin" />
									</tree>
									<form string="Applicant">
										<group col="4">
											<field name="intervenor_id" />
											<field name="gender" />
											<field name="document_number" />
											<field name="tin" />
											<field name="birthday" />
										</group>
									</form>
								</field>
							</page>
						</notebook>
                    </sheet>
                </form>
            </field>
        </record>
		
        <record id="view_rgm_requests_view_search" model="ir.ui.view">
            <field name="name">view.request.declaration.view.search</field>
            <field name="model">view.request.declaration</field>
            <field name="priority" eval="8" />
            <field name="arch" type="xml">
                <search string="RGM Requests">
                    <field name="process_number" string="Request Reference Number"
                        filter_domain="['|',('process_number', '=', self), ('process_number_display', '=', self)]"/>
                    <field name="record_date" />
                    <field name="user_id" />
                    <field name="state" />
                    <field name="request_type_id" />
                    <filter string="Today" name="today" domain="['&amp;',('record_date', '&gt;=', context_today().strftime('%%Y-%%m-%%d 00:00:00')), ('record_date', '&lt;', context_today().strftime('%%Y-%%m-%%d 23:59:59'))]"/>
                    <filter string="This Month" name="last_month" domain="['&amp;',('record_date', '&gt;=', context_today().strftime('%%Y-%%m-01')), ('record_date', '&lt;', (context_today() + relativedelta(months=1)).strftime('%%Y-%%m-01'))]"/>
					<filter string="This Year" name="thisyear" domain="[('record_date','&gt;=',time.strftime('%%Y-01-01'))]"/>
                    <separator/>
					<filter string="Draft" name="Draft" domain="[('state','=','draft')]"/>
					<filter string="Pending" name="Pending" domain="[('state','=','pending')]"/>
					<filter string="Active" name="Active" domain="[('state','=','active')]"/>
                    <group expand="0" string="Group By">
                        <filter string="State" name="state" context="{'group_by': 'state'}"/>
                        <filter string="Request Type" name="request_type_id" context="{'group_by': 'request_type_id'}"/>
                    </group>
                </search>
            </field>
        </record>

		<record id="view_rgm_requests_view_pivot" model="ir.ui.view">
			 <field name="name">view.request.declaration.consult.pivot</field>
			 <field name="model">view.request.declaration</field>
			 <field name="arch" type="xml">
				 <pivot string="RGM Requests" disable_linking="True" sample="1">
					 <field name="request_type" type="row" invisible="1"/>
					 <field name="process_number_display" type="row" invisible="1"/>
					 <field name="reference_id" type="row" invisible="1"/>
					 <field name="fact_date" type="row" invisible="1"/>
					 <field name="record_date" type="row" invisible="1"/>
					 <field name="end_date" type="row" invisible="1"/>
					 <field name="expiry_date" type="row" invisible="1"/>
					 <field name="requested_id" type="row" invisible="1"/>
					 <field name="searchable" type="row" invisible="1"/>
					 <field name="creditors" type="row" invisible="1"/>
					 <field name="debtors" type="row" invisible="1"/>
					 <field name="creditors_search" type="row" invisible="1"/>
					 <field name="debtors_search" type="row" invisible="1"/>
					 <field name="intervenors" type="row" invisible="1"/>
					 <field name="intervenors_search" type="row" invisible="1"/>
					 <field name="assets_references" type="row" invisible="1"/>
				 </pivot>
			 </field>
		</record>

        <record id="view_rgm_request_view_graph" model="ir.ui.view">
            <field name="name">view.request.declaration.graph</field>
            <field name="model">view.request.declaration</field>
            <field name="arch" type="xml">
                <graph string="RGM Requests" type="bar" sample="1">
                    <field name="request_type_id"/>
                </graph>
            </field>
         </record>		

        <record model="ir.actions.act_window" id="act_open_rgm_requests_view_view">
            <field name="name">RGM Requests</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">view.request.declaration</field>
            <field name="view_mode">tree,form,graph,pivot</field>
            <field name="search_view_id" ref="view_rgm_requests_view_search" />
            <field name="domain">[]</field>
			<field name="context">{'default_request_origin': 'backoffice'}</field>
			<field name="help" type="html">
              <p class="o_view_nocontent_smiling_face">
                Add a new request.
              </p>
            </field>
        </record>
		
        <record model="ir.actions.act_window.view" id="act_open_rgm_requests_view_view_form">
            <field name="act_window_id" ref="act_open_rgm_requests_view_view" />
            <field name="sequence" eval="20" />
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_rgm_requests_view_form" />
        </record>
        <record model="ir.actions.act_window.view" id="act_open_rgm_requests_view_view_tree">
            <field name="act_window_id" ref="act_open_rgm_requests_view_view" />
            <field name="sequence" eval="10" />
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_rgm_requests_view_tree" />
        </record>


    </data>
</odoo>
