コード例 #1
0
 def __init__(self, values, subno):
     '''
     Initialize own dict with attributes and coerce values to right type
     '''
     if len(self.attrnames) != len(values):
         raise ValueError(
             _('Invalid transaction line: expected %d columns, found %d') %
             (len(self.attrnames), len(values)))
     self.__dict__.update(dict(zip(self.attrnames, values)))
     # for lack of a standardized locale function to parse amounts
     self.transferred_amount = float(
         re.sub(',', '.', self.transferred_amount))
     if self.debcred == 'Af':
         self.transferred_amount = -self.transferred_amount
     try:
         self.execution_date = self.value_date = str2date(
             self.date, '%Y%m%d')
     except ValueError:
         self.execution_date = self.value_date = str2date(
             self.date, '%d-%m-%Y')
     self.statement_id = ''  #self.value_date.strftime('%Yw%W')
     self.id = str(subno).zfill(4)
     self.reference = ''
     # Normalize basic account numbers
     self.remote_account = self.remote_account.replace('.', '').zfill(10)
     self.local_account = self.local_account.replace('.', '').zfill(10)
コード例 #2
0
 def __init__(self, msg, *args, **kwargs):
     '''
     Set decent start values based on first transaction read
     '''
     super(statement, self).__init__(*args, **kwargs)
     self.id = msg.statement_id
     self.local_account = msg.local_account
     try:
         self.date = str2date(msg.date, '%Y%m%d')
     except ValueError:
         self.date = str2date(msg.date, '%d-%m-%Y')
     self.start_balance = self.end_balance = 0  # msg.start_balance
     self.import_transaction(msg)
コード例 #3
0
ファイル: ing.py プロジェクト: Endika/bank-payment
 def __init__(self, msg, *args, **kwargs):
     '''
     Set decent start values based on first transaction read
     '''
     super(statement, self).__init__(*args, **kwargs)
     self.id = msg.statement_id
     self.local_account = msg.local_account
     try:
         self.date = str2date(msg.date, '%Y%m%d')
     except ValueError:
         self.date = str2date(msg.date, '%d-%m-%Y')
     self.start_balance = self.end_balance = 0 # msg.start_balance
     self.import_transaction(msg)
コード例 #4
0
    def parse_Stmt(self, cr, node):
        """
        Parse a single Stmt node.

        Be sure to craft a unique, but short enough statement identifier,
        as it is used as the basis of the generated move lines' names
        which overflow when using the full IBAN and CAMT statement id.
        """
        statement = models.mem_bank_statement()
        statement.local_account = (self.xpath(
            node, './ns:Acct/ns:Id/ns:IBAN')[0].text if self.xpath(
                node, './ns:Acct/ns:Id/ns:IBAN') else self.xpath(
                    node, './ns:Acct/ns:Id/ns:Othr/ns:Id')[0].text)

        identifier = node.find(self.ns + 'Id').text
        if identifier.upper().startswith('CAMT053'):
            identifier = identifier[7:]
        statement.id = self.get_unique_statement_id(
            cr, "%s-%s" % (self.get_unique_account_identifier(
                cr, statement.local_account), identifier))

        statement.local_currency = self.xpath(node, './ns:Acct/ns:Ccy')[0].text
        statement.start_balance = self.get_start_balance(node)
        statement.end_balance = self.get_end_balance(node)
        number = 0
        for Ntry in self.xpath(node, './ns:Ntry'):
            transaction_detail = self.parse_Ntry(Ntry)
            if number == 0:
                # Take the statement date from the first transaction
                statement.date = str2date(transaction_detail['execution_date'],
                                          "%Y-%m-%d")
            number += 1
            transaction_detail['id'] = str(number).zfill(4)
            statement.transactions.append(transaction(transaction_detail))
        return statement
コード例 #5
0
ファイル: abnamro.py プロジェクト: coloh/bank-payment
 def __init__(self, values, subno):
     '''
     Initialize own dict with attributes and coerce values to right type
     '''
     if len(self.attrnames) != len(values):
         raise ValueError, \
                 _('Invalid transaction line: expected %d columns, found '
                   '%d') % (len(self.attrnames), len(values))
     ''' Strip all values except the blob '''
     for (key, val) in zip(self.attrnames, values):
         self.__dict__[key] = key == 'blob' and val or val.strip()
     # for lack of a standardized locale function to parse amounts
     self.local_account = self.local_account.zfill(10)
     self.transferred_amount = float(
         self.transferred_amount.replace(',', '.'))
     self.execution_date = str2date(self.date, '%Y%m%d')
     self.value_date = str2date(self.date, '%Y%m%d')
     # Set statement_id based on week number
     self.statement_id = self.execution_date.strftime('%Yw%W')
     self.id = str(subno).zfill(4)
