mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MIG] account_banking_mandate: Migration to v9
This commit is contained in:
committed by
Pedro M. Baeza
parent
9e0f5b75dd
commit
4b218c6c46
@@ -1,6 +1,7 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:alt: License: AGPL-3
|
||||
|
||||
=======================
|
||||
Account Banking Mandate
|
||||
=======================
|
||||
|
||||
@@ -31,22 +32,22 @@ Usage
|
||||
|
||||
To use this module, see menu "Accounting > payment > SEPA direct debit mandates"
|
||||
|
||||
For further information, please visit:
|
||||
|
||||
* https://www.odoo.com/forum/help-1
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/173/9.0
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* no known issues
|
||||
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-payment/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
|
||||
`here <https://github.com/OCA/bank-payment/issues/new?body=module:%20account_banking_mandate%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/bank-payment/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
@@ -54,11 +55,11 @@ Credits
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Alexis de Lattre
|
||||
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
* Pedro M. Baeza
|
||||
* Alexandre Fayolle
|
||||
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||
* Sergio Teruel (Incaser) <sergio@incaser.es>
|
||||
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||
* Sergio Teruel (Incaser) <sergio@incaser.es>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import models
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2015 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# © 2015-2016 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': 'Account Banking Mandate',
|
||||
'summary': 'Banking mandates',
|
||||
'version': '8.0.0.2.0',
|
||||
'version': '9.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': "Compassion CH, "
|
||||
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
|
||||
@@ -16,19 +16,21 @@
|
||||
'website': 'https://github.com/OCA/bank-payment',
|
||||
'category': 'Banking addons',
|
||||
'depends': [
|
||||
'account_banking_payment_export',
|
||||
'account_payment_order',
|
||||
],
|
||||
'data': [
|
||||
'views/account_banking_mandate_view.xml',
|
||||
'views/account_payment_method.xml',
|
||||
'views/account_invoice_view.xml',
|
||||
'views/account_payment_view.xml',
|
||||
'views/account_payment_line.xml',
|
||||
'views/res_partner_bank_view.xml',
|
||||
'views/res_partner.xml',
|
||||
'views/bank_payment_line_view.xml',
|
||||
'views/account_move_line.xml',
|
||||
'data/mandate_reference_sequence.xml',
|
||||
'security/mandate_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'demo': [],
|
||||
'test': ['test/banking_mandate.yml'],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -3,11 +3,6 @@
|
||||
<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>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2015 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import account_banking_mandate
|
||||
from . import account_payment_method
|
||||
from . import account_invoice
|
||||
from . import res_partner_bank
|
||||
from . import payment_line
|
||||
from . import res_partner
|
||||
from . import account_payment_line
|
||||
from . import bank_payment_line
|
||||
from . import account_move_line
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2015 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# © 2015-2016 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, exceptions, api, _
|
||||
from openerp import models, fields, api, _
|
||||
from openerp.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class AccountBankingMandate(models.Model):
|
||||
@@ -17,30 +18,10 @@ class AccountBankingMandate(models.Model):
|
||||
_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')]
|
||||
|
||||
format = fields.Selection(
|
||||
[('basic', _('Basic Mandate'))],
|
||||
default='basic',
|
||||
required=True,
|
||||
string='Mandate Format',
|
||||
)
|
||||
[('basic', 'Basic Mandate')], default='basic', required=True,
|
||||
string='Mandate Format', track_visibility='onchange')
|
||||
partner_bank_id = fields.Many2one(
|
||||
comodel_name='res.partner.bank', string='Bank Account',
|
||||
track_visibility='onchange')
|
||||
@@ -52,25 +33,28 @@ class AccountBankingMandate(models.Model):
|
||||
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='/')
|
||||
string='Unique Mandate Reference', track_visibility='onchange')
|
||||
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',
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('valid', 'Valid'),
|
||||
('expired', 'Expired'),
|
||||
('cancel', 'Cancelled'),
|
||||
], string='Status', default='draft', track_visibility='onchange',
|
||||
help="Only valid mandates can be used in a payment line. A cancelled "
|
||||
"mandate is a mandate that has been cancelled by the customer.")
|
||||
"mandate is a mandate that has been cancelled by the customer.")
|
||||
payment_line_ids = fields.One2many(
|
||||
comodel_name='payment.line', inverse_name='mandate_id',
|
||||
comodel_name='account.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 !')]
|
||||
'A Mandate with the same reference already exists for this company!')]
|
||||
|
||||
@api.multi
|
||||
@api.constrains('signature_date', 'last_debit_date')
|
||||
@@ -79,13 +63,13 @@ class AccountBankingMandate(models.Model):
|
||||
if (mandate.signature_date and
|
||||
mandate.signature_date > fields.Date.context_today(
|
||||
mandate)):
|
||||
raise exceptions.Warning(
|
||||
raise ValidationError(
|
||||
_("The date of signature of mandate '%s' "
|
||||
"is in the future !")
|
||||
"is in the future!")
|
||||
% mandate.unique_mandate_reference)
|
||||
if (mandate.signature_date and mandate.last_debit_date and
|
||||
mandate.signature_date > mandate.last_debit_date):
|
||||
raise exceptions.Warning(
|
||||
raise ValidationError(
|
||||
_("The mandate '%s' can't have a date of last debit "
|
||||
"before the date of signature."
|
||||
) % mandate.unique_mandate_reference)
|
||||
@@ -96,20 +80,21 @@ class AccountBankingMandate(models.Model):
|
||||
for mandate in self:
|
||||
if mandate.state == 'valid':
|
||||
if not mandate.signature_date:
|
||||
raise exceptions.Warning(
|
||||
raise ValidationError(
|
||||
_("Cannot validate the mandate '%s' without a date of "
|
||||
"signature.") % mandate.unique_mandate_reference)
|
||||
if not mandate.partner_bank_id:
|
||||
raise exceptions.Warning(
|
||||
raise ValidationError(
|
||||
_("Cannot validate the mandate '%s' because it is not "
|
||||
"attached to a bank account.") %
|
||||
mandate.unique_mandate_reference)
|
||||
|
||||
@api.model
|
||||
def create(self, vals=None):
|
||||
if vals.get('unique_mandate_reference', '/') == '/':
|
||||
if vals.get('unique_mandate_reference', 'New') == 'New':
|
||||
vals['unique_mandate_reference'] = \
|
||||
self.env['ir.sequence'].next_by_code('account.banking.mandate')
|
||||
self.env['ir.sequence'].next_by_code(
|
||||
'account.banking.mandate') or 'New'
|
||||
return super(AccountBankingMandate, self).create(vals)
|
||||
|
||||
@api.multi
|
||||
@@ -122,8 +107,8 @@ class AccountBankingMandate(models.Model):
|
||||
def validate(self):
|
||||
for mandate in self:
|
||||
if mandate.state != 'draft':
|
||||
raise exceptions.Warning(
|
||||
_('Mandate should be in draft state'))
|
||||
raise UserError(
|
||||
_('Mandate should be in draft state.'))
|
||||
self.write({'state': 'valid'})
|
||||
return True
|
||||
|
||||
@@ -131,8 +116,8 @@ class AccountBankingMandate(models.Model):
|
||||
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'))
|
||||
raise UserError(
|
||||
_('Mandate should be in draft or valid state.'))
|
||||
self.write({'state': 'cancel'})
|
||||
return True
|
||||
|
||||
@@ -143,7 +128,7 @@ class AccountBankingMandate(models.Model):
|
||||
"""
|
||||
for mandate in self:
|
||||
if mandate.state != 'cancel':
|
||||
raise exceptions.Warning(
|
||||
_('Mandate should be in cancel state'))
|
||||
raise UserError(
|
||||
_('Mandate should be in cancel state.'))
|
||||
self.write({'state': 'draft'})
|
||||
return True
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
|
||||
from openerp import models, fields
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
@@ -12,5 +13,64 @@ class AccountInvoice(models.Model):
|
||||
|
||||
mandate_id = fields.Many2one(
|
||||
'account.banking.mandate', string='Direct Debit Mandate',
|
||||
domain=[('state', '=', 'valid')], readonly=True,
|
||||
states={'draft': [('readonly', False)]})
|
||||
ondelete='restrict',
|
||||
readonly=True, states={'draft': [('readonly', False)]})
|
||||
mandate_required = fields.Boolean(
|
||||
related='payment_mode_id.payment_method_id.mandate_required',
|
||||
readonly=True)
|
||||
|
||||
@api.model
|
||||
def line_get_convert(self, line, part):
|
||||
"""Copy mandate from invoice to account move line"""
|
||||
res = super(AccountInvoice, self).line_get_convert(line, part)
|
||||
if line.get('type') == 'dest' and line.get('invoice_id'):
|
||||
invoice = self.browse(line['invoice_id'])
|
||||
if invoice.type in ('out_invoice', 'out_refund'):
|
||||
res['mandate_id'] = invoice.mandate_id.id or False
|
||||
return res
|
||||
|
||||
# If a customer pays via direct debit, it's refunds should
|
||||
# be deducted form the next debit by default. The module
|
||||
# account_payment_partner copies payment_mode_id from invoice
|
||||
# to refund, and we also need to copy mandate from invoice to refund
|
||||
@api.model
|
||||
def _prepare_refund(
|
||||
self, invoice, date_invoice=None, date=None, description=None,
|
||||
journal_id=None):
|
||||
vals = super(AccountInvoice, self)._prepare_refund(
|
||||
invoice, date_invoice=date_invoice, date=date,
|
||||
description=description, journal_id=journal_id)
|
||||
if invoice.type == 'out_invoice':
|
||||
vals['mandate_id'] = invoice.mandate_id.id
|
||||
return vals
|
||||
|
||||
@api.onchange('partner_id', 'company_id')
|
||||
def _onchange_partner_id(self):
|
||||
"""Select by default the first valid mandate of the partner"""
|
||||
super(AccountInvoice, self)._onchange_partner_id()
|
||||
if (
|
||||
self.type == 'out_invoice' and
|
||||
self.partner_id.customer_payment_mode_id.
|
||||
payment_type == 'inbound' and
|
||||
self.partner_id.customer_payment_mode_id.payment_method_id.
|
||||
mandate_required and
|
||||
self.commercial_partner_id):
|
||||
mandates = self.env['account.banking.mandate'].search([
|
||||
('state', '=', 'valid'),
|
||||
('partner_id', '=', self.commercial_partner_id.id),
|
||||
])
|
||||
if mandates:
|
||||
self.mandate_id = mandates[0]
|
||||
else:
|
||||
self.mandate_id = False
|
||||
|
||||
@api.onchange('payment_mode_id')
|
||||
def payment_mode_id_change(self):
|
||||
super(AccountInvoice, self).payment_mode_id_change()
|
||||
if (
|
||||
self.payment_mode_id and
|
||||
self.payment_mode_id.payment_type == 'inbound' and
|
||||
not self.payment_mode_id.payment_method_id.mandate_required):
|
||||
self.mandate_id = False
|
||||
elif not self.payment_mode_id:
|
||||
self.mandate_id = False
|
||||
|
||||
22
account_banking_mandate/models/account_move_line.py
Normal file
22
account_banking_mandate/models/account_move_line.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Akretion (http://www.akretion.com/)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
|
||||
mandate_id = fields.Many2one(
|
||||
'account.banking.mandate', string='Direct Debit Mandate',
|
||||
ondelete='restrict')
|
||||
|
||||
@api.multi
|
||||
def _prepare_payment_line_vals(self, payment_order):
|
||||
vals = super(AccountMoveLine, self)._prepare_payment_line_vals(
|
||||
payment_order)
|
||||
if payment_order.payment_type == 'inbound' and self.mandate_id:
|
||||
vals['mandate_id'] = self.mandate_id.id
|
||||
vals['partner_bank_id'] = self.mandate_id.partner_bank_id.id
|
||||
return vals
|
||||
42
account_banking_mandate/models/account_payment_line.py
Normal file
42
account_banking_mandate/models/account_payment_line.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2015-2016 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, api, _
|
||||
from openerp.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
class AccountPaymentLine(models.Model):
|
||||
_inherit = 'account.payment.line'
|
||||
|
||||
mandate_id = fields.Many2one(
|
||||
comodel_name='account.banking.mandate', string='Direct Debit Mandate',
|
||||
domain=[('state', '=', 'valid')])
|
||||
mandate_required = fields.Boolean(
|
||||
related='order_id.payment_method_id.mandate_required', readonly=True)
|
||||
|
||||
@api.multi
|
||||
@api.constrains('mandate_id', 'partner_bank_id')
|
||||
def _check_mandate_bank_link(self):
|
||||
for pline in self:
|
||||
if (pline.mandate_id and pline.partner_bank_id and
|
||||
pline.mandate_id.partner_bank_id !=
|
||||
pline.partner_bank_id):
|
||||
raise ValidationError(_(
|
||||
"The payment line number %s has the bank account "
|
||||
"'%s' which is not attached to the mandate '%s' (this "
|
||||
"mandate is attached to the bank account '%s').") %
|
||||
(pline.name,
|
||||
pline.partner_bank_id.acc_number,
|
||||
pline.mandate_id.unique_mandate_reference,
|
||||
pline.mandate_id.partner_bank_id.acc_number))
|
||||
|
||||
@api.multi
|
||||
def draft2open_payment_line_check(self):
|
||||
res = super(AccountPaymentLine, self).draft2open_payment_line_check()
|
||||
if self.mandate_required and not self.mandate_id:
|
||||
raise UserError(_(
|
||||
'Missing Mandate on payment line %s') % self.name)
|
||||
return res
|
||||
14
account_banking_mandate/models/account_payment_method.py
Normal file
14
account_banking_mandate/models/account_payment_method.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
|
||||
class AccountPaymentMethod(models.Model):
|
||||
_inherit = "account.payment.method"
|
||||
|
||||
mandate_required = fields.Boolean(
|
||||
string='Mandate Required',
|
||||
help="Activate this option if this payment method requires your "
|
||||
"customer to sign a direct debit mandate with your company.")
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2015 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# © 2015-2016 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, api
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2014 Compassion CH - Cyril Sester <csester@compassion.ch>
|
||||
# © 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# © 2015 Akretion - Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
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.model
|
||||
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[0].id
|
||||
return super(PaymentLine, self).create(vals)
|
||||
|
||||
@api.one
|
||||
@api.constrains('mandate_id', 'bank_id')
|
||||
def _check_mandate_bank_link(self):
|
||||
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]))
|
||||
23
account_banking_mandate/models/res_partner.py
Normal file
23
account_banking_mandate/models/res_partner.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
mandate_count = fields.Integer(
|
||||
compute='_compute_mandate_count', string="Number of Mandates",
|
||||
readonly=True)
|
||||
|
||||
@api.multi
|
||||
def _compute_mandate_count(self):
|
||||
mandate_data = self.env['account.banking.mandate'].read_group(
|
||||
[('partner_id', 'in', self.ids)], ['partner_id'], ['partner_id'])
|
||||
mapped_data = dict([
|
||||
(mandate['partner_id'][0], mandate['partner_id_count'])
|
||||
for mandate in mandate_data])
|
||||
for partner in self:
|
||||
partner.mandate_count = mapped_data.get(partner.id, 0)
|
||||
@@ -12,5 +12,5 @@ class ResPartnerBank(models.Model):
|
||||
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')
|
||||
help='Banking mandates represent an authorization that the bank '
|
||||
'account owner gives to a company for a specific operation.')
|
||||
|
||||
@@ -1,3 +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
|
||||
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_order.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
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
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
|
||||
-
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<filter name="cancel" string="Cancelled" domain="[('state', '=', 'cancel')]" />
|
||||
<filter name="expired" string="Expired" domain="[('state', '=', 'expired')]" />
|
||||
<group string="Group By" name="groupby">
|
||||
<filter name="state_groupby" string="State" context="{'group_by': 'state'}"/>
|
||||
<filter name="signature_date_groupby" string="Signature Date" context="{'group_by': 'signature_date'}"/>
|
||||
</group>
|
||||
</search>
|
||||
@@ -101,33 +102,11 @@
|
||||
</record>
|
||||
|
||||
<menuitem id="mandate_menu"
|
||||
parent="account_payment.menu_main_payment"
|
||||
parent="account_payment_order.payment_root"
|
||||
action="mandate_action"
|
||||
sequence="20"
|
||||
sequence="30"
|
||||
/>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
Copyright (C) 2013-2016 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
@@ -10,10 +10,13 @@
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<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="inherit_id" ref="account_payment_partner.invoice_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_id" domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]" attrs="{'invisible': [('type', '=', 'out_refund')]}"/>
|
||||
<field name="payment_mode_id" position="after">
|
||||
<field name="mandate_id"
|
||||
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
|
||||
attrs="{'required': [('mandate_required', '=', True)], 'invisible': [('mandate_required', '=', False)]}"/>
|
||||
<field name="mandate_required" invisible="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
26
account_banking_mandate/views/account_move_line.xml
Normal file
26
account_banking_mandate/views/account_move_line.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 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_move_line_form" model="ir.ui.view">
|
||||
<field name="name">account_banking_mandate.move_line_form</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit_id" ref="account_payment_order.view_move_line_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_id"
|
||||
domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
37
account_banking_mandate/views/account_payment_line.xml
Normal file
37
account_banking_mandate/views/account_payment_line.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
© 2013-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="account_payment_line_form" model="ir.ui.view">
|
||||
<field name="name">account_banking_mandate.account.payment.line.form</field>
|
||||
<field name="model">account.payment.line</field>
|
||||
<field name="inherit_id" ref="account_payment_order.account_payment_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_required" invisible="1"/>
|
||||
<field name="mandate_id"
|
||||
domain="[('partner_bank_id', '=', partner_bank_id), ('state', '=', 'valid')]"
|
||||
attrs="{'invisible': [('mandate_required', '=', False)], 'required': [('mandate_required', '=', True)]}"
|
||||
context="{'default_partner_bank_id': partner_bank_id}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="account_payment_line_tree" model="ir.ui.view">
|
||||
<field name="name">account_banking_mandate.account.payment.line.tree</field>
|
||||
<field name="model">account.payment.line</field>
|
||||
<field name="inherit_id" ref="account_payment_order.account_payment_line_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_id"
|
||||
invisible="context.get('default_payment_type') != 'inbound'"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
20
account_banking_mandate/views/account_payment_method.xml
Normal file
20
account_banking_mandate/views/account_payment_method.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record id="account_payment_method_form" model="ir.ui.view">
|
||||
<field name="name">account_banking_mandate.account.payment.method.form</field>
|
||||
<field name="model">account.payment.method</field>
|
||||
<field name="inherit_id" ref="account_payment_mode.account_payment_method_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="bank_account_required" position="after">
|
||||
<field name="mandate_required"
|
||||
attrs="{'invisible': [('payment_type', '!=', 'inbound')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,30 +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="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_banking_payment_export.view_payment_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='line_ids']/form//field[@name='bank_id']" position="after">
|
||||
<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="mandate_id" string="Mandate"
|
||||
invisible="context.get('search_payment_order_type')!='debit'"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||
Copyright (C) 2015-2016 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
@@ -10,11 +10,11 @@
|
||||
<record id="bank_payment_line_form" model="ir.ui.view">
|
||||
<field name="name">banking.mandate.bank.payment.line.form</field>
|
||||
<field name="model">bank.payment.line</field>
|
||||
<field name="inherit_id" ref="account_banking_payment_export.bank_payment_line_form"/>
|
||||
<field name="inherit_id" ref="account_payment_order.bank_payment_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="bank_id" position="after">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_id"
|
||||
invisible="context.get('search_payment_order_type')!='debit'"/>
|
||||
invisible="context.get('default_payment_type')!='inbound'"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
@@ -22,11 +22,11 @@
|
||||
<record id="bank_payment_line_tree" model="ir.ui.view">
|
||||
<field name="name">banking.mandate.bank.payment.line.tree</field>
|
||||
<field name="model">bank.payment.line</field>
|
||||
<field name="inherit_id" ref="account_banking_payment_export.bank_payment_line_tree"/>
|
||||
<field name="inherit_id" ref="account_payment_order.bank_payment_line_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="bank_id" position="after">
|
||||
<field name="partner_bank_id" position="after">
|
||||
<field name="mandate_id" string="Mandate"
|
||||
invisible="context.get('search_payment_order_type')!='debit'"/>
|
||||
invisible="context.get('default_payment_type')!='inbound'"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
26
account_banking_mandate/views/res_partner.xml
Normal file
26
account_banking_mandate/views/res_partner.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 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="partner_view_buttons" model="ir.ui.view">
|
||||
<field name="name">mandate.res.partner.form</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="account.partner_view_buttons"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='%(base.action_res_partner_bank_account_form)d']" position="after">
|
||||
<button type="action" class="btn-link"
|
||||
name="%(account_banking_mandate.mandate_action)d"
|
||||
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}">
|
||||
<field string="Mandate(s)" name="mandate_count" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||
Copyright (C) 2013-2016 Akretion (http://www.akretion.com)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
The licence is in the file __openerp__.py
|
||||
-->
|
||||
@@ -12,8 +12,8 @@
|
||||
<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="mandates" string="Direct Debit Mandates" colspan="4">
|
||||
<group col="4" position="after">
|
||||
<group name="mandates" string="Direct Debit Mandates">
|
||||
<field name="mandate_ids" context="{'default_partner_bank_id': active_id, 'mandate_bank_partner_view': True}" nolabel="1"/>
|
||||
</group>
|
||||
</group>
|
||||
@@ -26,23 +26,10 @@
|
||||
<field name="inherit_id" ref="base.view_partner_bank_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="partner_id" position="after">
|
||||
<field name="mandate_ids" string="DD Mandates"/>
|
||||
<field name="mandate_ids" string="Mandates"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- add number of mandates in this list of bank accounts
|
||||
on the partner form -->
|
||||
<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="mandate_ids" string="DD Mandates"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user