changeset 32b415552d7d in modules/account_payment_sepa:default
details: 
https://hg.tryton.org/modules/account_payment_sepa?cmd=changeset;node=32b415552d7d
description:
        Merge sepa identifier into eu_at_02

        issue9181
        review307371002
diffstat:

 CHANGELOG                          |   1 +
 message.xml                        |   3 --
 party.py                           |  43 +++++++++----------------------------
 payment.py                         |  16 +++++++++++++-
 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 |  31 +--------------------------
 8 files changed, 31 insertions(+), 69 deletions(-)

diffs (220 lines):

diff -r 80f42c6449cb -r 32b415552d7d CHANGELOG
--- a/CHANGELOG Thu Mar 19 19:00:35 2020 +0100
+++ b/CHANGELOG Mon Apr 20 14:28:05 2020 +0200
@@ -1,3 +1,4 @@
+* Merge sepa identifier into eu_at_02
 * Allow to customize message_id
 * Include bank account number on mandate rec_name
 * Allow sepa_mandate to be set on draft payments
diff -r 80f42c6449cb -r 32b415552d7d message.xml
--- a/message.xml       Thu Mar 19 19:00:35 2020 +0100
+++ b/message.xml       Mon Apr 20 14:28:05 2020 +0200
@@ -15,9 +15,6 @@
         <record model="ir.message" id="msg_mandate_delete_draft_canceled">
             <field name="text">To delete mandate "%(mandate)s" you must cancel 
it or reset its state to draft.</field>
         </record>
-        <record model="ir.message" id="msg_party_invalid_sepa">
-            <field name="text">The SEPA creditor identifier "%(code)s" for 
party "%(party)s" is not valid.</field>
-        </record>
         <record model="ir.message" id="msg_party_no_id">
             <field name="text">The party "%(party)s" is missing a "%(type)s" 
identifier.</field>
         </record>
diff -r 80f42c6449cb -r 32b415552d7d party.py
--- a/party.py  Thu Mar 19 19:00:35 2020 +0100
+++ b/party.py  Mon Apr 20 14:28:05 2020 +0200
@@ -3,8 +3,6 @@
 from sql import Null, Literal
 from sql.functions import CurrentTimestamp
 
-import stdnum.eu.at_02 as sepa
-import stdnum.exceptions
 
 from trytond.i18n import gettext
 from trytond.pool import PoolMeta, Pool
@@ -12,7 +10,6 @@
 from trytond.transaction import Transaction
 from trytond.pyson import Eval
 
-from trytond.modules.party.exceptions import InvalidIdentifierCode
 from .exceptions import PartyIdentificationdError
 
 
@@ -57,7 +54,7 @@
 
     def get_sepa_creditor_identifier_used(self, name):
         for identifier in self.identifiers:
-            if identifier.type == 'sepa':
+            if identifier.type == 'eu_at_02':
                 return identifier.code
 
     def get_sepa_identifier(self, name):
@@ -86,34 +83,16 @@
         depends=['type'])
 
     @classmethod
-    def __setup__(cls):
-        super(PartyIdentifier, cls).__setup__()
-        cls.type.selection.append(('sepa', 'SEPA Creditor Identifier'))
+    def __register__(cls, module_name):
+        cursor = Transaction().connection.cursor()
+        sql_table = cls.__table__()
+        super().__register__(module_name)
 
-    @fields.depends('party', '_parent_party.identifiers')
-    def check_code(self):
-        super(PartyIdentifier, self).check_code()
-        if self.type == 'sepa':
-            if not sepa.is_valid(self.code):
-                # Called from pre_validate so party may not be saved yet
-                if self.party and self.party.id > 0:
-                    party = self.party.rec_name
-                else:
-                    party = ''
-                raise InvalidIdentifierCode(
-                    gettext('account_payment_sepa.msg_party_invalid_sepa',
-                        code=self.code,
-                        party=party))
-
-    @fields.depends('type', 'code')
-    def on_change_with_code(self):
-        code = super(PartyIdentifier, self).on_change_with_code()
-        if self.type == 'sepa':
-            try:
-                return sepa.compact(self.code)
-            except stdnum.exceptions.ValidationError:
-                pass
-        return code
+        # Migration from 5.4: sepa identifier merged into eu_at_02
+        cursor.execute(*sql_table.update(
+                columns=[sql_table.type],
+                values=['eu_at_02'],
+                where=sql_table.type == 'sepa'))
 
     @property
     def sepa_identifier(self):
@@ -121,7 +100,7 @@
             'Type': 'OrgId',
             'Id': self.code,
             }
-        if self.type == 'sepa':
+        if self.type == 'eu_at_02':
             identifier['Type'] = 'PrvtId'
             identifier['SchmeNm'] = {'Prtry': 'SEPA'}
         elif self.type == 'be_vat':
diff -r 80f42c6449cb -r 32b415552d7d payment.py
--- a/payment.py        Thu Mar 19 19:00:35 2020 +0100
+++ b/payment.py        Mon Apr 20 14:28:05 2020 +0200
@@ -54,7 +54,7 @@
 
 INITIATOR_IDS = [
     (None, ''),
-    ('sepa', "SEPA Creditor Identifier"),
+    ('eu_at_02', "SEPA Creditor Identifier"),
     ('be_vat', "Belgian Enterprise Number"),
     ('es_nif', "Spanish VAT Number"),
     ]
@@ -133,6 +133,20 @@
             cls.process_method.selection.append(sepa_method)
 
     @classmethod
+    def __register__(cls, module_name):
+        cursor = Transaction().connection.cursor()
+        sql_table = cls.__table__()
+        super().__register__(module_name)
+
+        # Migration from 5.4: sepa identifier merged into eu_at_02
+        for name in {'payable', 'receivable'}:
+            column = getattr(sql_table, 'sepa_%s_initiator_id' % name)
+            cursor.execute(*sql_table.update(
+                    columns=[column],
+                    values=['eu_at_02'],
+                    where=column == 'sepa'))
+
+    @classmethod
     def default_company_party(cls):
         pool = Pool()
         Company = pool.get('company.company')
diff -r 80f42c6449cb -r 32b415552d7d template/pain.008.001.02.xml
--- a/template/pain.008.001.02.xml      Thu Mar 19 19:00:35 2020 +0100
+++ b/template/pain.008.001.02.xml      Mon Apr 20 14:28:05 2020 +0200
@@ -75,7 +75,7 @@
             <!-- ChrgsAcct -->
             <!-- ChrgsAcctAgt -->
             <CdtrSchmeId>
-                ${PartyIdentification(group.company.party, id='sepa')}
+                ${PartyIdentification(group.company.party, id='eu_at_02')}
             </CdtrSchmeId>
             <DrctDbtTxInf py:for="payment in payments">
                 <PmtId>
diff -r 80f42c6449cb -r 32b415552d7d template/pain.008.001.04.xml
--- a/template/pain.008.001.04.xml      Thu Mar 19 19:00:35 2020 +0100
+++ b/template/pain.008.001.04.xml      Mon Apr 20 14:28:05 2020 +0200
@@ -56,7 +56,7 @@
             <!-- ChrgsAcct -->
             <!-- ChrgsAcctAgt -->
             <CdtrSchmeId>
-                ${PartyIdentification(group.company.party, id='sepa')}
+                ${PartyIdentification(group.company.party, id='eu_at_02')}
             </CdtrSchmeId>
             <DrctDbtTxInf py:for="payment in payments">
                 <PmtId>
diff -r 80f42c6449cb -r 32b415552d7d template/pain.008.003.02.xml
--- a/template/pain.008.003.02.xml      Thu Mar 19 19:00:35 2020 +0100
+++ b/template/pain.008.003.02.xml      Mon Apr 20 14:28:05 2020 +0200
@@ -49,7 +49,7 @@
             <!-- UltmtCdtr -->
             <ChrgBr>SLEV</ChrgBr>
             <CdtrSchmeId>
-                ${PartyIdentification(group.company.party, id='sepa', 
with_name=False, with_address=False)}
+                ${PartyIdentification(group.company.party, id='eu_at_02', 
with_name=False, with_address=False)}
             </CdtrSchmeId>
             <DrctDbtTxInf py:for="payment in payments">
                 <PmtId>
diff -r 80f42c6449cb -r 32b415552d7d tests/test_account_payment_sepa.py
--- a/tests/test_account_payment_sepa.py        Thu Mar 19 19:00:35 2020 +0100
+++ b/tests/test_account_payment_sepa.py        Mon Apr 20 14:28:05 2020 +0200
@@ -29,7 +29,7 @@
     currency = create_currency('EUR')
     company = create_company(currency=currency)
     sepa = Identifier(party=company.party, code='ES23ZZZ47690558N',
-        type='sepa')
+        type='eu_at_02')
     sepa.save()
     bank_party = Party(name='European Bank')
     bank_party.save()
@@ -245,35 +245,6 @@
                         }])
 
     @with_transaction()
-    def test_sepa_identifier(self):
-        'Test sepa indentifier validation'
-        pool = Pool()
-        Party = pool.get('party.party')
-        Identifier = pool.get('party.identifier')
-
-        party = Party(name='test')
-        sepa = Identifier(party=party, code='BE68539007547034',
-            type='sepa')
-        with self.assertRaises(UserError):
-            sepa.save()
-
-        party2 = Party(name='test2')
-        sepa = Identifier(party=party2, code='007547034',
-            type='sepa')
-        with self.assertRaises(UserError):
-            sepa.save()
-
-        party3 = Party(name='test3')
-        sepa = Identifier(party=party3, code='ES23ZZZ47690558N',
-            type='sepa')
-        sepa.save()
-
-        party4 = Party(name='test4')
-        sepa = Identifier(party=party4, code='ES 23ZZZ 4769 055  8N',
-            type='sepa')
-        sepa.save()
-
-    @with_transaction()
     def test_payment_sepa_bank_account_number(self):
         'Test Payment.sepa_bank_account_number'
         pool = Pool()

Reply via email to