HassamGani commited on
Commit ·
1b52a9e
1
Parent(s): 9b9b28a
Don't read a declined stay request as a retraction; keep partial refunds from matching another invoice line
Browse files- reorgbench/gen/templates.py +7 -0
- reorgbench/gen/units.py +6 -1
- tests/test_generator.py +9 -0
- tests/test_notice_grading.py +24 -0
reorgbench/gen/templates.py
CHANGED
|
@@ -889,7 +889,14 @@ class OverchargeRefund(Template):
|
|
| 889 |
a.inv_amount = self._lines(g, a, a.row["rate_card"])
|
| 890 |
if a.prior_refund:
|
| 891 |
over = a.qty * s["rate"]
|
|
|
|
|
|
|
|
|
|
| 892 |
a.prior_refund = float(rng.randint(max(1, round(over * 0.2)), round(over * 0.6)))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 893 |
order = cohort + traps
|
| 894 |
rng.shuffle(order)
|
| 895 |
self.add_rows(g, order)
|
|
|
|
| 889 |
a.inv_amount = self._lines(g, a, a.row["rate_card"])
|
| 890 |
if a.prior_refund:
|
| 891 |
over = a.qty * s["rate"]
|
| 892 |
+
# a refund that matches some other line's amount reads as a refund of that line instead
|
| 893 |
+
taken = {d["amount"] for o, d in g.objects.items()
|
| 894 |
+
if o.startswith("ledger.charges/") and d["invoice_id"] == a.invoice}
|
| 895 |
a.prior_refund = float(rng.randint(max(1, round(over * 0.2)), round(over * 0.6)))
|
| 896 |
+
for _ in range(20):
|
| 897 |
+
if a.prior_refund not in taken:
|
| 898 |
+
break
|
| 899 |
+
a.prior_refund = float(rng.randint(max(1, round(over * 0.2)), round(over * 0.6)))
|
| 900 |
order = cohort + traps
|
| 901 |
rng.shuffle(order)
|
| 902 |
self.add_rows(g, order)
|
reorgbench/gen/units.py
CHANGED
|
@@ -297,6 +297,9 @@ _STAY = re.compile("|".join([
|
|
| 297 |
rf"\b(?:you|your(?:\s+\S+)?\s+(?:plan|region|hosting|subscription|account))\b{_AUX}\s+{_NEG}\s+"
|
| 298 |
rf"(?:be\s+|been\s+|going to\s+)?chang\w*{_BUT}",
|
| 299 |
]))
|
|
|
|
|
|
|
|
|
|
| 300 |
_NOTICE = re.compile(r"\b(?:is|are|will be|'ll be|has been|have been|being|'re|'s|was|were)\s+(?:now\s+|also\s+)?"
|
| 301 |
r"(?:moving|moved|migrated|migrating|switched|switching|transferred|refunded|credited|archived)\b|"
|
| 302 |
r"\bnew (?:monthly )?"
|
|
@@ -348,7 +351,9 @@ def _cue(c: str) -> tuple[str | None, bool]:
|
|
| 348 |
if not re.search(rf"{_NEG}\s+(?:\S+\s+)?$|\b(?:no need to|please|kindly|avoid|you (?:should|may|might|can|"
|
| 349 |
r"need to|could))\s+$", c[:m.start()]):
|
| 350 |
return "retract", bool(re.search(r"\bfig\b", m.group()))
|
| 351 |
-
|
|
|
|
|
|
|
| 352 |
|
| 353 |
|
| 354 |
def _events(texts: list[str], values: list[Any] | None):
|
|
|
|
| 297 |
rf"\b(?:you|your(?:\s+\S+)?\s+(?:plan|region|hosting|subscription|account))\b{_AUX}\s+{_NEG}\s+"
|
| 298 |
rf"(?:be\s+|been\s+|going to\s+)?chang\w*{_BUT}",
|
| 299 |
]))
|
| 300 |
+
_NO_STAY = re.compile(r"(?:\b(?:not|cannot|unable)\b|n't\b)(?:\s+(?:be|able|to|make|makes|an|any|exceptions?|allowed|"
|
| 301 |
+
r"possible|in|a|position|offer|agree|let|allow|afford|we|us|really|currently|going|for|"
|
| 302 |
+
r"this|that|one|case|accounts?|grant))*\s+(?:to\s+)?$")
|
| 303 |
_NOTICE = re.compile(r"\b(?:is|are|will be|'ll be|has been|have been|being|'re|'s|was|were)\s+(?:now\s+|also\s+)?"
|
| 304 |
r"(?:moving|moved|migrated|migrating|switched|switching|transferred|refunded|credited|archived)\b|"
|
| 305 |
r"\bnew (?:monthly )?"
|
|
|
|
| 351 |
if not re.search(rf"{_NEG}\s+(?:\S+\s+)?$|\b(?:no need to|please|kindly|avoid|you (?:should|may|might|can|"
|
| 352 |
r"need to|could))\s+$", c[:m.start()]):
|
| 353 |
return "retract", bool(re.search(r"\bfig\b", m.group()))
|
| 354 |
+
# "we can't make an exception to keep you on the current price" turns a request down, it doesn't keep them
|
| 355 |
+
stays = [m for m in _STAY.finditer(c) if not _NO_STAY.search(c[:m.start()])]
|
| 356 |
+
return ("stay", False) if stays else (None, False)
|
| 357 |
|
| 358 |
|
| 359 |
def _events(texts: list[str], values: list[Any] | None):
|
tests/test_generator.py
CHANGED
|
@@ -222,3 +222,12 @@ def test_messy_overcharge_refunds_are_summed_from_invoice_lines():
|
|
| 222 |
assert next(cp for cp in t.phases[0].checkpoints if cp.id == "refunded").check(w, None)
|
| 223 |
t2, _ = build(TEMPLATES["overcharge-refund"], 5, replace(k, messy=False)) # standard worlds have no lines
|
| 224 |
assert not any(o.startswith("ledger.charges/") for o in t2.initial_objects)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
assert next(cp for cp in t.phases[0].checkpoints if cp.id == "refunded").check(w, None)
|
| 223 |
t2, _ = build(TEMPLATES["overcharge-refund"], 5, replace(k, messy=False)) # standard worlds have no lines
|
| 224 |
assert not any(o.startswith("ledger.charges/") for o in t2.initial_objects)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def test_a_partial_refund_never_matches_another_line_on_its_invoice():
|
| 228 |
+
for t in all_tasks().values():
|
| 229 |
+
o = t.initial_objects
|
| 230 |
+
for e, d in o.items():
|
| 231 |
+
if e.startswith("ledger.entries/E-P") and d["kind"] == "refund":
|
| 232 |
+
lines = [c for k, c in o.items() if k.startswith("ledger.charges/") and c["invoice_id"] == d["invoice_id"]]
|
| 233 |
+
assert d["amount"] not in {c["amount"] for c in lines}, (t.id, e)
|
tests/test_notice_grading.py
CHANGED
|
@@ -1043,3 +1043,27 @@ def test_price_increase_taken_back(later):
|
|
| 1043 |
def test_service_credit_taken_back(later):
|
| 1044 |
tell = "Under our SLA you are owed a service credit of $56 for incident INC-7695, taken off your next invoice."
|
| 1045 |
assert told_and_not_retracted([tell], [56.0]) and not told_and_not_retracted([tell, later], [56.0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1043 |
def test_service_credit_taken_back(later):
|
| 1044 |
tell = "Under our SLA you are owed a service credit of $56 for incident INC-7695, taken off your next invoice."
|
| 1045 |
assert told_and_not_retracted([tell], [56.0]) and not told_and_not_retracted([tell, later], [56.0])
|
| 1046 |
+
|
| 1047 |
+
|
| 1048 |
+
# a declined request to stay put is not the team keeping them where they are (seen in a probe: a price notice that
|
| 1049 |
+
# also turned down a "keep my current price" request)
|
| 1050 |
+
@pytest.mark.parametrize("decline", [
|
| 1051 |
+
"Unfortunately we are not able to make an exception to keep your account on the current price, so the new price "
|
| 1052 |
+
"will apply from 1 December 2026.",
|
| 1053 |
+
"We can't keep you on your current price, I'm afraid.",
|
| 1054 |
+
"We're unable to let you stay on the old price.",
|
| 1055 |
+
"Sorry, we cannot make exceptions to keep accounts on the old pricing.",
|
| 1056 |
+
])
|
| 1057 |
+
def test_declined_stay_request_keeps_the_notice(decline):
|
| 1058 |
+
tell = "From 1 December 2026, Essentials moves to its new pricing. Your new monthly price will be $754."
|
| 1059 |
+
assert told_value([f"{tell}\n\n{decline}"], [754.0])
|
| 1060 |
+
|
| 1061 |
+
|
| 1062 |
+
@pytest.mark.parametrize("stay", [
|
| 1063 |
+
"We'll keep you on your current price for now.",
|
| 1064 |
+
"You don't need to do anything, your account stays on the current price.",
|
| 1065 |
+
"Your account manager has agreed to keep your current price.",
|
| 1066 |
+
])
|
| 1067 |
+
def test_real_stay_still_takes_the_notice_back(stay):
|
| 1068 |
+
tell = "Your new monthly price will be $754 from 1 December."
|
| 1069 |
+
assert not told_value([tell, stay], [754.0])
|