From eb57a814a8d4b4ee739b6c03ffa9808ea3e9c29e Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 7 Apr 2022 10:29:56 +0200 Subject: [PATCH] Store sepa message id and sepa payment info id issue11052 review389451002 --- CHANGELOG | 1 + payment.py | 68 +++++++++++++++++++++++++++--- payment.xml | 10 +++++ template/pain.001.001.03.xml | 2 +- template/pain.001.001.05.xml | 2 +- template/pain.001.003.03.xml | 2 +- template/pain.008.001.02.xml | 2 +- template/pain.008.001.04.xml | 2 +- template/pain.008.003.02.xml | 2 +- tests/test_account_payment_sepa.py | 2 + view/payment_form.xml | 2 + view/payment_group_form.xml | 2 + view/payment_group_list.xml | 8 ++++ view/payment_list.xml | 8 ++++ 14 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 view/payment_group_list.xml create mode 100644 view/payment_list.xml diff --git a/CHANGELOG b/CHANGELOG index 347e0c022a..50a6685f9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Store sepa message id and sepa payment info id * Add support for Python 3.10 * Remove support for Python 3.6 * Rename generate_message button to sepa_generate_message diff --git a/payment.py b/payment.py index 27551fd3b5..c0c21f403c 100644 --- a/payment.py +++ b/payment.py @@ -3,6 +3,7 @@ import datetime import os import unicodedata +import uuid from io import BytesIO from itertools import groupby @@ -23,7 +24,8 @@ from trytond.modules.account_payment.exceptions import ProcessError from trytond.modules.company import CompanyReport from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval, If -from trytond.tools import grouped_slice, reduce_ids, sortable_values +from trytond.tools import ( + grouped_slice, lstrip_wildcard, reduce_ids, sortable_values) from trytond.transaction import Transaction from .sepa_handler import CAMT054 @@ -189,6 +191,10 @@ class Group(metaclass=PoolMeta): 'invisible': ~Eval('sepa_messages'), }, depends=['company']) + sepa_id = fields.Char("SEPA ID", readonly=True, size=35, + states={ + 'invisible': ~Eval('sepa_id'), + }) @classmethod def __setup__(cls): @@ -238,6 +244,15 @@ class Group(metaclass=PoolMeta): gettext('account_payment_sepa' '.msg_payment_process_no_iban', payment=payment.rec_name)) + to_write = [] + for key, payments in self.sepa_payments: + to_write.append(payments) + to_write.append({ + 'sepa_info_id': self.sepa_group_payment_id(key), + }) + if to_write: + Payment.write(*to_write) + self.sepa_id = uuid.uuid4().hex self.sepa_generate_message(_save=False) @dualmethod @@ -267,17 +282,17 @@ class Group(metaclass=PoolMeta): return self.company.party def sepa_group_payment_key(self, payment): - key = (('date', payment.date),) + key = ( + ('payment_info', payment.sepa_info_id), + ('date', payment.date), + ) if self.kind == 'receivable': key += (('sequence_type', payment.sepa_mandate_sequence_type),) key += (('scheme', payment.sepa_mandate.scheme),) return key def sepa_group_payment_id(self, key): - payment_id = str(key['date'].toordinal()) - if self.kind == 'receivable': - payment_id += '-' + key['sequence_type'] - return payment_id + return key['payment_info'] or uuid.uuid4().hex @property def sepa_payments(self): @@ -292,7 +307,23 @@ class Group(metaclass=PoolMeta): @property def sepa_message_id(self): - return self.number + return self.sepa_id or self.number + + @classmethod + def search_rec_name(cls, name, clause): + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + code_value = clause[2] + if clause[1].endswith('like'): + code_value = lstrip_wildcard(clause[2]) + domain = super().search_rec_name(name, clause) + return [ + bool_op, + domain, + ('sepa_id', clause[1], code_value) + tuple(clause[3:]), + ] class Payment(metaclass=PoolMeta): @@ -335,6 +366,10 @@ class Payment(metaclass=PoolMeta): 'get_sepa_end_to_end_id', searcher='search_end_to_end_id') sepa_instruction_id = fields.Function(fields.Char('SEPA Instruction ID'), 'get_sepa_instruction_id', searcher='search_sepa_instruction_id') + sepa_info_id = fields.Char("SEPA Info ID", readonly=True, size=35, + states={ + 'invisible': ~Eval('sepa_info_id'), + }) @classmethod def copy(cls, payments, default=None): @@ -417,6 +452,25 @@ class Payment(metaclass=PoolMeta): }), ] + @classmethod + def search_rec_name(cls, name, clause): + domain = super().search_rec_name(name, clause) + if domain: + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + domain = [ + bool_op, + domain, + ] + code_value = clause[2] + if clause[1].endswith('like'): + code_value = lstrip_wildcard(clause[2]) + domain.append( + ('sepa_info_id', clause[1], code_value) + tuple(clause[3:])) + return domain + class Mandate(Workflow, ModelSQL, ModelView): 'SEPA Mandate' diff --git a/payment.xml b/payment.xml index 42df7da6cb..c0d5a89e10 100644 --- a/payment.xml +++ b/payment.xml @@ -14,12 +14,22 @@ this repository contains the full copyright notices and license terms. --> payment_group_form + + account.payment.group + + payment_group_list + account.payment payment_form + + account.payment + + payment_list + account.payment.sepa.mandate diff --git a/template/pain.001.001.03.xml b/template/pain.001.001.03.xml index e7ef46a5a4..ef689518b0 100644 --- a/template/pain.001.001.03.xml +++ b/template/pain.001.001.03.xml @@ -41,7 +41,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} TRF ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/template/pain.001.001.05.xml b/template/pain.001.001.05.xml index 65b5d17bc1..cd029cba1b 100644 --- a/template/pain.001.001.05.xml +++ b/template/pain.001.001.05.xml @@ -22,7 +22,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} TRF ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/template/pain.001.003.03.xml b/template/pain.001.003.03.xml index 06f443abcc..aac2eac7a5 100644 --- a/template/pain.001.003.03.xml +++ b/template/pain.001.003.03.xml @@ -21,7 +21,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} TRF ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/template/pain.008.001.02.xml b/template/pain.008.001.02.xml index 3e80008045..2dd3195542 100644 --- a/template/pain.008.001.02.xml +++ b/template/pain.008.001.02.xml @@ -41,7 +41,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} DD ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/template/pain.008.001.04.xml b/template/pain.008.001.04.xml index a1b653aa01..f43a861e84 100644 --- a/template/pain.008.001.04.xml +++ b/template/pain.008.001.04.xml @@ -22,7 +22,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} DD ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/template/pain.008.003.02.xml b/template/pain.008.003.02.xml index f9149744ee..ff22e76336 100644 --- a/template/pain.008.003.02.xml +++ b/template/pain.008.003.02.xml @@ -21,7 +21,7 @@ this repository contains the full copyright notices and license terms. --> - ${group.sepa_group_payment_id(key)[:35]} + ${key['payment_info'][:35]} DD ${'true' if group.journal.sepa_batch_booking else 'false'} ${len(payments)} diff --git a/tests/test_account_payment_sepa.py b/tests/test_account_payment_sepa.py index f379343d60..a5c9ffbdbf 100644 --- a/tests/test_account_payment_sepa.py +++ b/tests/test_account_payment_sepa.py @@ -355,6 +355,8 @@ class AccountPaymentSepaTestCase(CompanyTestMixin, ModuleTestCase): for payment in payments: self.assertEqual(payment.sepa_mandate_sequence_type, 'RCUR') + self.assertTrue(payment.sepa_info_id) + self.assertIsNotNone(payment.group.sepa_id) @with_transaction() def handle_camt054(self, flavor): diff --git a/view/payment_form.xml b/view/payment_form.xml index 620a59fa82..74ff2b7ed6 100644 --- a/view/payment_form.xml +++ b/view/payment_form.xml @@ -5,6 +5,8 @@ this repository contains the full copyright notices and license terms. -->