Beispiel #1
0
    def parse_recipients(self, items, assume_internal=False):
        for opt in items:
            lines = get_text_lines(opt)

            if opt.attrib['value'].startswith('I') or assume_internal:
                for n, line in enumerate(lines):
                    if line.strip().startswith('n°'):
                        rcpt = Recipient()
                        rcpt._index = opt.attrib['value']
                        rcpt._raw_label = ' '.join(lines)
                        rcpt.category = 'Interne'
                        rcpt.id = CleanText().filter(line[2:].strip())
                        # we don't have iban here, use account number
                        rcpt.label = ' '.join(lines[:n])
                        rcpt.currency = Currency.get_currency(lines[-1])
                        rcpt.enabled_at = datetime.now().replace(microsecond=0)
                        yield rcpt
                        break
            elif opt.attrib['value'].startswith('E'):
                if len(lines) > 1:
                    # In some cases we observed beneficiaries without label, we skip them
                    rcpt = Recipient()
                    rcpt._index = opt.attrib['value']
                    rcpt._raw_label = ' '.join(lines)
                    rcpt.category = 'Externe'
                    rcpt.label = lines[0]
                    rcpt.iban = lines[1].upper()
                    rcpt.id = rcpt.iban
                    rcpt.enabled_at = datetime.now().replace(microsecond=0)
                    yield rcpt
                else:
                    self.logger.warning('The recipient associated with the iban %s has got no label' % lines[0])