diff options
Diffstat (limited to 'python/Dawn/views.py')
| -rw-r--r-- | python/Dawn/views.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py index 897cef58..abd9ce83 100644 --- a/python/Dawn/views.py +++ b/python/Dawn/views.py @@ -385,23 +385,22 @@ def terminate(dealid, kind): termination = Termination() form = TerminationForm(dealid=dealid) form.termination_cp.choices = form.termination_cp.choices + list(cp_choices(kind)) + table = kind if kind.endswith("s") else kind + "s" if form.validate_on_submit(): form.populate_obj(termination) session = form.get_session() - if not termination.partial_termination or termination.termination_cp is None: - rec = db.session.execute( - "SELECT cp_code, notional, coalesce(terminated_amount, 0.) " - "FROM swaptions " - "LEFT JOIN " - "(SELECT dealid, sum(termination_amount) AS terminated_amount " - " FROM terminations group by dealid) term USING (dealid) " - "WHERE dealid = :dealid", - {"dealid": dealid}, - ) - cp_code, notional, terminated_amount = next(rec) + rec = db.session.execute( + "SELECT notional, coalesce(terminated_amount, 0.), currency, globeop_id " + f"FROM {table} " + "LEFT JOIN " + "(SELECT dealid, sum(termination_amount) AS terminated_amount " + " FROM terminations group by dealid) term USING (dealid) " + "WHERE dealid = :dealid", + {"dealid": dealid}, + ) + notional, terminated_amount, currency, globeop_id = next(rec) + if not termination.partial_termination: termination.termination_amount = notional - terminated_amount - if termination.termination_cp is None: - termination.termination_cp = cp_code session.add(termination) try: session.commit() @@ -409,7 +408,7 @@ def terminate(dealid, kind): app.logger.error(e) session.rollback() else: - buf = simple_serialize(termination) + buf = simple_serialize(termination, ccy=currency, globeopid=globeop_id) q = get_queue() q.rpush(f"{kind}_termination", buf) return redirect(url_for("list_trades", kind=kind)) |
