Thanks for any help you can give me.
*Question about Report Format String*The "lot price" (the price of one share) is shown in curly braces by the format string parameter %(amount). But I have been unable to obtain just the "lot price" using a format string parameter. I suspect that %(price) was intended to be the "lot price" and that it is a bug that it displays the %(cost) instead. *Question about the Ledger Python Extension* How do you obtain the "lot price" using the Ledger Python Extension? I suspect that either post.price or post.amount.price should be the "lot price" and that it is a bug that neither exists. *File lots.ledger*Attached is lots.ledger, a small test journal that shows the problem: 2008-02-19 (0) SPDR Lehman Int'l Tres. Bond ETF - Buy 100 shares > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX 200.0000 @ $27.25 > Expenses:Investment Expenses:Commissions:Vanguard $2.18 > * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free > MMF $-5,452.18 > > 2008-02-19 (1) SPDR Lehman Int'l Tres. Bond ETF - Buy 117 shares > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX 234.0000 @ $27.24995726 > Expenses:Investment Expenses:Commissions:Vanguard $2.56 > * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free > MMF $-6,379.05 > > 2008-02-19 (2) SPDR Lehman Int'l Tres. Bond ETF - Buy 700 shares > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX 1400.0000 @ $27.25 > Expenses:Investment Expenses:Commissions:Vanguard $15.26 > * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free > MMF $-38,165.26 > > 2017-06-23 (1to15) SPDR Lehman Int'l Tres. Bond ETF - Sell 3229.1222 > shares > Assets:Vanguard Trust Account:Vanguard Federal Money Market Fund > $50,736.76 > Expenses:Investment Expenses:Commissions:Vanguard $1.95 > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX -200.0000 @ $27.6656 ; Sold all of lot 0 > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX -1400.0000 @ $27.6656 ; Sold all of lot 2 > Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR > Barclays Int'l Bond ETF BWX -234.0000 @ $27.66559829 ; Sold all of lot 1 > > *Showing the Reports Problem*Here is a report format that shows the problem when run on lots.ledger: ledger -f lots.ledger reg --no-revalued --format 'code=%C > amount="%(amount)" quantity=%(quantity(amount)) cost=%(cost) > price=%(price)\n' > 2017-08-02 15:34:43 /pri/git/Ledger4/bugs > $ ledger -f lots.ledger reg --no-revalued --format 'code=%C > amount="%(amount)" quantity=%(quantity(amount)) cost=%(cost) > price=%(price)\n' > code=(0) amount="BWX 200.0000 {$27.25} [08-Feb-19]" quantity=200 > cost=$5,450.00 price=$5,450.00 > code=(0) amount="$2.18" quantity=2.18 cost=$2.18 price=$2.18 > code=(0) amount="$-5,452.18" quantity=-5452.18 cost=$-5,452.18 > price=$-5,452.18 > code=(1) amount="BWX 234.0000 {$27.24995726} [08-Feb-19]" quantity=234 > cost=$6,376.48999884 price=$6,376.48999884 > code=(1) amount="$2.56" quantity=2.56 cost=$2.56 price=$2.56 > code=(1) amount="$-6,379.05" quantity=-6379.05 cost=$-6,379.05 > price=$-6,379.05 > code=(2) amount="BWX 1400.0000 {$27.25} [08-Feb-19]" quantity=1400 > cost=$38,150.00 price=$38,150.00 > code=(2) amount="$15.26" quantity=15.26 cost=$15.26 price=$15.26 > code=(2) amount="$-38,165.26" quantity=-38165.26 cost=$-38,165.26 > price=$-38,165.26 > code=(1to15) amount="$50,736.76" quantity=50736.76 cost=$50,736.76 > price=$50,736.76 > code=(1to15) amount="$1.95" quantity=1.95 cost=$1.95 price=$1.95 > code=(1to15) amount="BWX -200.0000 {$27.6656} [17-Jun-23]" quantity=-200 > cost=$-5,533.12 price=$-5,533.12 > code=(1to15) amount="BWX -1400.0000 {$27.6656} [17-Jun-23]" > quantity=-1400 cost=$-38,731.84 price=$-38,731.84 > code=(1to15) amount="BWX -234.0000 {$27.66559829} [17-Jun-23]" > quantity=-234 cost=$-6,473.74999986 price=$-6,473.74999986 > 2017-08-02 15:35:22 /pri/git/Ledger4/bugs > > *File costPrice.py*Attached is costPrice.py, a Python script that shows the problem when run on lots.ledger. Here is the print statement that generates the output: print('code={code} amount="{amt}" quantity={qt} cost={cost} > price={price} amount.price={aprice}'.format( > code=xact.code, amt=post.amount, qt=post.amount.number(), > cost=post.cost, price=hasattr(post, 'price'), > aprice=hasattr(post.amount.price, 'price'))) > 2017-08-02 16:00:18 /pri/git/Ledger4/bugs/price > $ python2 costPrice.py lots.ledger > code=0 amount="BWX 200.0000 {$27.25} [08-Feb-19]" quantity=200 > cost=$5,450.00 price=False amount.price=False > code=0 amount="$2.18" quantity=2.18 cost=None price=False > amount.price=False > code=0 amount="$-5,452.18" quantity=-5452.18 cost=None price=False > amount.price=False > code=1 amount="BWX 234.0000 {$27.24995726} [08-Feb-19]" quantity=234 > cost=$6,376.48999884 price=False amount.price=False > code=1 amount="$2.56" quantity=2.56 cost=None price=False > amount.price=False > code=1 amount="$-6,379.05" quantity=-6379.05 cost=None price=False > amount.price=False > code=2 amount="BWX 1400.0000 {$27.25} [08-Feb-19]" quantity=1400 > cost=$38,150.00 price=False amount.price=False > code=2 amount="$15.26" quantity=15.26 cost=None price=False > amount.price=False > code=2 amount="$-38,165.26" quantity=-38165.26 cost=None price=False > amount.price=False > code=1to15 amount="$50,736.76" quantity=50736.76 cost=None price=False > amount.price=False > code=1to15 amount="$1.95" quantity=1.95 cost=None price=False > amount.price=False > code=1to15 amount="BWX -200.0000 {$27.6656} [17-Jun-23]" quantity=-200 > cost=$-5,533.12 price=False amount.price=False > code=1to15 amount="BWX -1400.0000 {$27.6656} [17-Jun-23]" quantity=-1400 > cost=$-38,731.84 price=False amount.price=False > code=1to15 amount="BWX -234.0000 {$27.66559829} [17-Jun-23]" quantity=-234 > cost=$-6,473.74999986 price=False amount.price=False > 2017-08-02 16:00:21 /pri/git/Ledger4/bugs/price > -- --- You received this message because you are subscribed to the Google Groups "Ledger" group. To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/python2 #@+leo-ver=5-thin #@+node:bob.20170802153736.1: * @file bugs/price/costPrice.py #@@first # -*- encoding: utf-8 -*- #@@language python #@@tabwidth -4 #@+<< imports >> #@+node:bob.20170802153736.2: ** << imports >> import argparse import codecs import ledger #@-<< imports >> #@+<< Parameters >> #@+node:bob.20170802153736.3: ** << Parameters >> Revision = '0.1' #@-<< Parameters >> #@+others #@+node:bob.20170802153736.4: ** cmdLineHandler() def cmdLineHandler(): """ Command Line Handler @param return: Instance of class argparse.Namespace containing all the parsed command line arguments. """ parser = argparse.ArgumentParser(description='Print all the posts to the specified accounts ' , usage='%(prog)s [options] pathJournal pathJson') parser.add_argument('-v', '--version', action='version', version='%(prog)s Revision {0}'.format(Revision)) parser.add_argument('fpnJournal', help='Pathname of the Ledger File') args = parser.parse_args() return args #@+node:bob.20170802153736.5: ** main() def main(): args = cmdLineHandler() session = ledger.read_journal(args.fpnJournal) for xact in session.xacts(): for post in xact.posts(): print('code={code} amount="{amt}" quantity={qt} cost={cost} price={price} amount.price={aprice}'.format( code=xact.code, amt=post.amount, qt=post.amount.number(), cost=post.cost, price=hasattr(post, 'price'), aprice=hasattr(post.amount.price, 'price'))) #@-others if __name__ == '__main__': main() #@-leo
lots.ledger
Description: Binary data