diff options
| -rw-r--r-- | python/report_ops/custodians.py | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py index 95c0befa..82892a40 100644 --- a/python/report_ops/custodians.py +++ b/python/report_ops/custodians.py @@ -42,30 +42,27 @@ def upload_to_custodian(account, trade_date, conn, upload, em): for row in c: _service = {"BBH": "BRINKER", "UMB": "UMB"} custodian = Service[_service[account]] - d.execute("SELECT * FROM bond_csv_upload WHERE allocationid=%s", (row.id,)) + d.execute( + "SELECT identifier, principal_payment, accrued_payment FROM bond_csv_upload WHERE allocationid=%s", + (row.id,), + ) if old_trade := d.fetchone(): - try: + if (row.identifier, row.principal_payment, row.accrued_payment) != ( + old_trade.identifier, + old_trade.principal_payment, + old_trade.accrued_payment, + ): d.execute( - _csv_query, + "UPDATE bond_csv_upload SET identifier=%s AND principal_payment=%s AND accrued_payment=%s WHERE allocationid=%s", ( - row.id, row.identifier, row.principal_payment, row.accrued_payment, + row.id, ), ) - except UniqueViolation: # The trade has not changed. We are unique on allocation id, identifier, principal, and accrued - conn.rollback() - else: - d.execute( - "DELETE FROM bond_csv_upload WHERE id=%s AND identifier=%s AND principal_payment=%s AND accrued_payment=%s", - ( - old_trade.id, - old_trade.identifier, - old_trade.principal_payment, - old_trade.accrued_payment, - ), - ) + for trade in gen_csv(row._asdict(), account, old_trade._asdict()): + custodian.staging_queue.append(trade) else: for trade in gen_csv(row._asdict(), account): custodian.staging_queue.append(trade) |
