~therp-nl/banking-addons/7.0-akretion-banking-addons-sepa

« back to all changes in this revision

Viewing changes to account_banking_nl_ing/ing.py

  • Committer: Stefan Rijnhart
  • Date: 2013-06-26 21:14:41 UTC
  • mfrom: (162.1.11 banking-addons-7.0)
  • Revision ID: stefan@therp.nl-20130626211441-k4l2libes7cakxwk
[MRG] Merged with target branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
        # Normalize basic account numbers
78
78
        self.remote_account = self.remote_account.replace('.', '').zfill(10)
79
79
        self.local_account = self.local_account.replace('.', '').zfill(10)             
 
80
        
80
81
 
81
82
class transaction(models.mem_bank_transaction):
82
83
    '''
114
115
 
115
116
    # global expression for matching storno references
116
117
    ref_expr = re.compile('REF[\*:]([0-9A-Z-z_-]+)')
 
118
    # match references for Acceptgiro's through Internet banking
 
119
    kn_expr = re.compile('KN: ([^ ]+)')
117
120
 
118
121
    def __init__(self, line, *args, **kwargs):
119
122
        '''
149
152
                    self.reference = res.group(1)
150
153
                    self.storno_retry = True
151
154
            self.remote_owner = False
 
155
        if self.transfer_type == 'GT':
 
156
            res = self.kn_expr.search(self.message)
 
157
            if res:
 
158
                self.reference = res.group(1)
 
159
        if self.transfer_type == 'AC':
 
160
            self.parse_acceptgiro()
 
161
        if self.message and not self.reference:
 
162
            self.reference = self.message
 
163
 
 
164
    def parse_acceptgiro(self):
 
165
        """
 
166
        Entries of type 'Acceptgiro' can contain the reference
 
167
        in the 'name' column, as well as full address information
 
168
        in the 'message' column'
 
169
        """
 
170
        reference = ''
 
171
        street = False
 
172
        zipcode = False
 
173
        street = False
 
174
        before = False
 
175
        if self.remote_owner.startswith('KN: '):
 
176
            self.reference = self.remote_owner[4:]
 
177
            self.remote_owner = ''
 
178
        if 'KN: ' in self.message:
 
179
            index = self.message.index('KN: ')
 
180
            before = self.message[:index]
 
181
            self.message = self.message[index:]
 
182
        expression = (
 
183
            "^\s*(KN:\s*(?P<kn>[^\s]+))?(\s*)"
 
184
            "(?P<navr>NAVR:\s*[^\s]+)?(\s*)(?P<after>.*?)$")
 
185
        msg_match = re.match(expression, self.message)
 
186
        after = msg_match.group('after')
 
187
        kn = msg_match.group('kn')
 
188
        navr = msg_match.group('navr')
 
189
        if kn:
 
190
            self.reference = kn[4:]
 
191
        self.message = 'Acceptgiro %s' % (navr or '')
 
192
        if after:
 
193
            parts = [after[i:i+33] for i in range(0, len(after), 33)]
 
194
            if parts and not self.remote_owner:
 
195
                self.remote_owner = parts.pop(0).strip()
 
196
            if parts:
 
197
                self.remote_owner_address = [parts.pop(0).strip()]
 
198
            if parts:
 
199
                zip_city = parts.pop(0).strip()
 
200
                zip_match = re.match(
 
201
                    "^(?P<zipcode>[^ ]{6})\s+(?P<city>.*?)$", zip_city)
 
202
                if zip_match:
 
203
                    self.remote_owner_postalcode = zip_match.group('zipcode')
 
204
                    self.remote_owner_city = zip_match.group('city')
 
205
        if before and not self.remote_owner_city:
 
206
            self.remote_owner_city = before.strip()
152
207
 
153
208
    def is_valid(self):
154
209
        if not self.error_message: