(self, st_group, line)
return st_group
33 - Registro final de cuenta
33 - Registro final de cuenta
33 - Registro final de cuenta
def _process_record_33(self, st_group, line):
        """33 - Registro final de cuenta"""
        st_group["num_debe"] += int(line[20:25])
        st_group["debe"] += float("{}.{}".format(line[25:37], line[37:39]))
        st_group["num_haber"] += int(line[39:44])
        st_group["haber"] += float("{}.{}".format(line[44:56], line[56:58]))
        st_group["saldo_fin"] += float("{}.{}".format(line[59:71], line[71:73]))
        if line[58:59] == "1":  # pragma: no cover
            st_group["saldo_fin"] *= -1
        # Group level checks
        debit_count = 0
        debit = 0.0
        credit_count = 0
        credit = 0.0
        for st_line in st_group["lines"]:
            if st_line["importe"] < 0:
                debit_count += 1
                debit -= st_line["importe"]
            else:
                credit_count += 1
                credit += st_line["importe"]
        if st_group["num_debe"] != debit_count:  # pragma: no cover
            raise exceptions.UserError(
                _(
                    "Number of debit records doesn't match with the defined in "
                    "the last record of account."
                )
            )
        if st_group["num_haber"] != credit_count:  # pragma: no cover
            raise exceptions.UserError(
                _(
                    "Number of credit records doesn't match with the defined "
                    "in the last record of account."
                )
            )
        if abs(st_group["debe"] - debit) > 0.005:  # pragma: no cover
            raise exceptions.UserError(
                _(
                    "Debit amount doesn't match with the defined in the last "
                    "record of account."
                )
            )
        if abs(st_group["haber"] - credit) > 0.005:  # pragma: no cover
            raise exceptions.UserError(
                _(
                    "Credit amount doesn't match with the defined in the last "
                    "record of account."
                )
            )
        # Note: Only perform this check if the balance is defined on the file
        # record, as some banks may leave it empty (zero) on some circumstances
        # (like CaixaNova extracts for VISA credit cards).
        if st_group["saldo_fin"] and st_group["saldo_ini"]:  # pragma: no cover
            balance = st_group["saldo_ini"] + credit - debit
            if abs(st_group["saldo_fin"] - balance) > 0.005:
                raise exceptions.UserError(
                    _(
                        "Final balance amount = (initial balance + credit "
                        "- debit) doesn't match with the defined in the last "
                        "record of account."
                    )
                )
        return st_group
def _process_record_33 ( self , st_group , line ) : st_group [ "num_debe" ] += int ( line [ 20 : 25 ] ) st_group [ "debe" ] += float ( "{}.{}" . format ( line [ 25 : 37 ] , line [ 37 : 39 ] ) ) st_group [ "num_haber" ] += int ( line [ 39 : 44 ] ) st_group [ "haber" ] += float ( "{}.{}" . format ( line [ 44 : 56 ] , line [ 56 : 58 ] ) ) st_group [ "saldo_fin" ] += float ( "{}.{}" . format ( line [ 59 : 71 ] , line [ 71 : 73 ] ) ) if line [ 58 : 59 ] == "1" : # pragma: no cover st_group [ "saldo_fin" ] *= - 1 # Group level checks debit_count = 0 debit = 0.0 credit_count = 0 credit = 0.0 for st_line in st_group [ "lines" ] : if st_line [ "importe" ] < 0 : debit_count += 1 debit -= st_line [ "importe" ] else : credit_count += 1 credit += st_line [ "importe" ] if st_group [ "num_debe" ] != debit_count : # pragma: no cover raise exceptions . UserError ( _ ( "Number of debit records doesn't match with the defined in " "the last record of account." ) ) if st_group [ "num_haber" ] != credit_count : # pragma: no cover raise exceptions . UserError ( _ ( "Number of credit records doesn't match with the defined " "in the last record of account." ) ) if abs ( st_group [ "debe" ] - debit ) > 0.005 : # pragma: no cover raise exceptions . UserError ( _ ( "Debit amount doesn't match with the defined in the last " "record of account." ) ) if abs ( st_group [ "haber" ] - credit ) > 0.005 : # pragma: no cover raise exceptions . UserError ( _ ( "Credit amount doesn't match with the defined in the last " "record of account." ) ) # Note: Only perform this check if the balance is defined on the file # record, as some banks may leave it empty (zero) on some circumstances # (like CaixaNova extracts for VISA credit cards). if st_group [ "saldo_fin" ] and st_group [ "saldo_ini" ] : # pragma: no cover balance = st_group [ "saldo_ini" ] + credit - debit if abs ( st_group [ "saldo_fin" ] - balance ) > 0.005 : raise exceptions . UserError ( _ ( "Final balance amount = (initial balance + credit " "- debit) doesn't match with the defined in the last " "record of account." ) ) return st_group