[ADD] account_banking_mandate, spliting functionality in two modules

This commit is contained in:
Pedro M. Baeza
2014-10-08 03:34:21 +02:00
parent 7d3b61dbec
commit ba0375a615
26 changed files with 935 additions and 645 deletions

View File

@@ -1,30 +1,22 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Direct Debit module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields
class ResPartnerBank(models.Model):
_inherit = 'res.partner.bank'
sdd_mandate_ids = fields.One2many(
'sdd.mandate', 'partner_bank_id', string='SEPA Direct Debit Mandates')
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>
#
# 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/>.
#
##############################################################################
from . import models

View File

@@ -0,0 +1,57 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
{
'name': 'Account Banking Mandate',
'summary': 'Banking mandates',
'version': '0.1',
'license': 'AGPL-3',
'author': 'Compassion CH',
'website': 'http://www.compassion.ch',
'contributors': ['Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>'],
'category': 'Banking addons',
'depends': [
'account_payment',
],
'data': [
'views/account_banking_mandate_view.xml',
'views/account_invoice_view.xml',
'views/account_payment_view.xml',
'views/res_partner_bank_view.xml',
'data/mandate_reference_sequence.xml',
'security/ir.model.access.csv',
],
'demo': [],
'test': ['test/banking_mandate.yml'],
'description': '''
This module adds a generic model for banking mandates.
These mandates can be specialized to fit any banking mandates (such as
sepa or lsv).
A banking mandate is attached to a bank account and represents an
authorization that the bank account owner gives to a company for a
specific operation (such as direct debit).
You can setup mandates from the accounting menu or directly from a bank
account.
''',
'installable': True,
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="dd_mandate_seq_type" model="ir.sequence.type">
<field name="name">DD Mandate Reference</field>
<field name="code">account.banking.mandate</field>
</record>
<record id="dd_mandate_seq" model="ir.sequence">
<field name="name">DD Mandate Reference</field>
<field name="code">account.banking.mandate</field>
<field name="prefix">BM</field>
<field name="padding" eval="7"/>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from . import account_banking_mandate
from . import account_invoice
from . import res_partner_bank
from . import payment_line

View File

@@ -0,0 +1,154 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields, exceptions, api, _
class AccountBankingMandate(models.Model):
''' The banking mandate is attached to a bank account and represents an
authorization that the bank account owner gives to a company for a
specific operation (such as direct debit)
'''
_name = 'account.banking.mandate'
_description = "A generic banking mandate"
_rec_name = 'unique_mandate_reference'
_inherit = ['mail.thread']
_order = 'signature_date desc'
_track = {
'state': {
'account_banking_mandate.mandate_valid': (
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'valid'),
'account_banking_mandate.mandate_expired': (
lambda self, cr, uid, obj, ctx=None:
obj['state'] == 'expired'),
'account_banking_mandate.mandate_cancel': (
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel'),
},
}
def _get_states(self):
return [('draft', 'Draft'),
('valid', 'Valid'),
('expired', 'Expired'),
('cancel', 'Cancelled')]
partner_bank_id = fields.Many2one(
comodel_name='res.partner.bank', string='Bank Account',
track_visibility='onchange')
partner_id = fields.Many2one(
comodel_name='res.partner', relation='partner_bank_id.partner_id',
string='Partner', readonly=True, store=True)
company_id = fields.Many2one(
comodel_name='res.company', string='Company', required=True,
default=lambda self: self.env['res.company']._company_default_get(
'account.banking.mandate'))
unique_mandate_reference = fields.Char(
string='Unique Mandate Reference', track_visibility='always',
default='/')
signature_date = fields.Date(string='Date of Signature of the Mandate',
track_visibility='onchange')
scan = fields.Binary(string='Scan of the Mandate')
last_debit_date = fields.Date(string='Date of the Last Debit',
readonly=True)
state = fields.Selection(
_get_states, string='Status', default='draft',
help="Only valid mandates can be used in a payment line. A cancelled "
"mandate is a mandate that has been cancelled by the customer.")
payment_line_ids = fields.One2many(
comodel_name='payment.line', inverse_name='mandate_id',
string="Related Payment Lines")
_sql_constraints = [(
'mandate_ref_company_uniq',
'unique(unique_mandate_reference, company_id)',
'A Mandate with the same reference already exists for this company !')]
@api.one
@api.constrains('signature_date', 'last_debit_date')
def _check_dates(self):
if (self.signature_date and
self.signature_date > fields.Date.context_today(self)):
raise exceptions.Warning(
_("The date of signature of mandate '%s' is in the future !")
% self.unique_mandate_reference)
if (self.signature_date and self.last_debit_date and
self.signature_date > self.last_debit_date):
raise exceptions.Warning(
_("The mandate '%s' can't have a date of last debit before "
"the date of signature.") % self.unique_mandate_reference)
@api.one
@api.constrains('state', 'partner_bank_id')
def _check_valid_state(self):
if self.state == 'valid':
if not self.signature_date:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' without a date of "
"signature.") % self.unique_mandate_reference)
if not self.partner_bank_id:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' because it is not "
"attached to a bank account.") %
self.unique_mandate_reference)
@api.model
def create(self, vals=None):
if vals.get('unique_mandate_reference', '/') == '/':
vals['unique_mandate_reference'] = \
self.env['ir.sequence'].next_by_code('account.banking.mandate')
return super(AccountBankingMandate, self).create(vals)
@api.one
@api.onchange('partner_bank_id')
def mandate_partner_bank_change(self):
self.partner_id = self.partner_bank_id.partner_id
@api.multi
def validate(self):
for mandate in self:
if mandate.state != 'draft':
raise exceptions.Warning(
_('Mandate should be in draft state'))
self.write({'state': 'valid'})
return True
@api.multi
def cancel(self):
for mandate in self:
if mandate.state not in ('draft', 'valid'):
raise exceptions.Warning(
_('Mandate should be in draft or valid state'))
self.write({'state': 'cancel'})
return True
@api.multi
def back2draft(self):
"""Allows to set the mandate back to the draft state.
This is for mandates cancelled by mistake.
"""
for mandate in self:
if mandate.state != 'cancel':
raise exceptions.Warning(
_('Mandate should be in cancel state'))
self.write({'state': 'draft'})
return True

