diff --git a/CHANGELOG b/CHANGELOG index f276510188..3f796a6244 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add initiator identifiers on journal * Allow to store SEPA message content on the file system Version 5.2.0 - 2019-05-06 diff --git a/__init__.py b/__init__.py index d490546d51..17457a9bad 100644 --- a/__init__.py +++ b/__init__.py @@ -1,23 +1,23 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from trytond.pool import Pool -from .payment import * -from .party import * -from .account import * +from . import payment +from . import party +from . import account def register(): Pool.register( - Journal, - Group, - Mandate, - Payment, - Message, - Party, - PartyIdentifier, - Configuration, - ConfigurationSepaMandateSequence, + payment.Journal, + payment.Group, + payment.Mandate, + payment.Payment, + payment.Message, + party.Party, + party.PartyIdentifier, + account.Configuration, + account.ConfigurationSepaMandateSequence, module='account_payment_sepa', type_='model') Pool.register( - MandateReport, + payment.MandateReport, module='account_payment_sepa', type_='report') diff --git a/doc/index.rst b/doc/index.rst index 0828d50f61..8bb743f432 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -14,9 +14,15 @@ The Journal has some fields when the process method is SEPA: - Payable Flavor: - pain.001.001.03 - pain.001.001.05 + - pain.001.003.05 - Receivable Flavor: - pain.008.001.02 - pain.008.001.04 + - pain.008.003.02 +- Payable/Receivable Initiator Identifier: + - SEPA Creditor Identifier + - Belgian Enterprise Number + - Spanish VAT Number - Batch Booking. - Charge Bearer: - Debtor diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..ca3e24ee87 --- /dev/null +++ b/exceptions.py @@ -0,0 +1,7 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from trytond.exceptions import UserError + + +class PartyIdentificationdError(UserError): + pass diff --git a/message.xml b/message.xml index e180256c4b..0d5db93083 100644 --- a/message.xml +++ b/message.xml @@ -18,5 +18,8 @@ this repository contains the full copyright notices and license terms. --> The SEPA creditor identifier "%(code)s" for party "%(party)s" is not valid. + + The party "%(party)s" is missing a "%(type)s" identifier. + diff --git a/party.py b/party.py index b6ceabe81b..41c9e41b6c 100644 --- a/party.py +++ b/party.py @@ -10,10 +10,10 @@ from trytond.i18n import gettext from trytond.pool import PoolMeta, Pool from trytond.model import fields from trytond.transaction import Transaction +from trytond.pyson import Eval from trytond.modules.party.exceptions import InvalidIdentifierCode - -__all__ = ['Party', 'PartyIdentifier'] +from .exceptions import PartyIdentificationdError class Party(metaclass=PoolMeta): @@ -51,10 +51,31 @@ class Party(metaclass=PoolMeta): if identifier.type == 'sepa': return identifier.code + def get_sepa_identifier(self, name): + pool = Pool() + Identifier = pool.get('party.identifier') + for identifier in self.identifiers: + if identifier.type == name: + return identifier.sepa_identifier + else: + selection = Identifier.fields_get(['type'])['type']['selection'] + type = dict(selection).get(name, name) + raise PartyIdentificationdError( + gettext('account_payment_sepa.msg_party_no_id', + party=self.rec_name, + type=type)) + class PartyIdentifier(metaclass=PoolMeta): __name__ = 'party.identifier' + sepa_es_suffix = fields.Char( + "SEPA Suffix", size=3, + states={ + 'invisible': Eval('type') != 'es_nif', + }, + depends=['type']) + @classmethod def __setup__(cls): super(PartyIdentifier, cls).__setup__() @@ -84,3 +105,18 @@ class PartyIdentifier(metaclass=PoolMeta): except stdnum.exceptions.ValidationError: pass return code + + @property + def sepa_identifier(self): + identifier = { + 'Type': 'OrgId', + 'Id': self.code, + } + if self.type == 'sepa': + identifier['Type'] = 'PrvtId' + identifier['SchmeNm'] = {'Prtry': 'SEPA'} + elif self.type == 'be_vat': + identifier['Issr'] = 'KBO-BCE' + elif self.type == 'es_nif': + identifier['Id'] += self.sepa_es_suffix or '000' + return identifier diff --git a/party.xml b/party.xml index c9dbc68f66..7a814a2739 100644 --- a/party.xml +++ b/party.xml @@ -3,6 +3,12 @@ this repository contains the full copyright notices and license terms. --> + + party.identifier + + party_identifier_form + + Mandates account.payment.sepa.mandate diff --git a/payment.py b/payment.py index 56570b4ed8..ac29d174ab 100644 --- a/payment.py +++ b/payment.py @@ -27,9 +27,6 @@ from trytond.modules.company import CompanyReport from .sepa_handler import CAMT054 -__all__ = ['Journal', 'Group', 'Payment', 'Mandate', 'Message', - 'MandateReport'] - # XXX fix: https://genshi.edgewall.org/ticket/582 from genshi.template.astutil import ASTCodeGenerator, ASTTransformer if not hasattr(ASTCodeGenerator, 'visit_NameConstant'): @@ -55,6 +52,13 @@ else: file_id = None store_prefix = None +INITIATOR_IDS = [ + (None, ''), + ('sepa', "SEPA Creditor Identifier"), + ('be_vat', "Belgian Enterprise Number"), + ('es_nif', "Spanish VAT Number"), + ] + class Journal(metaclass=PoolMeta): __name__ = 'account.payment.journal' @@ -92,6 +96,20 @@ class Journal(metaclass=PoolMeta): }, translate=False, depends=['process_method']) + sepa_payable_initiator_id = fields.Selection( + INITIATOR_IDS, "SEPA Payable Initiator Identifier", + states={ + 'invisible': Eval('process_method') != 'sepa', + }, + depends=['process_method'], + help="The identifier used for the initiating party.") + sepa_receivable_initiator_id = fields.Selection( + INITIATOR_IDS, "SEPA Receivable Initiator Identifier", + states={ + 'invisible': Eval('process_method') != 'sepa', + }, + depends=['process_method'], + help="The identifier used for the initiating party.") sepa_batch_booking = fields.Boolean('Batch Booking', states={ 'invisible': Eval('process_method') != 'sepa', }, diff --git a/template/base.003.xml b/template/base.003.xml index c6c4d3b917..53a55e1964 100644 --- a/template/base.003.xml +++ b/template/base.003.xml @@ -3,7 +3,7 @@ this repository contains the full copyright notices and license terms. --> - + ${normalize('NFKD', party.name).encode('ascii', 'replace')[:70]} @@ -13,16 +13,36 @@ this repository contains the full copyright notices and license terms. --> - - - - ${party.sepa_creditor_identifier_used} - - SEPA - - - - + + + + ${identifier['BICOrBEI']} + + ${identifier['Id']} + + ${identifier['SchmeNm']['Cd']} + ${identifier['SchmeNm']['Cd']} + + ${identifier['Issr']} + + + + + ${identifier['DtAndPlcOfBirth']['BirthDt'].isoformat()} + ${identifier['DtAndPlcOfBirth']['PrvcOfBirth']} + ${identifier['DtAndPlcOfBirth']['CityOfBirth']} + ${identifier['DtAndPlcOfBirth']['CtryOfBirth']} + + + ${identifier['Id']} + + ${identifier['SchmeNm']['Cd']} + ${identifier['SchmeNm']['Prtry']} + + ${identifier['Issr']} + + + diff --git a/template/base.xml b/template/base.xml index eed129045f..6808725acd 100644 --- a/template/base.xml +++ b/template/base.xml @@ -2,7 +2,7 @@ - + ${party.name[:70]} @@ -10,16 +10,36 @@ this repository contains the full copyright notices and license terms. --> ${PostalAddress(address)} - - - - ${party.sepa_creditor_identifier_used} - - SEPA - - - - + + + + ${identifier['BICOrBEI']} + + ${identifier['Id']} + + ${identifier['SchmeNm']['Cd']} + ${identifier['SchmeNm']['Cd']} + + ${identifier['Issr']} + + + + + ${identifier['DtAndPlcOfBirth']['BirthDt'].isoformat()} + ${identifier['DtAndPlcOfBirth']['PrvcOfBirth']} + ${identifier['DtAndPlcOfBirth']['CityOfBirth']} + ${identifier['DtAndPlcOfBirth']['CtryOfBirth']} + + + ${identifier['Id']} + + ${identifier['SchmeNm']['Cd']} + ${identifier['SchmeNm']['Prtry']} + + ${identifier['Issr']} + + + diff --git a/template/pain.001.001.03.xml b/template/pain.001.001.03.xml index 7e69b6dfda..b340e1a01b 100644 --- a/template/pain.001.001.03.xml +++ b/template/pain.001.001.03.xml @@ -36,7 +36,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.sepa_initiating_party)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_payable_initiator_id)} diff --git a/template/pain.001.001.05.xml b/template/pain.001.001.05.xml index c71a788a75..cee89bf7aa 100644 --- a/template/pain.001.001.05.xml +++ b/template/pain.001.001.05.xml @@ -17,7 +17,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.sepa_initiating_party)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_payable_initiator_id)} diff --git a/template/pain.001.003.03.xml b/template/pain.001.003.03.xml index 5b437ac610..530bc5c0cf 100644 --- a/template/pain.001.003.03.xml +++ b/template/pain.001.003.03.xml @@ -17,7 +17,7 @@ this repository contains the full copyright notices and license terms. --> ${sum(len(payments) for _, payments in group.sepa_payments)} ${sum(p.amount for p in group.payments)} - ${PartyIdentification(group.sepa_initiating_party, with_address=False)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_payable_initiator_id, with_address=False)} diff --git a/template/pain.008.001.02.xml b/template/pain.008.001.02.xml index ed3d0faae0..86d3b1fd30 100644 --- a/template/pain.008.001.02.xml +++ b/template/pain.008.001.02.xml @@ -36,7 +36,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.sepa_initiating_party)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_receivable_initiator_id)} @@ -61,7 +61,7 @@ this repository contains the full copyright notices and license terms. --> ${key['date'].isoformat()} - ${PartyIdentification(group.company.party, id=False)} + ${PartyIdentification(group.company.party)} ${Account(group.journal.sepa_bank_account_number)} @@ -75,7 +75,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.company.party)} + ${PartyIdentification(group.company.party, id='sepa')} diff --git a/template/pain.008.001.04.xml b/template/pain.008.001.04.xml index 1bb2520128..f21becca1b 100644 --- a/template/pain.008.001.04.xml +++ b/template/pain.008.001.04.xml @@ -17,7 +17,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.sepa_initiating_party)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_receivable_initiator_id)} @@ -42,7 +42,7 @@ this repository contains the full copyright notices and license terms. --> ${key['date'].isoformat()} - ${PartyIdentification(group.company.party, id=False)} + ${PartyIdentification(group.company.party)} ${Account(group.journal.sepa_bank_account_number)} @@ -56,7 +56,7 @@ this repository contains the full copyright notices and license terms. --> - ${PartyIdentification(group.company.party)} + ${PartyIdentification(group.company.party, id='sepa')} diff --git a/template/pain.008.003.02.xml b/template/pain.008.003.02.xml index 5091e6d260..7793fe17cc 100644 --- a/template/pain.008.003.02.xml +++ b/template/pain.008.003.02.xml @@ -17,7 +17,7 @@ this repository contains the full copyright notices and license terms. --> ${sum(len(payments) for _, payments in group.sepa_payments)} ${sum(p.amount for p in group.payments)} - ${PartyIdentification(group.sepa_initiating_party, with_address=False)} + ${PartyIdentification(group.sepa_initiating_party, id=group.journal.sepa_receivable_initiator_id, with_address=False)} @@ -38,7 +38,7 @@ this repository contains the full copyright notices and license terms. --> ${key['date'].isoformat()} - ${PartyIdentification(group.company.party, id=False)} + ${PartyIdentification(group.company.party)} ${Account(group.journal.sepa_bank_account_number)} @@ -49,7 +49,7 @@ this repository contains the full copyright notices and license terms. --> SLEV - ${PartyIdentification(group.company.party, with_name=False, with_address=False)} + ${PartyIdentification(group.company.party, id='sepa', with_name=False, with_address=False)} diff --git a/view/party_identifier_form.xml b/view/party_identifier_form.xml new file mode 100644 index 0000000000..0242b2e4d9 --- /dev/null +++ b/view/party_identifier_form.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/view/payment_journal_form.xml b/view/payment_journal_form.xml index c14b08cf05..c35f7f7b1d 100644 --- a/view/payment_journal_form.xml +++ b/view/payment_journal_form.xml @@ -15,5 +15,9 @@ this repository contains the full copyright notices and license terms. -->