<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2013 Akretion (http://www.akretion.com)
  @author: Alexis de Lattre <alexis.delattre@akretion.com>
  The licence is in the file __openerp__.py
-->
<openerp>
<data>
	<record id="view_mandate_form" model="ir.ui.view">
		<field name="name">view.mandate.form</field>
		<field name="model">account.banking.mandate</field>
		<field name="arch" type="xml">
			<form string="Banking Mandate" version="7.0">
				<header>
					<button name="validate" type="object" string="Validate" states="draft" class="oe_highlight"/>
					<button name="cancel" type="object" string="Cancel" states="draft,valid"/>
					<button name="back2draft" type="object" string="Back to Draft"
						states="cancel" groups="account.group_account_manager"
						confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue ?"/>
					<field name="state" widget="statusbar"/>
				</header>
				<sheet>
					<div class="oe_title">
						<h1>
							<field name="unique_mandate_reference" class="oe_inline"/>
						</h1>
					</div>
					<group name="main">
						<field name="company_id" groups="base.group_multi_company"/>
						<field name="partner_bank_id"
							on_change="mandate_partner_bank_change(partner_bank_id, last_debit_date, state)"
							invisible="context.get('mandate_bank_partner_view')"
							/>
						<field name="partner_id" invisible="context.get('mandate_bank_partner_view')"/>
						<field name="signature_date"/>
						<field name="scan"/>
						<field name="last_debit_date"/>
					</group>
					<group name="payment_lines" string="Related Payment Lines">
						<field name="payment_line_ids" nolabel="1"/>
					</group>
				</sheet>
				<div class="oe_chatter">
					<field name="message_follower_ids" widget="mail_followers"/>
					<field name="message_ids" widget="mail_thread"/>
				</div>
			</form>
		</field>
	</record>

	<record id="view_mandate_tree" model="ir.ui.view">
		<field name="name">view.mandate.tree</field>
		<field name="model">account.banking.mandate</field>
		<field name="arch" type="xml">
			<tree string="Banking Mandate" colors="blue:state=='draft';black:state in ('expired', 'cancel')">
				<field name="company_id" groups="base.group_multi_company"/>
				<field name="partner_id" invisible="context.get('mandate_bank_partner_view')"/>
				<field name="unique_mandate_reference" string="Reference"/>
				<field name="signature_date" string="Signature Date"/>
				<field name="last_debit_date"/>
				<field name="state"/>
			</tree>
		</field>
	</record>

	<record id="view_mandate_search" model="ir.ui.view">
		<field name="name">view.mandate.search</field>
		<field name="model">account.banking.mandate</field>
		<field name="arch" type="xml">
			<search string="Search Banking Mandates">
				<field name="partner_id"/>
				<filter name="draft" string="Draft" domain="[('state', '=', 'draft')]" />
				<filter name="valid" string="Valid" domain="[('state', '=', 'valid')]" />
				<filter name="cancel" string="Cancelled" domain="[('state', '=', 'cancel')]" />
				<filter name="expired" string="Expired" domain="[('state', '=', 'expired')]" />
			</search>
		</field>
	</record>
	
	<record id="mandate_action" model="ir.actions.act_window">
		<field name="name">Banking Mandates</field>
		<field name="res_model">account.banking.mandate</field>
		<field name="view_type">form</field>
		<field name="view_mode">tree,form</field>
		<field name="help" type="html">
			<p class="oe_view_nocontent_create">
			Click to create a new Banking Mandate.
			</p><p>
			A Banking Mandate is a document signed by your customer that gives you the autorization to do one or several operations on his bank account.
			</p>
		</field>
	</record>

	<menuitem id="mandate_menu"
			  parent="account_payment.menu_main_payment"
			  action="mandate_action"
			  sequence="20"
			  />

	<!-- notifications in the chatter -->
	<record id="mandate_valid" model="mail.message.subtype">
		<field name="name">Mandate Validated</field>
		<field name="res_model">account.banking.mandate</field>
		<field name="default" eval="False"/>
		<field name="description">Banking Mandate Validated</field>
	</record>

	<record id="mandate_expired" model="mail.message.subtype">
		<field name="name">Mandate Expired</field>
		<field name="res_model">account.banking.mandate</field>
		<field name="default" eval="False"/>
		<field name="description">Banking Mandate has Expired</field>
	</record>

	<record id="mandate_cancel" model="mail.message.subtype">
		<field name="name">Mandate Cancelled</field>
		<field name="res_model">account.banking.mandate</field>
		<field name="default" eval="False"/>
		<field name="description">Banking Mandate Cancelled</field>
	</record>
</data>
</openerp>
