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

<!--
Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.

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

<odoo>
  <data>
    <!-- Forms -->
    <record model="ir.ui.view" id="account_payment_form_inherit_golem_payment">
      <field name="name">Add number of bank check into main form</field>
      <field name="model">account.payment</field>
      <field name="inherit_id" ref="account.view_account_payment_form" />
      <field name="arch" type="xml">
        <field name="communication" position="before">
          <field name="reference" />
        </field>
      </field>
    </record>

    <record model="ir.ui.view" id="account_invoice_form_inherit_golem_payment">
      <field name="name">Add number of bank check into main form</field>
      <field name="model">account.payment</field>
      <field name="inherit_id" ref="account.view_account_payment_invoice_form" />
      <field name="arch" type="xml">
        <field name="communication" position="before">
          <field name="reference" />
        </field>
      </field>
    </record>

    <!-- Trees -->
    <record id="golem_payment_tree_inherit_account_payment" model="ir.ui.view">
      <field name="name">Account payment list</field>
      <field name="model">account.payment</field>
      <field name="inherit_id" ref="account.view_account_payment_tree" />
      <field name="arch" type="xml">
        <tree position="attributes">
          <attribute name="decoration-warning">state=='draft' and payment_date &lt;= current_date</attribute>
        </tree>
        <field name="state" position="before" >
          <field name="reference" />
        </field>
      </field>
    </record>

    <!-- Search -->
    <record id="account_payment_search" model="ir.ui.view">
      <field name="name">Account Payment Filters</field>
      <field name="model">account.payment</field>
      <field name="arch" type="xml">
        <search>
          <field name="state" />
          <field name="payment_date" />
          <field name="reference" />
          <group string="Group By">
            <filter name="group_week" string="By week"
              context="{'group_by': 'payment_date:week'}"/>
            <filter name="group_month" string="By month"
              context="{'group_by': 'payment_date:month'}"/>
          </group>
          <filter name="payment_7_days" string="payment in 7 days"
            domain="[('state','=', 'draft'),
              ('payment_date','&lt;=', (context_today() + datetime.timedelta(days=7)).strftime('%Y-%m-%d')),
              ('payment_date','&gt;=', context_today().strftime('%Y-%m-%d'))]" />
            <filter name="payment_30_days" string="payment in 30 days"
              domain="[('state','=', 'draft'),
                ('payment_date','&lt;=', (context_today() + datetime.timedelta(days=30)).strftime('%Y-%m-%d')),
                ('payment_date','&gt;=', context_today().strftime('%Y-%m-%d'))]" />
            <separator />
            <filter name="payment_delayed" string="Payment delayed"
              domain="[('state','=', 'draft'), ('payment_date','&lt;=', context_today().strftime('%Y-%m-%d'))]" />
        </search>
      </field>
    </record>

  </data>
</odoo>