View File

@@ -1,32 +1,33 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Direct Debit module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
sdd_mandate_id = fields.Many2one(
'sdd.mandate', string='SEPA Direct Debit Mandate',
domain=[('state', '=', 'valid')], readonly=True,
states={'draft': [('readonly', False)]})
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
mandate_id = fields.Many2one(
'account.banking.mandate', string='Direct Debit Mandate',
domain=[('state', '=', 'valid')], readonly=True,
states={'draft': [('readonly', False)]})

View File

@@ -0,0 +1,76 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields, api, exceptions, _
class PaymentLine(models.Model):
_inherit = 'payment.line'
mandate_id = fields.Many2one(
comodel_name='account.banking.mandate', string='Direct Debit Mandate',
domain=[('state', '=', 'valid')])
@api.multi
def create(self, vals=None):
"""If the customer invoice has a mandate, take it
otherwise, take the first valid mandate of the bank account
"""
if vals is None:
vals = {}
partner_bank_id = vals.get('bank_id')
move_line_id = vals.get('move_line_id')
if (self.env.context.get('search_payment_order_type') == 'debit'
and 'mandate_id' not in vals):
if move_line_id:
line = self.env['account.move.line'].browse(move_line_id)
if (line.invoice and line.invoice.type == 'out_invoice'
and line.invoice.mandate_id):
vals.update({
'mandate_id': line.invoice.mandate_id.id,
'bank_id': line.invoice.mandate_id.partner_bank_id.id,
})
if partner_bank_id and 'mandate_id' not in vals:
mandates = self.env['account.banking.mandate'].search(
[('partner_bank_id', '=', partner_bank_id),
('state', '=', 'valid')])
if mandates:
vals['mandate_id'] = mandates.id
return super(PaymentLine, self).create(vals)
@api.one
@api.constrains('mandate_id', 'bank_id')
def _check_mandate_bank_link(self, cr, uid, ids):
if (self.mandate_id and self.bank_id
and self.mandate_id.partner_bank_id.id !=
self.bank_id.id):
raise exceptions.Warning(
_("The payment line with reference '%s' has the bank account "
"'%s' which is not attached to the mandate '%s' (this "
"mandate is attached to the bank account '%s').") %
(self.name,
self.env['res.partner.bank'].name_get(
[self.bank_id.id])[0][1],
self.mandate_id.unique_mandate_reference,
self.env['res.partner.bank'].name_get(
[self.mandate_id.partner_bank_id.id])[0][1]))

View File

@@ -0,0 +1,34 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Mandate module for openERP
# Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
# @author: Cyril Sester <csester@compassion.ch>,
# Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields
class ResPartnerBank(models.Model):
_inherit = 'res.partner.bank'
mandate_ids = fields.One2many(
comodel_name='account.banking.mandate', inverse_name='partner_bank_id',
string='Direct Debit Mandates',
help='Banking mandates represents an authorization that the bank '
'account owner gives to a company for a specific operation')

View File

@@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_account_banking_mandate","Full access on account.banking.mandate","model_account_banking_mandate","account_payment.group_account_payment",1,1,1,1
"access_account_banking_mandate_read","Read access on account.banking.mandate","model_account_banking_mandate","base.group_user",1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_account_banking_mandate Full access on account.banking.mandate model_account_banking_mandate account_payment.group_account_payment 1 1 1 1
3 access_account_banking_mandate_read Read access on account.banking.mandate model_account_banking_mandate base.group_user 1 0 0 0

View File

@@ -0,0 +1,36 @@
-
In order to test mandate, I create a partner with a bank account.
Then, I create a mandate, validate it, cancel it and the set it back to draft
I create a partner
-
!record {model: res.partner, id: mandate_partner, view: False}:
name: "Mandate test"
-
I create a partner bank account
-
!record {model: res.partner.bank, id: mandate_partner_bank, view: False}:
state: 'bank'
acc_number: '1234'
partner_id: mandate_partner
-
I create a mandate on 1st January
-
!record {model: account.banking.mandate, id: test_mandate, view: False}:
partner_bank_id: mandate_partner_bank
signature_date: "2014-01-01"
-
I check that the state field is automatically set by default
-
!assert {model: account.banking.mandate, id: test_mandate}:
- state == 'draft'
-
I go through all states by clicking on buttons and check that cancel state is reached
-
!python {model: account.banking.mandate}: |
self.validate(cr, uid, [ref('test_mandate')])
self.cancel(cr, uid, [ref('test_mandate')])
mandate = self.browse(cr, uid, ref('test_mandate'))
assert mandate.state == 'cancel', 'Mandate is not in cancel state'
self.back2draft(cr, uid, [ref('test_mandate')])

View File

