Merge pull request #555 from acsone/12.0-ref_banking_sepa_direct_debit_sepa_ready_tbi

[12.0] [REF] direct debit: refactor some checks
This commit is contained in:
Pedro M. Baeza
2019-02-25 18:42:30 +01:00
committed by GitHub
3 changed files with 54 additions and 27 deletions

View File

@@ -6,3 +6,4 @@ from . import bank_payment_line
from . import account_payment_mode
from . import account_payment_method
from . import account_payment_order
from . import account_payment_line

View File

@@ -0,0 +1,48 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, _
from odoo.exceptions import UserError
class AccountPaymentLine(models.Model):
_inherit = 'account.payment.line'
@api.multi
def draft2open_payment_line_check(self):
res = super(AccountPaymentLine, self).draft2open_payment_line_check()
sepa_dd_lines = self.filtered(
lambda l: l.order_id.payment_method_id.code == 'sepa_direct_debit')
sepa_dd_lines._check_sepa_direct_debit_ready()
return res
@api.multi
def _check_sepa_direct_debit_ready(self):
"""
This method checks whether the payment line(s) are ready to be used
in the SEPA Direct Debit file generation.
:raise: UserError if a line does not fulfils all requirements
"""
for rec in self:
if not rec.mandate_id:
raise UserError(_(
"Missing SEPA Direct Debit mandate on the line with "
"partner {partner_name} (reference {reference}).").format(
partner_name=rec.partner_id.name, reference=rec.name))
if rec.mandate_id.state != 'valid':
raise UserError(_(
"The SEPA Direct Debit mandate with reference "
"{mandate_ref} for partner {partner_name} has "
"expired.").format(
mandate_ref=rec.mandate_id.unique_mandate_reference,
partner_name=rec.partner_id.name))
if rec.mandate_id.type == 'oneoff' and \
rec.mandate_id.last_debit_date:
raise UserError(_(
"The SEPA Direct Debit mandate with reference "
"{mandate_ref} for partner {partner_name} has type set "
"to 'One-Off' but has a last debit date set to "
"{last_debit_date}. Therefore, it cannot be used.").format(
mandate_ref=rec.mandate_id.unique_mandate_reference,
partner_name=rec.partner_id.name,
last_debit_date=rec.mandate_id.last_debit_date))

View File

@@ -69,44 +69,22 @@ class AccountPaymentOrder(models.Model):
transactions_count_a += 1
priority = line.priority
categ_purpose = line.category_purpose
# The field line.date is the requested payment date
# taking into account the 'date_prefered' setting
# cf account_banking_payment_export/models/account_payment.py
# in the inherit of action_open()
if not line.mandate_id:
raise UserError(
_("Missing SEPA Direct Debit mandate on the "
"bank payment line with partner '%s' "
"(reference '%s').")
% (line.partner_id.name, line.name))
scheme = line.mandate_id.scheme
if line.mandate_id.state != 'valid':
raise Warning(
_("The SEPA Direct Debit mandate with reference '%s' "
"for partner '%s' has expired.")
% (line.mandate_id.unique_mandate_reference,
line.mandate_id.partner_id.name))
if line.mandate_id.type == 'oneoff':
seq_type = 'OOFF'
if line.mandate_id.last_debit_date:
raise Warning(
_("The mandate with reference '%s' for partner "
"'%s' has type set to 'One-Off' and it has a "
"last debit date set to '%s', so we can't use "
"it.")
% (line.mandate_id.unique_mandate_reference,
line.mandate_id.partner_id.name,
line.mandate_id.last_debit_date))
elif line.mandate_id.type == 'recurrent':
seq_type_map = {
'recurring': 'RCUR',
'first': 'FRST',
'final': 'FNAL',
}
seq_type_label = \
line.mandate_id.recurrent_sequence_type
seq_type_label = line.mandate_id.recurrent_sequence_type
assert seq_type_label is not False
seq_type = seq_type_map[seq_type_label]
# The field line.date is the requested payment date
# taking into account the 'date_preferred' setting
# cf account_banking_payment_export/models/account_payment.py
# in the inherit of action_open()
key = (line.date, priority, categ_purpose, seq_type, scheme)
if key in lines_per_group:
lines_per_group[key].append(line)