11import click
2- from pyfx import PyfxApp
32
43from clidat .meta import (
54 company_and_connection_ids_required ,
87 company_id_required_with_pagination ,
98)
109
10+ from ..tui .viewer import ViewerDispatcher
11+
1112
1213@click .command ("get-accounts" )
1314@click .pass_context
@@ -19,6 +20,7 @@ def get_accounts(
1920 page_number : int ,
2021 query : str ,
2122 order_by : str ,
23+ json : bool = False ,
2224):
2325 client = ctx .obj
2426 accounts = client .get_accounts_page (
@@ -28,17 +30,25 @@ def get_accounts(
2830 query = query ,
2931 order_by = order_by ,
3032 )
31- PyfxApp (data = accounts ).run ()
33+ accounts_json = accounts .json ()
34+ viewer = ViewerDispatcher (
35+ data = accounts_json , json_flag = json , data_type = "Chart of Accounts"
36+ )
37+ viewer ()
3238
3339
3440@click .command ("get-account" )
3541@click .pass_context
3642@click .option ("--account" , required = True , type = str )
3743@company_id_required
38- def get_account (ctx : click .Context , company_id : str , account : str ):
44+ def get_account (ctx : click .Context , company_id : str , account : str , json : bool = False ):
3945 client = ctx .obj
4046 account_result = client .get_account (company_id , account )
41- PyfxApp (data = account_result ).run ()
47+ account_result_json = account_result .json ()
48+ viewer = ViewerDispatcher (
49+ data = account_result_json , json_flag = json , data_type = "Accounts"
50+ )
51+ viewer ()
4252
4353
4454@click .command ("get-account-transactions" )
@@ -52,6 +62,7 @@ def get_account_transactions(
5262 page_number : int ,
5363 query : str ,
5464 order_by : str ,
65+ json : bool = False ,
5566):
5667 client = ctx .obj
5768 account_transactions = client .get_account_transactions_page (
@@ -62,21 +73,37 @@ def get_account_transactions(
6273 query = query ,
6374 order_by = order_by ,
6475 )
65- PyfxApp (data = account_transactions ).run ()
76+ account_transactions_json = account_transactions .json ()
77+ viewer = ViewerDispatcher (
78+ data = account_transactions_json ,
79+ json_flag = json ,
80+ data_type = "List of Account Transactions" ,
81+ )
82+ viewer ()
6683
6784
6885@click .command ("get-account-transaction" )
6986@click .pass_context
7087@click .option ("--account-transaction" , required = True , type = str )
7188@company_and_connection_ids_required
7289def get_account_transaction (
73- ctx : click .Context , company_id : str , connection : str , account_transaction : str
90+ ctx : click .Context ,
91+ company_id : str ,
92+ connection : str ,
93+ account_transaction : str ,
94+ json : bool = False ,
7495):
7596 client = ctx .obj
7697 account_transaction_result = client .get_account_transaction (
7798 company_id , connection , account_transaction
7899 )
79- PyfxApp (data = account_transaction_result ).run ()
100+ account_transaction_result_json = account_transaction_result .json ()
101+ viewer = ViewerDispatcher (
102+ data = account_transaction_result_json ,
103+ json_flag = json ,
104+ data_type = "Account Transaction" ,
105+ )
106+ viewer ()
80107
81108
82109@click .command ("get-bills" )
@@ -89,6 +116,7 @@ def get_bills(
89116 page_number : int ,
90117 query : str ,
91118 order_by : str ,
119+ json : bool = False ,
92120):
93121 client = ctx .obj
94122 bills = client .get_bills_page (
@@ -98,17 +126,23 @@ def get_bills(
98126 query = query ,
99127 order_by = order_by ,
100128 )
101- PyfxApp (data = bills ).run ()
129+ bills_json = bills .json ()
130+ viewer = ViewerDispatcher (
131+ data = bills_json , json_flag = json , data_type = "List of Bills"
132+ )
133+ viewer ()
102134
103135
104136@click .command ("get-bill" )
105137@click .pass_context
106138@click .option ("--bill" , required = True , type = str )
107139@company_id_required
108- def get_bill (ctx : click .Context , company_id : str , bill : str ):
140+ def get_bill (ctx : click .Context , company_id : str , bill : str , json : bool = False ):
109141 client = ctx .obj
110142 bill_result = client .get_bill (company_id , bill )
111- PyfxApp (data = bill_result ).run ()
143+ bill_result_json = bill_result .json ()
144+ viewer = ViewerDispatcher (data = bill_result_json , json_flag = json , data_type = "Bills" )
145+ viewer ()
112146
113147
114148@click .command ("get-suppliers" )
@@ -121,6 +155,7 @@ def get_suppliers(
121155 page_number : int ,
122156 query : str ,
123157 order_by : str ,
158+ json : bool = False ,
124159):
125160 client = ctx .obj
126161 suppliers = client .get_suppliers_page (
@@ -130,17 +165,27 @@ def get_suppliers(
130165 query = query ,
131166 order_by = order_by ,
132167 )
133- PyfxApp (data = suppliers ).run ()
168+ suppliers_json = suppliers .json ()
169+ viewer = ViewerDispatcher (
170+ data = suppliers_json , json_flag = json , data_type = "List of Suppliers"
171+ )
172+ viewer ()
134173
135174
136175@click .command ("get-supplier" )
137176@click .pass_context
138177@click .option ("--supplier" , required = True , type = str )
139178@company_id_required
140- def get_supplier (ctx : click .Context , company_id : str , supplier : str ):
179+ def get_supplier (
180+ ctx : click .Context , company_id : str , supplier : str , json : bool = False
181+ ):
141182 client = ctx .obj
142183 supplier_result = client .get_supplier (company_id , supplier )
143- PyfxApp (data = supplier_result ).run ()
184+ supplier_result_json = supplier_result .json ()
185+ viewer = ViewerDispatcher (
186+ data = supplier_result_json , json_flag = json , data_type = "Supplier"
187+ )
188+ viewer ()
144189
145190
146191@click .command ("get-invoices" )
@@ -153,6 +198,7 @@ def get_invoices(
153198 page_number : int ,
154199 query : str ,
155200 order_by : str ,
201+ json : bool = False ,
156202):
157203 client = ctx .obj
158204 invoices = client .get_invoices_page (
@@ -162,17 +208,25 @@ def get_invoices(
162208 query = query ,
163209 order_by = order_by ,
164210 )
165- PyfxApp (data = invoices ).run ()
211+ invoices_json = invoices .json ()
212+ viewer = ViewerDispatcher (
213+ data = invoices_json , json_flag = json , data_type = "List of Invoices"
214+ )
215+ viewer ()
166216
167217
168218@click .command ("get-invoice" )
169219@click .pass_context
170220@click .option ("--invoice" , required = True , type = str )
171221@company_id_required
172- def get_invoice (ctx : click .Context , company_id : str , invoice : str ):
222+ def get_invoice (ctx : click .Context , company_id : str , invoice : str , json : bool = False ):
173223 client = ctx .obj
174224 invoice_result = client .get_invoice (company_id , invoice )
175- PyfxApp (data = invoice_result ).run ()
225+ invoice_result_json = invoice_result .json ()
226+ viewer = ViewerDispatcher (
227+ data = invoice_result_json , json_flag = json , data_type = "Invoice"
228+ )
229+ viewer ()
176230
177231
178232@click .command ("get-payments" )
@@ -185,6 +239,7 @@ def get_payments(
185239 page_number : int ,
186240 query : str ,
187241 order_by : str ,
242+ json : bool = False ,
188243):
189244 client = ctx .obj
190245 payments = client .get_payment_page (
@@ -194,14 +249,22 @@ def get_payments(
194249 query = query ,
195250 order_by = order_by ,
196251 )
197- PyfxApp (data = payments ).run ()
252+ payments_json = payments .json ()
253+ viewer = ViewerDispatcher (
254+ data = payments_json , json_flag = json , data_type = "List of Payments"
255+ )
256+ viewer ()
198257
199258
200259@click .command ("get-payment" )
201260@click .pass_context
202261@click .option ("--payment" , required = True , type = str )
203262@company_id_required
204- def get_payment (ctx : click .Context , company_id : str , payment : str ):
263+ def get_payment (ctx : click .Context , company_id : str , payment : str , json : bool = False ):
205264 client = ctx .obj
206265 payment_result = client .get_payment (company_id , payment )
207- PyfxApp (data = payment_result ).run ()
266+ payment_result_json = payment_result .json ()
267+ viewer = ViewerDispatcher (
268+ data = payment_result_json , json_flag = json , data_type = "Payment"
269+ )
270+ viewer ()
0 commit comments