def stmtRq0(self): return StmtRq( acctid="111111", accttype="CHECKING", dtstart=datetime(2017, 1, 1, tzinfo=UTC), dtend=datetime(2017, 3, 31, tzinfo=UTC), )
def stmtRq1(self): return StmtRq( acctid="222222", accttype="SAVINGS", dtstart=datetime(2017, 1, 1, tzinfo=UTC), dtend=datetime(2017, 3, 31, tzinfo=UTC), )
def fetch_transactions_for_account(self, account): try: latest_transaction = Transaction.objects.filter(account=account).latest('date_posted') from_date = latest_transaction.date_posted.replace(tzinfo=OFX_UTC) except Transaction.DoesNotExist: from_date = datetime(2016, 1, 1, tzinfo=OFX_UTC) to_date = datetime.now().replace(tzinfo=OFX_UTC) statement_request = StmtRq(acctid=account.account_number, accttype=account.account_type, dtstart=from_date, dtend=to_date) response = self.bank.ofx_client.request_statements(self.bank.password, statement_request) parsed_response = self.parser.parse(response) yield from parsed_response.findall('.//STMTTRN')
def request_stmt(args: ArgsType) -> None: """ Send *STMTRQ """ dt = convert_datetime(args) password = get_passwd(args) if args["all"]: acctinfo = _request_acctinfo(args, password) _merge_acctinfo(args, acctinfo) stmtrqs: List[Union[StmtRq, CcStmtRq, InvStmtRq]] = [] for accttype in ("checking", "savings", "moneymrkt", "creditline"): stmtrqs.extend([ StmtRq( acctid=acctid, accttype=accttype.upper(), dtstart=dt["start"], dtend=dt["end"], inctran=args["inctran"], ) for acctid in args[accttype] ]) for acctid in args["creditcard"]: stmtrqs.append( CcStmtRq( acctid=acctid, dtstart=dt["start"], dtend=dt["end"], inctran=args["inctran"], )) for acctid in args["investment"]: stmtrqs.append( InvStmtRq( acctid=acctid, dtstart=dt["start"], dtend=dt["end"], dtasof=dt["asof"], inctran=args["inctran"], incoo=args["incoo"], incpos=args["incpos"], incbal=args["incbal"], )) if not stmtrqs: accttypes = [ "checking", "savings", "moneymrkt", "creditline", "creditcard", "investment", ] msg = f"No accounts specified; configure at least one of {accttypes}" warnings.warn(msg, category=SyntaxWarning) client = init_client(args) with client.request_statements(password, *stmtrqs, dryrun=args["dryrun"], verify_ssl=not args["unsafe"]) as f: response = f.read() print(response.decode()) if args["write"]: write_config(args) if args["savepass"]: save_passwd(args, password)
def testDoStmtDryrun(self): with patch("ofxtools.Client.OFXClient.request_statements" ) as fake_rq_stmt: fake_rq_stmt.return_value = BytesIO(b"th-th-th-that's all folks!") output = do_stmt(self.args) self.assertEqual(output, None) args, kwargs = fake_rq_stmt.call_args user, password, *stmtrqs = args self.assertEqual(user, "porkypig") self.assertEqual(password, "{:0<32}".format("anonymous")) self.assertEqual( stmtrqs, [ StmtRq( acctid="123", accttype="CHECKING", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="234", accttype="CHECKING", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="345", accttype="SAVINGS", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="456", accttype="SAVINGS", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="567", accttype="MONEYMRKT", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="678", accttype="MONEYMRKT", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="789", accttype="CREDITLINE", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), StmtRq( acctid="890", accttype="CREDITLINE", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), CcStmtRq( acctid="111", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), CcStmtRq( acctid="222", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, ), InvStmtRq( acctid="333", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), dtasof=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, incoo=False, incpos=True, incbal=True, ), InvStmtRq( acctid="444", dtstart=datetime(2007, 1, 1, tzinfo=UTC), dtend=datetime(2007, 12, 31, tzinfo=UTC), dtasof=datetime(2007, 12, 31, tzinfo=UTC), inctran=True, incoo=False, incpos=True, incbal=True, ), ], ) self.assertEqual( kwargs, { "clientuid": None, "dryrun": True, "close_elements": True, "prettyprint": False, })