@@ -0,0 +1,122 @@
<?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"
readonly="1"/>
</h1>
</div>
<group name="main">
<field name="company_id" groups="base.group_multi_company"/>
<field name="partner_bank_id"
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>

View File

@@ -8,12 +8,12 @@
<data>
<record id="invoice_form" model="ir.ui.view">
<field name="name">add.sdd.mandate.on.customer.invoice.form</field>
<field name="name">add.mandate.on.customer.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<field name="partner_bank_id" position="after">
<field name="sdd_mandate_id" domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]" attrs="{'invisible': [('type', '=', 'out_refund')]}"/>
<field name="mandate_id" domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]" attrs="{'invisible': [('type', '=', 'out_refund')]}"/>
</field>
</field>
</record>

View File

@@ -7,17 +7,17 @@
<openerp>
<data>
<record id="sdd_view_payment_order_form" model="ir.ui.view">
<field name="name">sdd.payment.order.form</field>
<record id="view_mandate_payment_order_form" model="ir.ui.view">
<field name="name">mandate.payment.order.form</field>
<field name="model">payment.order</field>
<field name="inherit_id" ref="account_payment.view_payment_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='line_ids']/form/notebook/page/group/field[@name='bank_id']" position="after">
<field name="sdd_mandate_id" domain="[('partner_bank_id', '=', bank_id), ('state', '=', 'valid')]" invisible="context.get('default_payment_order_type')!='debit'" context="{'default_partner_bank_id': bank_id}"/>
<field name="mandate_id" domain="[('partner_bank_id', '=', bank_id), ('state', '=', 'valid')]" invisible="context.get('search_payment_order_type')!='debit'" context="{'default_partner_bank_id': bank_id}"/>
<newline />
</xpath>
<xpath expr="//field[@name='line_ids']/tree/field[@name='bank_id']" position="after">
<field name="sdd_mandate_id" string="SDD Mandate" invisible="context.get('default_payment_order_type')!='debit'"/>
<field name="mandate_id" string="DD Mandate" invisible="context.get('search_payment_order_type')!='debit'"/>
</xpath>
</field>
</record>

View File

@@ -7,39 +7,39 @@
<openerp>
<data>
<record id="sdd_mandate_partner_bank_form" model="ir.ui.view">
<field name="name">sdd.mandate.res.partner.bank.form</field>
<record id="mandate_partner_bank_form" model="ir.ui.view">
<field name="name">mandate.res.partner.bank.form</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_form"/>
<field name="arch" type="xml">
<group name="bank" position="after">
<group name="sdd_mandates" string="SEPA Direct Debit Mandates" colspan="4">
<field name="sdd_mandate_ids" context="{'default_partner_bank_id': active_id, 'sdd_mandate_bank_partner_view': True}" nolabel="1"/>
<group name="mandates" string="Direct Debit Mandates" colspan="4">
<field name="mandate_ids" context="{'default_partner_bank_id': active_id, 'mandate_bank_partner_view': True}" nolabel="1"/>
</group>
</group>
</field>
</record>
<record id="sdd_mandate_partner_bank_tree" model="ir.ui.view">
<field name="name">sdd.mandate.res.partner.bank.tree</field>
<record id="mandate_partner_bank_tree" model="ir.ui.view">
<field name="name">mandate.res.partner.bank.tree</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="base.view_partner_bank_tree"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="sdd_mandate_ids" string="SDD Mandates"/>
<field name="mandate_ids" string="DD Mandates"/>
</field>
</field>
</record>
<!-- add number of mandates in this list of bank accounts
on the partner form -->
<record id="sdd_mandate_partner_form" model="ir.ui.view">
<field name="name">sdd.mandate.partner.form</field>
<record id="mandate_partner_form" model="ir.ui.view">
<field name="name">mandate.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bank_ids']/tree/field[@name='owner_name']" position="after">
<field name="sdd_mandate_ids" string="SDD Mandates"/>
<field name="mandate_ids" string="DD Mandates"/>
</xpath>
</field>
</record>

View File

@@ -34,15 +34,11 @@
},
'data': [
'views/account_banking_sdd_view.xml',
'views/sdd_mandate_view.xml',
'views/res_partner_bank_view.xml',
'views/account_payment_view.xml',
'views/account_banking_mandate_view.xml',
'views/res_company_view.xml',
'views/account_invoice_view.xml',
'wizard/export_sdd_view.xml',
'data/mandate_expire_cron.xml',
'data/payment_type_sdd.xml',
'data/mandate_reference_sequence.xml',
'security/original_mandate_required_security.xml',
'security/ir.model.access.csv',
],

View File

@@ -7,20 +7,18 @@
-->
<openerp>
<data noupdate="1"> <!-- noupdate = 1 for the 'active' field -->
<record id="sdd_mandate_expire_cron" model="ir.cron">
<field name="name">Set SEPA Direct Debit Mandates to Expired</field>
<field name="active" eval="True"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field> <!-- don't limit the number of calls -->
<field name="doall" eval="False"/>
<field name="model" eval="'sdd.mandate'"/>
<field name="function" eval="'_sdd_mandate_set_state_to_expired'" />
<field name="args" eval="'()'"/>
</record>
</data>
<data noupdate="1">
<record id="sdd_mandate_expire_cron" model="ir.cron">
<field name="name">Set SEPA Direct Debit Mandates to Expired</field>
<field name="active" eval="True"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'account.banking.mandate'"/>
<field name="function" eval="'_sdd_mandate_set_state_to_expired'" />
<field name="args" eval="'()'"/>
</record>
</data>
</openerp>

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="sdd_mandate_seq_type" model="ir.sequence.type">
<field name="name">SDD Mandate Reference</field>
<field name="code">sdd.mandate.reference</field>
</record>
<record id="sdd_mandate_seq" model="ir.sequence">
<field name="name">SDD Mandate Reference</field>
<field name="code">sdd.mandate.reference</field>
<field name="prefix">RUM</field>
<field name="padding" eval="7"/>
<!-- remember that max size for the mandate ref is 35 -->
</record>
</data>
</openerp>

