From 919c0a2b522e6a35fa33e4d30748f0f319393ba6 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 21 Sep 2015 12:32:45 +0200 Subject: [PATCH] [IMP] account_banking_sepa_direct_debit: 4 things * Add bank.payment.lines object to allow grouping in the payments * Add a hook to inherit grouping of the transfer account move line Use that new hook in SEPA direct debits Better variable names * FIX Reading wrong field for sequence type of SEPA DD Loop on bank payment lines instead of payment lines * Update automated tests and demo data * Add on_change on field 'type' of payment.mode for easier configuration --- .../demo/sepa_direct_debit_demo.xml | 1 + .../models/__init__.py | 23 +--------- .../models/bank_payment_line.py | 41 +++++++++++++++++ .../wizard/export_sdd.py | 44 ++++++++----------- 4 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 account_banking_sepa_direct_debit/models/bank_payment_line.py diff --git a/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml b/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml index 51a24bad1..07b347f6c 100644 --- a/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml +++ b/account_banking_sepa_direct_debit/demo/sepa_direct_debit_demo.xml @@ -10,6 +10,7 @@ + diff --git a/account_banking_sepa_direct_debit/models/__init__.py b/account_banking_sepa_direct_debit/models/__init__.py index 153ab3543..ac7674156 100644 --- a/account_banking_sepa_direct_debit/models/__init__.py +++ b/account_banking_sepa_direct_debit/models/__init__.py @@ -1,24 +1,5 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# SEPA Direct Debit module for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com) -# @author: Alexis de Lattre -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- from . import res_company from . import account_banking_mandate +from . import bank_payment_line diff --git a/account_banking_sepa_direct_debit/models/bank_payment_line.py b/account_banking_sepa_direct_debit/models/bank_payment_line.py new file mode 100644 index 000000000..67a0da3f5 --- /dev/null +++ b/account_banking_sepa_direct_debit/models/bank_payment_line.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# SEPA Direct Debit module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com) +# @author: Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp import models, api + + +class BankPaymentLine(models.Model): + _inherit = 'bank.payment.line' + + @api.multi + def move_line_transfer_account_hashcode(self): + """ + From my experience, even when you ask several direct debits + at the same date with enough delay, you will have several credits + on your bank statement: one for each mandate types. + So we split the transfer move lines by mandate type, so easier + reconciliation of the bank statement. + """ + hashcode = super(BankPaymentLine, self).\ + move_line_transfer_account_hashcode() + hashcode += '-' + unicode(self.mandate_id.recurrent_sequence_type) + return hashcode diff --git a/account_banking_sepa_direct_debit/wizard/export_sdd.py b/account_banking_sepa_direct_debit/wizard/export_sdd.py index b76e14050..53bdd3d10 100644 --- a/account_banking_sepa_direct_debit/wizard/export_sdd.py +++ b/account_banking_sepa_direct_debit/wizard/export_sdd.py @@ -144,25 +144,22 @@ class BankingExportSddWizard(models.TransientModel): # key = (requested_date, priority, sequence type) # value = list of lines as objects # Iterate on payment orders - today = fields.Date.context_today(self) for payment_order in self.payment_order_ids: total_amount = total_amount + payment_order.total # Iterate each payment lines - for line in payment_order.line_ids: + for line in payment_order.bank_line_ids: transactions_count_1_6 += 1 priority = line.priority - if payment_order.date_prefered == 'due': - requested_date = line.ml_maturity_date or today - elif payment_order.date_prefered == 'fixed': - requested_date = payment_order.date_scheduled or today - else: - requested_date = today + # 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 Warning( - _("Missing SEPA Direct Debit mandate on the payment " - "line with partner '%s' and Invoice ref '%s'.") - % (line.partner_id.name, - line.ml_inv_ref.number)) + _("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( @@ -191,14 +188,11 @@ class BankingExportSddWizard(models.TransientModel): line.mandate_id.recurrent_sequence_type assert seq_type_label is not False seq_type = seq_type_map[seq_type_label] - key = (requested_date, priority, seq_type, scheme) + key = (line.date, priority, seq_type, scheme) if key in lines_per_group: lines_per_group[key].append(line) else: lines_per_group[key] = [line] - # Write requested_exec_date on 'Payment date' of the pay line - if requested_date != line.date: - line.date = requested_date for (requested_date, priority, sequence_type, scheme), lines in \ lines_per_group.items(): @@ -374,18 +368,18 @@ class BankingExportSddWizard(models.TransientModel): to_expire_mandates = abmo.browse([]) first_mandates = abmo.browse([]) all_mandates = abmo.browse([]) - for line in order.line_ids: - if line.mandate_id in all_mandates: + for bline in order.bank_line_ids: + if bline.mandate_id in all_mandates: continue - all_mandates += line.mandate_id - if line.mandate_id.type == 'oneoff': - to_expire_mandates += line.mandate_id - elif line.mandate_id.type == 'recurrent': - seq_type = line.mandate_id.recurrent_sequence_type + all_mandates += bline.mandate_id + if bline.mandate_id.type == 'oneoff': + to_expire_mandates += bline.mandate_id + elif bline.mandate_id.type == 'recurrent': + seq_type = bline.mandate_id.recurrent_sequence_type if seq_type == 'final': - to_expire_mandates += line.mandate_id + to_expire_mandates += bline.mandate_id elif seq_type == 'first': - first_mandates += line.mandate_id + first_mandates += bline.mandate_id all_mandates.write( {'last_debit_date': fields.Date.context_today(self)}) to_expire_mandates.write({'state': 'expired'})