Skip to content
Snippets Groups Projects
Commit 8eb24e7e authored by Daniele Nicolodi's avatar Daniele Nicolodi
Browse files

orders: Add check command

The check command compares the orders costs recorded in the ledger to
the one reported in SAP. It is useful to track down discrepancies in
the balances.
parent a20cfb25
No related branches found
No related tags found
No related merge requests found
......@@ -1021,6 +1021,68 @@ def balance(conf):
print(results.rename('amount', 'sap'))
@main.command()
@click.argument('accounts', nargs=-1, required=False)
@click.option('--verbose', '-v', count=True)
@click.pass_obj
def check(conf, accounts, verbose):
"""Verify amounts."""
log = print if verbose else lambda x: None
existing, errors, options = parser.parse_file(conf['ledger'])
if errors:
print_errors(errors)
sys.exit(1)
orders = {entry.meta.get('order'): entry for entry in existing if entry.meta.get('order') is not None}
accounts = accounts or list_designated_accounts(existing)
fromdate = datetime.date(1970, 1, 1)
todate = datetime.date(9999, 12, 31)
with sap.session(True) as session:
for account in accounts:
log(account)
entries = []
psp = account.rsplit(':', 1)[-1]
# Project Actual Cost Line Items
session.StartTransaction('CJI3')
setDbProfile(session)
session.findById('wnd[0]/usr/ctxtCN_PROJN-LOW').text = ''
session.findById('wnd[0]/usr/ctxtCN_PSPNR-LOW').text = psp
session.findById('wnd[0]/usr/ctxtR_BUDAT-LOW').text = fromdate.strftime('%d.%m.%Y')
session.findById('wnd[0]/usr/ctxtR_BUDAT-HIGH').text = todate.strftime('%d.%m.%Y')
session.findById('wnd[0]/usr/ctxtP_DISVAR').text = '/NICOLODI'
session.findById('wnd[0]').sendVKey(8)
if session.findById('wnd[0]/sbar').messageNumber != '422': # No line items were selected
entries += extract_po_postings(session, account)
# Project Commitment Line Items
session.StartTransaction('CJI5')
setDbProfile(session)
session.findById('wnd[0]/usr/ctxtCN_PROJN-LOW').text = ''
session.findById('wnd[0]/usr/ctxtCN_PSPNR-LOW').text = psp
session.findById('wnd[0]/usr/ctxtR_OBDAT-LOW').text = fromdate.strftime('%d.%m.%Y')
session.findById('wnd[0]/usr/ctxtR_OBDAT-HIGH').text = todate.strftime('%d.%m.%Y')
session.findById('wnd[0]/usr/ctxtP_DISVAR').text = '/NICOLODI'
session.findById('wnd[0]').sendVKey(8)
if session.findById('wnd[0]/sbar').messageNumber != '422': # No line items were selected
entries += extract_req_postings(session, account)
data = {entry.meta.get('order'): entry.postings[0].units for entry in entries}
for oid, amount in data.items():
entry = orders.get(oid)
if entry is None:
continue
log(f' {oid} {str(amount):>16s}')
if entry.postings[0].units != amount:
beanutils.print_entries([entry])
print(f';')
print(f'; {str(amount):>56s}')
def git_diff_filepath(filepath):
parent = path.dirname(filepath)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment