diff options
Diffstat (limited to 'python/report_ops/wires.py')
| -rw-r--r-- | python/report_ops/wires.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/python/report_ops/wires.py b/python/report_ops/wires.py index a2f5ce1d..60ad0e93 100644 --- a/python/report_ops/wires.py +++ b/python/report_ops/wires.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +import pandas as pd from typing import Literal import datetime from serenitas.ops.trade_dataclasses import Deal, Ccy @@ -44,11 +45,12 @@ class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"): cls.dtkey = dtkey def __post_init__(self): - self.amount = self.amount.replace(",", "") - if "(" in self.amount: - self.amount = -float(self.amount[1:-1]) - else: - self.amount = float(self.amount) + if not isinstance(self.amount, float): + self.amount = self.amount.replace(",", "") + if "(" in self.amount: + self.amount = -float(self.amount[1:-1]) + else: + self.amount = float(self.amount) @classmethod def get_newest_report(cls, fname, date): @@ -119,13 +121,33 @@ class SerenitasUMBWire( ): @classmethod def from_report_line(cls, line: dict): - return + return cls( + date=line["Transaction Date"], + entry_date=line["Transaction Date"], + value_date=line["Transaction Date"], + pay_date=line["Transaction Date"], + currency=line["Local Currency Code"], + amount=line["Net Amount"], + wire_details=line["Transaction Description"], + unique_ref=f'{line["Transaction Date"]}-{line["index"]}', + ) @classmethod def to_db(cls, date): - # conn = cls._conn - # with conn.cursor() as c: - # c.execute("DELETE FROM custodian_wires WHERE date=%s AND fund=%s AND custodian=%s", (date, cls.fund, cls.custodian,)) - # conn.commit() - # the unique ref will be generated from the row + the date and reports will only be delivered at 7pm daily - pass + p = cls.get_newest_report("umbwires_", date) + conn = cls._conn + with conn.cursor() as c: + c.execute( + "DELETE FROM custodian_wires WHERE date=%s AND fund=%s AND custodian=%s", + ( + date, + cls.fund, + cls.custodian, + ), + ) + conn.commit() + df = pd.read_excel(p, skiprows=3) + df["index"] = df.index + for row_dict in df.to_dict(orient="records"): + cls.from_report_line(row_dict).stage() + cls.commit() |
