@@ -32,11 +32,11 @@ def test_conversions():
3232 c1_tbl = conversions_table ( c1 )
3333 print ( '\n ' + c1_tbl )
3434 assert c1_tbl == """\
35- | Coin | BTC | ETH | USD |
36- |--------+-------+ -------+-----------|
37- | BTC | 1 | ? | 23,456.8 |
38- | ETH | | 1 | 1,234.56 |
39- | USD | | | 1 |"""
35+ | Coin | in BTC | in ETH | in USD |
36+ |--------+----------+--- -------+-----------|
37+ | BTC | | ? | 23,456.78 |
38+ | ETH | | | 1,234.56 |
39+ | USD | | | |"""
4040
4141 c_simple = dict ( c1 )
4242 c_simple_i = 0
@@ -46,11 +46,11 @@ def test_conversions():
4646 c_simple_tbl = conversions_table ( c_simple )
4747 print ( c_simple_tbl )
4848 assert c_simple_tbl == """\
49- | Coin | BTC | ETH | USD |
50- |--------+-------------+-------------- +-----------|
51- | BTC | 1 | 19.0001 | 23,456.8 |
52- | ETH | 0.0526313 | 1 | 1,234.56 |
53- | USD | 4.26316e-05 | 0.000810005 | 1 |"""
49+ | Coin | in BTC | in ETH | in USD |
50+ |--------+-------------+-----------+-----------|
51+ | BTC | | 19.000113 | 23,456.78 |
52+ | ETH | 0.052631265 | | 1,234.56 |
53+ | USD | | | |"""
5454
5555 c_w_doge = dict ( c1 , ) | { ('DOGE' ,'BTC' ): .00000385 , ('DOGE' ,'USD' ): None }
5656 c_w_doge_i = 0
@@ -74,12 +74,22 @@ def test_conversions():
7474 c_w_doge_tbl = conversions_table ( c_w_doge )
7575 print ( c_w_doge_tbl )
7676 assert c_w_doge_tbl == """\
77- | Coin | BTC | DOGE | ETH | USD |
78- |--------+-------------+--------------+--------------+----------------|
79- | BTC | 1 | 259,740 | 19.0001 | 23,456.8 |
80- | DOGE | 3.85e-06 | 1 | 7.31504e-05 | 0.0903086 |
81- | ETH | 0.0526313 | 13,670.5 | 1 | 1,234.56 |
82- | USD | 4.26316e-05 | 11.0731 | 0.000810005 | 1 |"""
77+ | Coin | in BTC | in DOGE | in ETH | in USD |
78+ |--------+----------+----------------+-----------+-----------|
79+ | BTC | | 259,740.26 | 19.000113 | 23,456.78 |
80+ | DOGE | | | | |
81+ | ETH | | 13,670.458 | | 1,234.56 |
82+ | USD | | 11.073142 | | |"""
83+
84+ c_w_doge_all = conversions_table ( c_w_doge , greater = False )
85+ print ( c_w_doge_all )
86+ assert c_w_doge_all == """\
87+ | Coin | in BTC | in DOGE | in ETH | in USD |
88+ |--------+---------------+----------------+----------------+------------------|
89+ | BTC | | 259,740.26 | 19.000113 | 23,456.78 |
90+ | DOGE | 3.85e-06 | | 7.3150437e-05 | 0.090308603 |
91+ | ETH | 0.052631265 | 13,670.458 | | 1,234.56 |
92+ | USD | 4.2631597e-05 | 11.073142 | 0.00081000518 | |"""
8393
8494 c_bad = dict ( c1 , ) | { ('DOGE' ,'USD' ): None }
8595 with pytest .raises ( Exception ) as c_bad_exc :
@@ -107,7 +117,7 @@ def test_conversions():
107117 LineItem (
108118 description = "More Widgets" ,
109119 units = 2500 ,
110- price = Fraction ( 201 , 1000 ),
120+ price = Fraction ( 201 , 100000 ),
111121 tax = Fraction ( 5 , 100 ), # exclusive
112122 currency = 'ETH' ,
113123 ),
@@ -116,7 +126,7 @@ def test_conversions():
116126 LineItem (
117127 description = "Something else, very detailed and elaborate to explain" ,
118128 units = 100 ,
119- price = Fraction ( 201 , 10000 ),
129+ price = Fraction ( 201 , 100000 ),
120130 tax = Fraction ( 105 , 100 ), # inclusive
121131 decimals = 8 ,
122132 currency = 'Bitcoin' ,
@@ -126,7 +136,7 @@ def test_conversions():
126136 LineItem (
127137 description = "Buy some Holo hosting" ,
128138 units = 12 ,
129- price = 10000 ,
139+ price = 12345.6 ,
130140 tax = Fraction ( 5 , 100 ), # inclusive
131141 currency = 'HoloToken' ,
132142 ),
@@ -294,41 +304,74 @@ def test_tabulate( tmp_path ):
294304
295305 inv_date = parse_datetime ( "2021-01-01 00:00:00.1 Canada/Pacific" )
296306
297- (paper_format ,orientation ),pdf ,metadata = produce_invoice (
298- invoice = shorter_invoice ,
299- inv_date = inv_date ,
300- vendor = Contact (
301- name = "Dominion Research & Development Corp." ,
302- contact = "Perry Kundert <[email protected] >" ,
303- phone = "+1-780-970-8148" ,
304- address = """\
307+ vendor = Contact (
308+ name = "Dominion Research & Development Corp." ,
309+ contact = "Perry Kundert <[email protected] >" ,
310+ phone = "+1-780-970-8148" ,
311+ address = """\
305312 275040 HWY 604
306313Lacombe, AB T4L 2N3
307314CANADA
308315""" ,
309- billing = """\
316+ billing = """\
310317 RR#3, Site 1, Box 13
311318Lacombe, AB T4L 2N3
312319CANADA
313320""" ,
314- ),
315- client = Contact (
316- name = "Awesome, Inc." ,
317- contact = "Great Guy <[email protected] >" ,
318- address = """\
321+ )
322+ client = Contact (
323+ name = "Awesome, Inc." ,
324+ contact = "Great Guy <[email protected] >" ,
325+ address = """\
319326 123 Awesome Ave.
320327Schenectady, NY 12345
321328USA
322329""" ,
323- ),
330+ )
331+
332+ (paper_format ,orientation ),pdf ,metadata = produce_invoice (
333+ invoice = shorter_invoice ,
334+ inv_date = inv_date ,
335+ vendor = vendor ,
336+ client = client ,
324337 directory = test ,
325- inv_image = 'dominionrnd-invoice.png' , # Full page background image
338+ # inv_image = 'dominionrnd-invoice.png', # Full page background image
326339 inv_logo = 'dominionrnd-logo.png' , # Logo 16/9 in bottom right of header
327340 inv_label = 'Quote' ,
328341 )
329342
330343 print ( f"Invoice metadata: { metadata } " )
331344 temp = Path ( tmp_path )
332- path = temp / 'invoice.pdf'
345+ path = temp / 'invoice-shorter.pdf'
346+ pdf .output ( path )
347+ print ( f"Invoice saved: { path } " )
348+
349+ # Finally, generate invoice with all rows, and all conversions from blockchain Oracle (except
350+ # XRP, for which we do not have an oracle, so must provide an estimate from another source...)
351+ complete_invoice = Invoice (
352+ [
353+ line
354+ for line ,_ in line_amounts
355+ ],
356+ currencies = ["HOT" , "ETH" , "BTC" , "USD" ],
357+ accounts = accounts ,
358+ conversions = {
359+ ("BTC" ,"XRP" ): 60000 ,
360+ }
361+ )
362+
363+ (paper_format ,orientation ),pdf ,metadata = produce_invoice (
364+ invoice = complete_invoice ,
365+ inv_date = inv_date ,
366+ vendor = vendor ,
367+ client = client ,
368+ directory = test ,
369+ #inv_image = 'dominionrnd-invoice.png', # Full page background image
370+ inv_logo = 'dominionrnd-logo.png' , # Logo 16/9 in bottom right of header
371+ )
372+
373+ print ( f"Invoice metadata: { metadata } " )
374+ temp = Path ( tmp_path )
375+ path = temp / 'invoice-complete.pdf'
333376 pdf .output ( path )
334377 print ( f"Invoice saved: { path } " )
0 commit comments