コード例 #6
0
ファイル: ing.py プロジェクト: Endika/bank-payment
 def __init__(self, values, subno):
     '''
     Initialize own dict with attributes and coerce values to right type
     '''
     if len(self.attrnames) != len(values):
         raise ValueError(
             _('Invalid transaction line: expected %d columns, found %d')
             % (len(self.attrnames), len(values)))
     self.__dict__.update(dict(zip(self.attrnames, values)))
     # for lack of a standardized locale function to parse amounts
     self.transferred_amount = float(
         re.sub(',', '.', self.transferred_amount))
     if self.debcred == 'Af':
         self.transferred_amount = -self.transferred_amount
     try:
         self.execution_date = self.value_date = str2date(self.date, '%Y%m%d')
     except ValueError:
         self.execution_date = self.value_date = str2date(self.date, '%d-%m-%Y')
     self.statement_id = '' #self.value_date.strftime('%Yw%W')
     self.id = str(subno).zfill(4)
     self.reference = ''
     # Normalize basic account numbers
     self.remote_account = self.remote_account.replace('.', '').zfill(10)
     self.local_account = self.local_account.replace('.', '').zfill(10)             
コード例 #7
0
ファイル: camt.py プロジェクト: Endika/bank-payment
    def parse_Stmt(self, cr, node):
        """
        Parse a single Stmt node.

        Be sure to craft a unique, but short enough statement identifier,
        as it is used as the basis of the generated move lines' names
        which overflow when using the full IBAN and CAMT statement id.
        """
        statement = models.mem_bank_statement()
        statement.local_account = (
            self.xpath(node, './ns:Acct/ns:Id/ns:IBAN')[0].text
            if self.xpath(node, './ns:Acct/ns:Id/ns:IBAN')
            else self.xpath(node, './ns:Acct/ns:Id/ns:Othr/ns:Id')[0].text)

        identifier = node.find(self.ns + 'Id').text
        if identifier.upper().startswith('CAMT053'):
            identifier = identifier[7:]
        statement.id = self.get_unique_statement_id(
            cr, "%s-%s" % (
                self.get_unique_account_identifier(
                    cr, statement.local_account),
                identifier)
            )

        statement.local_currency = self.xpath(node, './ns:Acct/ns:Ccy')[0].text
        statement.start_balance = self.get_start_balance(node)
        statement.end_balance = self.get_end_balance(node)
        number = 0
        for Ntry in self.xpath(node, './ns:Ntry'):
            transaction_detail = self.parse_Ntry(Ntry)
            if number == 0:
                # Take the statement date from the first transaction
                statement.date = str2date(
                    transaction_detail['execution_date'], "%Y-%m-%d")
            number += 1
            transaction_detail['id'] = str(number).zfill(4)
            statement.transactions.append(
                transaction(transaction_detail))
        return statement
コード例 #8
0
    def parse(self, cr, data):
        '''
        Parse data.

        data is a raw in memory file object. You have to split it in
        whatever chunks you see fit for parsing. It should return a list
        of mem_bank_statement objects. Every mem_bank_statement object
        should contain a list of mem_bank_transaction objects.

        For identification purposes, don't invent numbering of the transaction
        numbers or bank statements ids on your own - stick with those provided
        by your bank. Doing so enables the users to re-load old transaction
        files without creating multiple identical bank statements.

        If your bank does not provide transaction ids, take a high resolution
        and a repeatable algorithm for the numbering. For example the date can
        be used as a prefix. Adding a tracer (day resolution) can create
        uniqueness. Adding unique statement ids can add to the robustness of
        your transaction numbering.

        Just mind that users can create random (file)containers with
        transactions in it. Try not to depend on order of appearance within
        these files. If in doubt: sort.
        '''
        statement = bs()
        lines = data.split('\n')
        last_balance = ''
        for line in lines:
            sp = line.split(';')
            # ignore empty lines
            if not bool(''.join(sp)):
                continue
            if sp[0] == '':
                if "Relevé de compte mensuel" in sp[1]:
                    statement.id = sp[1].split("du ")[1].capitalize()
                if "Numéro de compte :" in sp[1]:
                    statement.local_account = sp[1].split(":")[1].replace(
                        ' ', '')
                continue
            if sp[0] == 'DATE':
                continue
            if sp[1] == "Solde reporté":
                statement.start_balance = convert.str2float(sp[7])
                continue
            d = bt()
            d.id = hashlib.md5(line).hexdigest()
            d.transfer_type = "DD"
            d.statement_id = statement.id
            d.local_account = statement.local_account
            d.execution_date = convert.str2date(sp[0], '%d-%b-%Y')
            d.message = sp[1]
            d.remote_account = "N/A in Statement"
            d.value_date = convert.str2date(sp[3], '%d-%b-%Y')
            d.reference = sp[2]
            if sp[4] and sp[4] != sp[2]:
                d.reference = sp[4]
            if "Droit de Timbre" in sp[1]:
                d.transfer_type = "BC"
            if "CERTIF" in sp[1]:
                d.transfer_type = "BC"
            if "SMS CHARGES" in sp[1]:
                d.transfer_type = "BC"
            if "COMM. MENSUELLES" in sp[1]:
                d.transfer_type = "BC"
            if sp[5]:
                d.transferred_amount = convert.str2float(sp[5], True)
            if sp[6]:
                d.transferred_amount = convert.str2float(sp[6])
            if sp[2] != '':
                d.transfer_type = "CK"
            last_balance = sp[7]
            last_date = sp[0]
            statement.transactions.append(d)
        statement.end_balance = convert.str2float(last_balance)
        statement.date = convert.str2date(last_date, '%d-%b-%Y')
        return [statement]