View File

@@ -15,7 +15,7 @@
<field name="sepa_creditor_identifier">FR78ZZZ424242</field>
</record>
<record id="res_partner_12_mandate" model="sdd.mandate">
<record id="res_partner_12_mandate" model="account.banking.mandate">
<field name="partner_bank_id" ref="account_banking_payment_export.res_partner_12_iban"/>
<field name="type">recurrent</field>
<field name="recurrent_sequence_type">first</field>

View File

@@ -20,9 +20,6 @@
#
##############################################################################
from . import account_invoice
from . import banking_export_sdd
from . import payment_line
from . import res_company
from . import res_partner_bank
from . import sdd_mandate
from . import account_banking_mandate

View File

@@ -0,0 +1,145 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Direct Debit module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields, api, exceptions, _
from datetime import datetime
from dateutil.relativedelta import relativedelta
import logging
NUMBER_OF_UNUSED_MONTHS_BEFORE_EXPIRY = 36
logger = logging.getLogger(__name__)
class AccountBankingMandate(models.Model):
"""SEPA Direct Debit Mandate"""
_inherit = 'account.banking.mandate'
_track = {
'recurrent_sequence_type': {
'account_banking_sepa_direct_debit.recurrent_sequence_type_first':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'first',
'account_banking_sepa_direct_debit.'
'recurrent_sequence_type_recurring':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'recurring',
'account_banking_sepa_direct_debit.recurrent_sequence_type_final':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'final',
}
}
type = fields.Selection([('recurrent', 'Recurrent'),
('oneoff', 'One-Off')],
string='Type of Mandate', required=True,
track_visibility='always')
recurrent_sequence_type = fields.Selection(
[('first', 'First'),
('recurring', 'Recurring'),
('final', 'Final')],
string='Sequence Type for Next Debit', track_visibility='onchange',
help="This field is only used for Recurrent mandates, not for "
"One-Off mandates.", default="first")
sepa_migrated = fields.Boolean(
string='Migrated to SEPA', track_visibility='onchange',
help="If this field is not active, the mandate section of the next "
"direct debit file that include this mandate will contain the "
"'Original Mandate Identification' and the 'Original Creditor "
"Scheme Identification'. This is required in a few countries "
"(Belgium for instance), but not in all countries. If this is "
"not required in your country, you should keep this field always "
"active.", default=True)
original_mandate_identification = fields.Char(
string='Original Mandate Identification', track_visibility='onchange',
help="When the field 'Migrated to SEPA' is not active, this field "
"will be used as the Original Mandate Identification in the "
"Direct Debit file.")
scheme = fields.Selection([('CORE', 'Basic (CORE)'),
('B2B', 'Enterprise (B2B)')],
string='Scheme', required=True, default="CORE")
@api.one
@api.constrains('type', 'recurrent_sequence_type')
def _check_recurring_type(self):
if (self.type == 'recurrent'
and not self.recurrent_sequence_type):
raise exceptions.Warning(
_("The recurrent mandate '%s' must have a sequence type.")
% self.unique_mandate_reference)
@api.one
@api.constrains('type', 'recurrent_sequence_type', 'sepa_migrated')
def _check_migrated_to_sepa(self):
if (self.type == 'recurrent' and not self.sepa_migrated
and self.recurrent_sequence_type != 'first'):
raise exceptions.Warning(
_("The recurrent mandate '%s' which is not marked as "
"'Migrated to SEPA' must have its recurrent sequence type "
"set to 'First'.") % self.unique_mandate_reference)
@api.one
@api.constrains('type', 'original_mandate_identification', 'sepa_migrated')
def _check_original_mandate_identification(self):
if (self.type == 'recurrent' and not self.sepa_migrated
and not self.original_mandate_identification):
raise exceptions.Warning(
_("You must set the 'Original Mandate Identification' on the "
"recurrent mandate '%s' which is not marked as 'Migrated to "
"SEPA'.") % self.unique_mandate_reference)
@api.one
@api.onchange('partner_bank_id')
def mandate_partner_bank_change(self):
super(AccountBankingMandate, self).mandate_partner_bank_change()
res = {}
if (self.state == 'valid' and self.partner_bank_id
and self.type == 'recurrent'
and self.recurrent_sequence_type != 'first'):
self.recurrent_sequence_type = 'first'
res['warning'] = {
'title': _('Mandate update'),
'message': _("As you changed the bank account attached to "
"this mandate, the 'Sequence Type' has been set "
"back to 'First'."),
}
return res
@api.multi
def _sdd_mandate_set_state_to_expired(self):
logger.info('Searching for SDD Mandates that must be set to Expired')
expire_limit_date = datetime.today() + \
relativedelta(months=-NUMBER_OF_UNUSED_MONTHS_BEFORE_EXPIRY)
expire_limit_date_str = expire_limit_date.strftime('%Y-%m-%d')
expired_mandates = self.search(
['|',
('last_debit_date', '=', False),
('last_debit_date', '<=', expire_limit_date_str),
('state', '=', 'valid'),
('signature_date', '<=', expire_limit_date_str)])
if expired_mandates:
expired_mandates.write({'state': 'expired'})
logger.info(
'The following SDD Mandate IDs has been set to expired: %s'
% expired_mandates.ids)
else:
logger.info('0 SDD Mandates must be set to Expired')
return True

View File

@@ -1,74 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Direct Debit module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp import models, fields, api, exceptions, _
class PaymentLine(models.Model):
_inherit = 'payment.line'
sdd_mandate_id = fields.Many2one(
'sdd.mandate', string='SEPA Direct Debit Mandate',
domain=[('state', '=', 'valid')])
def create(self, vals=None):
"""If the customer invoice has a mandate, take it. Otherwise, take the
first valid mandate of the bank account.
"""
if not vals:
vals = {}
partner_bank_id = vals.get('bank_id')
if (self.env.context.get('search_payment_order_type') == 'debit'
and 'sdd_mandate_id' not in vals):
if vals.get('move_line_id'):
line = self.env['account.move.line'].browse(
vals['move_line_id'])
if (line.invoice and line.invoice.type == 'out_invoice'
and line.invoice.sdd_mandate_id):
vals.update(
{'sdd_mandate_id': line.invoice.sdd_mandate_id.id,
'bank_id':
line.invoice.sdd_mandate_id.partner_bank_id.id})
if partner_bank_id and 'sdd_mandate_id' not in vals:
mandates = self.env['sdd.mandate'].search(
[('partner_bank_id', '=', partner_bank_id),
('state', '=', 'valid')])
if mandates:
vals['sdd_mandate_id'] = mandates.ids[0]
return super(PaymentLine, self).create(vals)
@api.one
@api.constrains('sdd_mandate_id', 'bank_id')
def _check_mandate_bank_link(self):
if (self.sdd_mandate_id and self.bank_id
and self.sdd_mandate_id.partner_bank_id.id !=
self.bank_id.id):
raise exceptions.Warning(
_('Error:'),
_("The payment line with reference '%s' has the bank "
"account '%s' which is not attached to the mandate "
"'%s' (this mandate is attached to the bank account "
"'%s').") %
(self.name,
self.bank_id.name_get()[0][1],
self.sdd_mandate_id.unique_mandate_reference,
self.sdd_mandate_id.partner_bank_id.name_get()[0][1]))

View File

@@ -1,291 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# SEPA Direct Debit module for OpenERP
# Copyright (C) 2013 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.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/>.
#
##############################################################################
from openerp.osv import orm, fields
from openerp.tools.translate import _
from datetime import datetime
from dateutil.relativedelta import relativedelta
import logging
NUMBER_OF_UNUSED_MONTHS_BEFORE_EXPIRY = 36
logger = logging.getLogger(__name__)
class SddMandate(orm.Model):
"""SEPA Direct Debit Mandate"""
_name = 'sdd.mandate'
_description = __doc__
_rec_name = 'unique_mandate_reference'
_inherit = ['mail.thread']
_order = 'signature_date desc'
_track = {
'state': {
'account_banking_sepa_direct_debit.mandate_valid':
lambda self, cr, uid, obj, ctx=None:
obj['state'] == 'valid',
'account_banking_sepa_direct_debit.mandate_expired':
lambda self, cr, uid, obj, ctx=None:
obj['state'] == 'expired',
'account_banking_sepa_direct_debit.mandate_cancel':
lambda self, cr, uid, obj, ctx=None:
obj['state'] == 'cancel',
},
'recurrent_sequence_type': {
'account_banking_sepa_direct_debit.recurrent_sequence_type_first':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'first',
'account_banking_sepa_direct_debit.'
'recurrent_sequence_type_recurring':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'recurring',
'account_banking_sepa_direct_debit.recurrent_sequence_type_final':
lambda self, cr, uid, obj, ctx=None:
obj['recurrent_sequence_type'] == 'final',
}
}
_columns = {
'partner_bank_id': fields.many2one(
'res.partner.bank', 'Bank Account', track_visibility='onchange'),
'partner_id': fields.related(
'partner_bank_id', 'partner_id', type='many2one',
relation='res.partner', string='Partner', readonly=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'unique_mandate_reference': fields.char(
'Unique Mandate Reference', size=35, readonly=True,
track_visibility='always'),
'type': fields.selection([
('recurrent', 'Recurrent'),
('oneoff', 'One-Off'),
], 'Type of Mandate', required=True, track_visibility='always'),
'recurrent_sequence_type': fields.selection([
('first', 'First'),
('recurring', 'Recurring'),
('final', 'Final'),
], 'Sequence Type for Next Debit', track_visibility='onchange',
help="This field is only used for Recurrent mandates, not for "
"One-Off mandates."),
'signature_date': fields.date(
'Date of Signature of the Mandate', track_visibility='onchange'),
'scan': fields.binary('Scan of the Mandate'),
'last_debit_date': fields.date(
'Date of the Last Debit', readonly=True),
'state': fields.selection([
('draft', 'Draft'),
('valid', 'Valid'),
('expired', 'Expired'),
('cancel', 'Cancelled'),
], 'Status',
help="Only valid mandates can be used in a payment line. A "
"cancelled mandate is a mandate that has been cancelled by "
"the customer. A one-off mandate expires after its first use. "
"A recurrent mandate expires after it's final use or if it "
"hasn't been used for 36 months."),
'payment_line_ids': fields.one2many(
'payment.line', 'sdd_mandate_id', "Related Payment Lines"),
'sepa_migrated': fields.boolean(
'Migrated to SEPA', track_visibility='onchange',
help="If this field is not active, the mandate section of the "
"next direct debit file that include this mandate will contain "
"the 'Original Mandate Identification' and the 'Original "
"Creditor Scheme Identification'. This is required in a few "
"countries (Belgium for instance), but not in all countries. "
"If this is not required in your country, you should keep this "
"field always active."),
'original_mandate_identification': fields.char(
'Original Mandate Identification', size=35,
track_visibility='onchange',
help="When the field 'Migrated to SEPA' is not active, this "
"field will be used as the Original Mandate Identification in "
"the Direct Debit file."),
'scheme': fields.selection([('CORE', 'Basic (CORE)'),
('B2B', 'Enterprise (B2B)')],
'Scheme', required=True),
}
_defaults = {
'company_id': lambda self, cr, uid, context:
self.pool['res.company']._company_default_get(
cr, uid, 'sdd.mandate', context=context),
'unique_mandate_reference': '/',
'state': 'draft',
'sepa_migrated': True,
'scheme': 'CORE',
}
_sql_constraints = [(
'mandate_ref_company_uniq',
'unique(unique_mandate_reference, company_id)',
'A Mandate with the same reference already exists for this company !'
)]
def create(self, cr, uid, vals, context=None):
if vals.get('unique_mandate_reference', '/') == '/':
vals['unique_mandate_reference'] = \
self.pool['ir.sequence'].next_by_code(
cr, uid, 'sdd.mandate.reference', context=context)
return super(SddMandate, self).create(cr, uid, vals, context=context)
def _check_sdd_mandate(self, cr, uid, ids):
for mandate in self.browse(cr, uid, ids):
if (mandate.signature_date and
mandate.signature_date >
datetime.today().strftime('%Y-%m-%d')):
raise orm.except_orm(
_('Error:'),
_("The date of signature of mandate '%s' is in the "
"future !")
% mandate.unique_mandate_reference)
if mandate.state == 'valid' and not mandate.signature_date:
raise orm.except_orm(
_('Error:'),
_("Cannot validate the mandate '%s' without a date of "
"signature.")
% mandate.unique_mandate_reference)
if mandate.state == 'valid' and not mandate.partner_bank_id:
raise orm.except_orm(
_('Error:'),
_("Cannot validate the mandate '%s' because it is not "
"attached to a bank account.")
% mandate.unique_mandate_reference)
if (mandate.signature_date and mandate.last_debit_date and
mandate.signature_date > mandate.last_debit_date):
raise orm.except_orm(
_('Error:'),
_("The mandate '%s' can't have a date of last debit "
"before the date of signature.")
% mandate.unique_mandate_reference)
if (mandate.type == 'recurrent'
and not mandate.recurrent_sequence_type):
raise orm.except_orm(
_('Error:'),
_("The recurrent mandate '%s' must have a sequence type.")
% mandate.unique_mandate_reference)
if (mandate.type == 'recurrent' and not mandate.sepa_migrated
and mandate.recurrent_sequence_type != 'first'):
raise orm.except_orm(
_('Error:'),
_("The recurrent mandate '%s' which is not marked as "
"'Migrated to SEPA' must have its recurrent sequence "
"type set to 'First'.")
% mandate.unique_mandate_reference)
if (mandate.type == 'recurrent' and not mandate.sepa_migrated
and not mandate.original_mandate_identification):
raise orm.except_orm(
_('Error:'),
_("You must set the 'Original Mandate Identification' "
"on the recurrent mandate '%s' which is not marked "
"as 'Migrated to SEPA'.")
% mandate.unique_mandate_reference)
return True
_constraints = [
(_check_sdd_mandate, "Error msg in raise", [
'last_debit_date', 'signature_date', 'state', 'partner_bank_id',
'type', 'recurrent_sequence_type', 'sepa_migrated',
'original_mandate_identification',
]),
]
def mandate_type_change(self, cr, uid, ids, type):
if type == 'recurrent':
recurrent_sequence_type = 'first'
else:
recurrent_sequence_type = False
res = {'value': {'recurrent_sequence_type': recurrent_sequence_type}}
return res
def mandate_partner_bank_change(
self, cr, uid, ids, partner_bank_id, type, recurrent_sequence_type,
last_debit_date, state):
res = {'value': {}}
if partner_bank_id:
partner_bank_read = self.pool['res.partner.bank'].read(
cr, uid, partner_bank_id, ['partner_id'])['partner_id']
if partner_bank_read:
res['value']['partner_id'] = partner_bank_read[0]
if (state == 'valid' and partner_bank_id
and type == 'recurrent'
and recurrent_sequence_type != 'first'):
res['value']['recurrent_sequence_type'] = 'first'
res['warning'] = {
'title': _('Mandate update'),
'message': _(
"As you changed the bank account attached to this "
"mandate, the 'Sequence Type' has been set back to "
"'First'."),
}
return res
def validate(self, cr, uid, ids, context=None):
to_validate_ids = []
for mandate in self.browse(cr, uid, ids, context=context):
assert mandate.state == 'draft', 'Mandate should be in draft state'
to_validate_ids.append(mandate.id)
self.write(
cr, uid, to_validate_ids, {'state': 'valid'}, context=context)
return True
def cancel(self, cr, uid, ids, context=None):
to_cancel_ids = []
for mandate in self.browse(cr, uid, ids, context=context):
assert mandate.state in ('draft', 'valid'),\
'Mandate should be in draft or valid state'
to_cancel_ids.append(mandate.id)
self.write(
cr, uid, to_cancel_ids, {'state': 'cancel'}, context=context)
return True
def back2draft(self, cr, uid, ids, context=None):
to_draft_ids = []
for mandate in self.browse(cr, uid, ids, context=context):
assert mandate.state == 'cancel',\
'Mandate should be in cancel state'
to_draft_ids.append(mandate.id)
self.write(
cr, uid, to_draft_ids, {'state': 'draft'}, context=context)
return True
def _sdd_mandate_set_state_to_expired(self, cr, uid, context=None):
logger.info('Searching for SDD Mandates that must be set to Expired')
expire_limit_date = datetime.today() + \
relativedelta(months=-NUMBER_OF_UNUSED_MONTHS_BEFORE_EXPIRY)
expire_limit_date_str = expire_limit_date.strftime('%Y-%m-%d')
expired_mandate_ids = self.search(cr, uid, [
'|',
('last_debit_date', '=', False),
('last_debit_date', '<=', expire_limit_date_str),
('state', '=', 'valid'),
('signature_date', '<=', expire_limit_date_str),
], context=context)
if expired_mandate_ids:
self.write(
cr, uid, expired_mandate_ids, {'state': 'expired'},
context=context)
logger.info(
'The following SDD Mandate IDs has been set to expired: %s'
% expired_mandate_ids)
else:
logger.info('0 SDD Mandates must be set to Expired')
return True

View File

@@ -1,4 +1,2 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_banking_export_sdd","Full access on banking.export.sdd","model_banking_export_sdd","account_payment.group_account_payment",1,1,1,1
"access_sdd_mandate","Full access on sdd.mandate","model_sdd_mandate","account_payment.group_account_payment",1,1,1,1
"access_sdd_mandate_read","Read access on sdd.mandate","model_sdd_mandate","base.group_user",1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_banking_export_sdd Full access on banking.export.sdd model_banking_export_sdd account_payment.group_account_payment 1 1 1 1
access_sdd_mandate Full access on sdd.mandate model_sdd_mandate account_payment.group_account_payment 1 1 1 1
access_sdd_mandate_read Read access on sdd.mandate model_sdd_mandate base.group_user 1 0 0 0

View File

@@ -0,0 +1,117 @@
<?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
-->
<!--
Customize all mandate views (and actions) to fit SEPA mandate style
-->
<openerp>
<data>
<record id="sdd_mandate_form" model="ir.ui.view">
<field name="name">sdd.mandate.form</field>
<field name="model">account.banking.mandate</field>
<field name="inherit_id" ref="account_banking_mandate.view_mandate_form"/>
<field name="arch" type="xml">
<data>
<field name="partner_id" position="after">
<field name="type"/>
<field name="recurrent_sequence_type" attrs="{'invisible': [('type', '=', 'oneoff')], 'required': [('type', '=', 'recurrent')]}"/>
</field>
<field name="last_debit_date" position="after">
<field name="sepa_migrated" groups="account_banking_sepa_direct_debit.group_original_mandate_required"/>
<field name="original_mandate_identification" attrs="{'invisible': [('sepa_migrated', '=', True)], 'required': [('sepa_migrated', '=', False)]}" groups="account_banking_sepa_direct_debit.group_original_mandate_required"/>
</field>
</data>
</field>
</record>
<record id="sdd_mandate_tree" model="ir.ui.view">
<field name="name">sdd.mandate.tree</field>
<field name="model">account.banking.mandate</field>
<field name="inherit_id" ref="account_banking_mandate.view_mandate_tree"/>
<field name="arch" type="xml">
<field name="unique_mandate_reference" position="after">
<field name="type" string="Type"/>
</field>
</field>
</record>
<record id="sdd_mandate_search" model="ir.ui.view">
<field name="name">sdd.mandate.search</field>
<field name="model">account.banking.mandate</field>
<field name="inherit_id" ref="account_banking_mandate.view_mandate_search"/>
<field name="arch" type="xml">
<filter name="expired" position="after">
<filter name="oneoff" string="One-Off" domain="[('type', '=', 'oneoff')]" />
<filter name="recurrent" string="Recurrent" domain="[('type', '=', 'recurrent')]" />
</filter>
</field>
</record>
<record id="mandate_action" model="ir.actions.act_window">
<field name="name">SEPA Direct Debit 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 SEPA Direct Debit Mandate.
</p><p>
A SEPA Direct Debit Mandate is a document signed by your customer that gives you the autorization to do one or several direct debits on his bank account.
</p>
</field>
</record>
<menuitem id="account_banking_mandate.mandate_menu"
parent="account_payment.menu_main_payment"
action="mandate_action"
sequence="20"
/>
<record id="sdd_mandate_partner_bank_tree" model="ir.ui.view">
<field name="name">sdd.mandate.res.partner.bank.tree</field>
<field name="model">res.partner.bank</field>
<field name="inherit_id" ref="account_banking_mandate.mandate_partner_bank_tree"/>
<field name="arch" type="xml">
<field name="mandate_ids" position="attributes">
<attribute name="string">SDD Mandates</attribute>
</field>
</field>
</record>
<record id="sdd_mandate_partner_form" model="ir.ui.view">
<field name="name">sdd.mandate.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account_banking_mandate.mandate_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='bank_ids']/tree/field[@name='mandate_ids']" position="attributes">
<attribute name="string">SDD Mandates</attribute>
</xpath>
</field>
</record>
<record id="recurrent_sequence_type_first" model="mail.message.subtype">
<field name="name">Sequence Type set to First</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to First</field>
</record>
<record id="recurrent_sequence_type_recurring" model="mail.message.subtype">
<field name="name">Sequence Type set to Recurring</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to Recurring</field>
</record>
<record id="recurrent_sequence_type_final" model="mail.message.subtype">
<field name="name">Sequence Type set to Final</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to Final</field>
</record>
</data>
</openerp>

