# Path: pynYNAB/schema/budget.py
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)
# 
# Path: pynYNAB/utils.py
# def get_or_create_account(client, name):
#     accounts = {a.account_name: a for a in client.budget.be_accounts if
#                 a.account_name == name}
#     if name in accounts:
#         return accounts[name]
# 
#     account = Account(
#         account_type=AccountTypes.Checking,
#         account_name=name
#     )
# 
#     client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now())
#     return account
# 
# def get_or_create_payee(client, name):
#     payees = {p.name: p for p in client.budget.be_payees if
#               p.name == name}
#     if name in payees:
#         return payees[name]
#     payee = Payee(
#         name=name
#     )
# 
#     client.budget.be_payees.append(payee)
#     client.push(1)
#     return payee


import json
import os
import tempfile
import unittest
import configargparse
from datetime import datetime
from pynYNAB.schema.budget import Transaction
from pynYNAB.scripts.ofximport import do_ofximport
from pynYNAB.utils import get_or_create_account, get_or_create_payee
from common import TestCommonMock
                    <BANKACCTFROM>
                    <BANKID>11706
                    <BRANCHID>41029
                    <ACCTID>29939615002
                    <ACCTTYPE>CHECKING
                </BANKACCTFROM>
                <BANKTRANLIST>
                    <DTSTART>20130128000000
                    <DTEND>20130314235959
                    <STMTTRN>
                        <TRNTYPE>CHECK
                        <DTPOSTED>20130312
                        <TRNAMT>-491.09
                        <FITID>13071099780237330004
                        <CHECKNUM>0003445
                        <NAME>CHEQUE
                        <MEMO>CHEQUE
                    </STMTTRN>
                </BANKTRANLIST>
                <LEDGERBAL>
                    <BALAMT>-6348.01
                    <DTASOF>20130312
                </LEDGERBAL>
                <AVAILBAL>
                <BALAMT>-6348.01
                <DTASOF>20130312
                </AVAILBAL>
            </STMTRS>
        </STMTTRNRS>
    </BANKMSGSRSV1>

# Path: pynYNAB/schema/budget.py
# class Transaction(Base, BudgetEntity):
#     accepted = Column(Boolean, default=True)
#     amount = Column(AmountType)
#     cash_amount = Column(AmountType)
#     check_number = Column(String)
#     cleared = Column(String, default='Uncleared')
#     credit_amount = Column(AmountType)
#     credit_amount_adjusted = Column(AmountType)
#     date = Column(Date)
#     date_entered_from_schedule = Column(Date)
#     entities_account_id = Column(ForeignKey('account.id'))
#     entities_account = relationship('Account', foreign_keys=entities_account_id)
#     entities_payee_id = Column(ForeignKey('payee.id'))
#     entities_payee = relationship('Payee')
#     entities_scheduled_transaction_id = Column(ForeignKey('scheduledtransaction.id'))
#     entities_subcategory_id = Column(ForeignKey('subcategory.id'))
#     entities_subcategory = relationship('SubCategory')
#     flag = Column(Enum(ColorFlagType), default=None)
#     imported_date = Column(Date)
#     imported_payee = Column(String)
#     matched_transaction_id = Column(ForeignKey('transaction.id'))
#     matched_transaction = relationship('Transaction', foreign_keys=matched_transaction_id)
#     memo = Column(String)
#     source = Column(String)
#     subcategory_credit_amount_preceding = Column(AmountType, default=0)
#     transfer_account_id = Column(ForeignKey('account.id'))
#     transfer_account = relationship('Account', foreign_keys=transfer_account_id)
#     transfer_subtransaction_id = Column(ForeignKey('subtransaction.id'))
#     transfer_transaction_id = Column(ForeignKey('transaction.id'))
#     transfer_transaction = relationship('Transaction', foreign_keys=transfer_transaction_id)
#     ynab_id = Column(String)
# 
# Path: pynYNAB/utils.py
# def get_or_create_account(client, name):
#     accounts = {a.account_name: a for a in client.budget.be_accounts if
#                 a.account_name == name}
#     if name in accounts:
#         return accounts[name]
# 
#     account = Account(
#         account_type=AccountTypes.Checking,
#         account_name=name
#     )
# 
#     client.add_account(account, balance=random.randint(-10, 10), balance_date=datetime.now())
#     return account
# 
# def get_or_create_payee(client, name):
#     payees = {p.name: p for p in client.budget.be_payees if
#               p.name == name}
#     if name in payees:
#         return payees[name]
#     payee = Payee(
#         name=name
#     )
# 
#     client.budget.be_payees.append(payee)
#     client.push(1)
#     return payee


# Path: testscripts/test_ofximport.py
import json
import os
import tempfile
import unittest
import configargparse
from datetime import datetime
from pynYNAB.schema.budget import Transaction
from pynYNAB.scripts.ofximport import do_ofximport
from pynYNAB.utils import get_or_create_account, get_or_create_payee
from common import TestCommonMock

                    <BANKACCTFROM>
                    <BANKID>11706
                    <BRANCHID>41029
                    <ACCTID>29939615002
                    <ACCTTYPE>CHECKING
                </BANKACCTFROM>
                <BANKTRANLIST>
                    <DTSTART>20130128000000
                    <DTEND>20130314235959
                    <STMTTRN>
                        <TRNTYPE>CHECK
                        <DTPOSTED>20130312
                        <TRNAMT>-491.09
                        <FITID>13071099780237330004
                        <CHECKNUM>0003445
                        <NAME>CHEQUE
                        <MEMO>CHEQUE
                    </STMTTRN>
                </BANKTRANLIST>
                <LEDGERBAL>
                    <BALAMT>-6348.01
                    <DTASOF>20130312
                </LEDGERBAL>
                <AVAILBAL>
                <BALAMT>-6348.01
                <DTASOF>20130312
                </AVAILBAL>
            </STMTRS>
        </STMTTRNRS>
    </BANKMSGSRSV1>

</OFX>"""