- ID
- 0036759b-5781-439e-9afc-ecfc704042cc
2023-08-17
DONE Policies not exporting
#+begin_src python
supposed_to_exist = ['TOR7RTXU1C', 'TOSDZZ0YCO', 'TOGR7REIUP', 'TORZHTZF3E', 'TOXEB60BOZ', 'TOYD769K5P', 'TOUN2W4CUT', 'TO2348NQG5', ]
#+end_src
DONE Figure out how to address NY loss history
DONE Error in renters refunds
#+begin_src python
from pprint import pprint
from platform_core.apps.core_protections.models import BillingScheduleItem, Policy
from platform_core.apps.core_protections.utils.calculator_utils import (
calculate_prorated_breakdown,
get_line_item_breakdown,
)
from platform_core.apps.core_protections.verticals.manager import VerticalsManager
policy = Policy.objects.get(id="caa762c5-893c-4eab-95cf-2cdd533081e8")
canceled_at = policy.canceled_at
vm = VerticalsManager.from_policy_id(policy.id)
pm = vm.policy_manager(policy=policy)
cancel_cls = pm.cancel_policy_cls(policy=policy, now=canceled_at, process_refund=True)
si_qs = BillingScheduleItem.objects.filter(
policy=policy,
processed_at__isnull=False,
ends_at__gt=canceled_at.date(),
)
si = si_qs.first()
print("Current pro-rated renters")
pprint(cancel_cls._get_prorated_breakdown(si)) # current incorrect amount
print(
"***********"
) # current calculation, uses `calculate_prorated_breakdown` underlying
print("Corrected pro-rated renters")
bills = [b for b in si.bills.all()]
minimum_premium_due = 0
cancel_cls._cancelled_in_first_month(si) # sanity check, so no different rules appoly
billing_history = next(
item
for item in policy.details.billing_history
if item.billing_cadence == policy.billing_cadence
)
line_items = billing_history.last_line_items or []
line_item_breakdowns = []
for line_item in line_items:
line_item_breakdowns.append(
get_line_item_breakdown(
line_item=line_item,
new_amount=0,
period_started_at=si.starts_at,
period_ended_at=si.ends_at,
prorated_at=canceled_at.date(),
policy_starts_at=policy.starts_at.date(),
policy_ends_at=policy.ends_at.date(),
)
)
corrected_subtotal_amount = sum([b.subtotal_amount for b in bills])
corrected_taxes_amount = sum([b.total_taxes_amount for b in bills])
pprint(
calculate_prorated_breakdown(
period_started_at=si.starts_at,
period_ended_at=si.ends_at,
prorated_at=canceled_at.date(),
minimum_premium_due=minimum_premium_due,
current_subtotal_amount=corrected_subtotal_amount,
current_taxes_amount=corrected_taxes_amount,
new_subtotal_amount=0,
new_taxes_amount=0,
line_item_breakdowns=line_item_breakdowns,
)
)
#+end_src