View File

@@ -1,153 +0,0 @@
<?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="sdd_mandate_form" model="ir.ui.view">
<field name="name">sdd.mandate.form</field>
<field name="model">sdd.mandate</field>
<field name="arch" type="xml">
<form string="SEPA Direct Debit 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, type, recurrent_sequence_type, last_debit_date, state)"
invisible="context.get('sdd_mandate_bank_partner_view')"
/>
<field name="partner_id" invisible="context.get('sdd_mandate_bank_partner_view')"/>
<field name="type" on_change="mandate_type_change(type)"/>
<field name="recurrent_sequence_type" attrs="{'invisible': [('type', '=', 'oneoff')], 'required': [('type', '=', 'recurrent')]}"/>
<field name="scheme"/>
<field name="signature_date"/>
<field name="scan"/>
<field name="last_debit_date"/>
<field name="sepa_migrated" groups="account_banking_sepa_direct_debit.group_original_mandate_required"/>
<field name="original_mandate_identification" attrs="{'invisible': [('sepa_migrated', '=', True)], 'required': [('sepa_migrated', '=', False)]}" groups="account_banking_sepa_direct_debit.group_original_mandate_required"/>
</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="sdd_mandate_tree" model="ir.ui.view">
<field name="name">sdd.mandate.tree</field>
<field name="model">sdd.mandate</field>
<field name="arch" type="xml">
<tree string="SEPA Direct Debit 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('sdd_mandate_bank_partner_view')"/>
<field name="unique_mandate_reference" string="Reference"/>
<field name="type" string="Type"/>
<field name="signature_date" string="Signature Date"/>
<field name="last_debit_date"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="sdd_mandate_search" model="ir.ui.view">
<field name="name">sdd.mandate.search</field>
<field name="model">sdd.mandate</field>
<field name="arch" type="xml">
<search string="Search SEPA Direct Debit 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')]" />
<filter name="oneoff" string="One-Off" domain="[('type', '=', 'oneoff')]" />
<filter name="recurrent" string="Recurrent" domain="[('type', '=', 'recurrent')]" />
</search>
</field>
</record>
<record id="sdd_mandate_action" model="ir.actions.act_window">
<field name="name">SEPA Direct Debit Mandates</field>
<field name="res_model">sdd.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 SEPA Direct Debit Mandate.
</p><p>
A SEPA Direct Debit Mandate is a document signed by your customer that gives you the autorization to do one or several direct debits on his bank account.
</p>
</field>
</record>
<menuitem id="sdd_mandate_menu"
parent="account_payment.menu_main_payment"
action="sdd_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">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">SEPA Direct Debit Mandate Validated</field>
</record>
<record id="mandate_expired" model="mail.message.subtype">
<field name="name">Mandate Expired</field>
<field name="res_model">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">SEPA Direct Debit Mandate has Expired</field>
</record>
<record id="mandate_cancel" model="mail.message.subtype">
<field name="name">Mandate Cancelled</field>
<field name="res_model">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">SEPA Direct Debit Mandate Cancelled</field>
</record>
<record id="recurrent_sequence_type_first" model="mail.message.subtype">
<field name="name">Sequence Type set to First</field>
<field name="res_model">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to First</field>
</record>
<record id="recurrent_sequence_type_recurring" model="mail.message.subtype">
<field name="name">Sequence Type set to Recurring</field>
<field name="res_model">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to Recurring</field>
</record>
<record id="recurrent_sequence_type_final" model="mail.message.subtype">
<field name="name">Sequence Type set to Final</field>
<field name="res_model">sdd.mandate</field>
<field name="default" eval="False"/>
<field name="description">Sequence Type set to Final</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,57 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_payment_partner
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-06-09 23:22+0000\n"
"PO-Revision-Date: 2014-06-09 23:22+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_payment_partner
#: field:res.partner,customer_payment_mode:0
msgid "Customer Payment Mode"
msgstr ""
#. module: account_payment_partner
#: model:ir.model,name:account_payment_partner.model_account_invoice
msgid "Invoice"
msgstr ""
#. module: account_payment_partner
#: model:ir.model,name:account_payment_partner.model_res_partner
msgid "Partner"
msgstr ""
#. module: account_payment_partner
#: field:account.invoice,payment_mode_id:0
msgid "Payment Mode"
msgstr ""
#. module: account_payment_partner
#: help:res.partner,customer_payment_mode:0
msgid "Select the default payment mode for this customer."
msgstr ""
#. module: account_payment_partner
#: help:res.partner,supplier_payment_mode:0
msgid "Select the default payment mode for this supplier."
msgstr ""
#. module: account_payment_partner
#: field:res.partner,supplier_payment_mode:0
msgid "Supplier Payment Mode"
msgstr ""
#. module: account_payment_partner
#: model:ir.model,name:account_payment_partner.model_payment_order_create
msgid "payment.order.create"
msgstr ""