HassamGani commited on
Generator: notices worked out on a seat gap (Acct.base), for families that charge or credit the difference
Browse files- reorgbench/gen/build.py +10 -4
- reorgbench/gen/world.py +6 -2
reorgbench/gen/build.py
CHANGED
|
@@ -197,9 +197,15 @@ class PhaseBuilder:
|
|
| 197 |
ref = "{" + g.units["window"].fact + "}"
|
| 198 |
hi = "{" + g.units["window"].fact + "_hi}"
|
| 199 |
return lambda c: hi if n.hi(g.accts[c].seats) else ref
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
# an amount summed from invoice lines comes from finance, which reads them (see refunds)
|
| 201 |
-
return lambda c: "{" + f"n{n.ver}_{g.index(c)}" + "}" if g.accts[c].charged else
|
| 202 |
-
f"n{n.ver}_{g.index(c)}", c, n.rate_hi if n.hi(g.accts[c].seats) else n.rate)
|
| 203 |
|
| 204 |
def refunds(self, label: str, r: Refund, topup: bool) -> list[Step]:
|
| 205 |
g, out = self.g, []
|
|
@@ -360,7 +366,7 @@ def late_steps(g: Gen, b: PhaseBuilder) -> None:
|
|
| 360 |
if nt.rate is None:
|
| 361 |
val = b.notify_value(nt)(c)
|
| 362 |
else:
|
| 363 |
-
val = nt.value(a.
|
| 364 |
val = int(val) if float(val).is_integer() else val
|
| 365 |
sup = g.labels("support")[0]
|
| 366 |
b.work(sup, [Step("tickets.read", {"ticket_id": a.ticket}),
|
|
@@ -618,7 +624,7 @@ def negatives(g: Gen, cancel_id: str | None) -> list[Checkpoint]:
|
|
| 618 |
out.append(Checkpoint("no_late_excluded_change", "no out-of-scope record changed after the cancel could "
|
| 619 |
"be acted on", no_late_move, negative=True))
|
| 620 |
nt: Notify = u["told"]
|
| 621 |
-
tickets = {acc[c].ticket: [nt.value(acc[c].
|
| 622 |
owner = {acc[c].ticket: c for c in x}
|
| 623 |
|
| 624 |
def consistent(w, v):
|
|
|
|
| 197 |
ref = "{" + g.units["window"].fact + "}"
|
| 198 |
hi = "{" + g.units["window"].fact + "_hi}"
|
| 199 |
return lambda c: hi if n.hi(g.accts[c].seats) else ref
|
| 200 |
+
def need(c: str) -> str:
|
| 201 |
+
a, name = g.accts[c], f"n{n.ver}_{g.index(c)}"
|
| 202 |
+
rate = n.rate_hi if n.hi(a.qty) else n.rate
|
| 203 |
+
if a.base is None:
|
| 204 |
+
return self.need_seats(name, c, rate)
|
| 205 |
+
sign = 1 if a.seats >= a.base else -1 # the record's seats above or below the base
|
| 206 |
+
return self.need_seats(name, c, sign * rate, -sign * rate * a.base)
|
| 207 |
# an amount summed from invoice lines comes from finance, which reads them (see refunds)
|
| 208 |
+
return lambda c: "{" + f"n{n.ver}_{g.index(c)}" + "}" if g.accts[c].charged else need(c)
|
|
|
|
| 209 |
|
| 210 |
def refunds(self, label: str, r: Refund, topup: bool) -> list[Step]:
|
| 211 |
g, out = self.g, []
|
|
|
|
| 366 |
if nt.rate is None:
|
| 367 |
val = b.notify_value(nt)(c)
|
| 368 |
else:
|
| 369 |
+
val = nt.value(a.qty)
|
| 370 |
val = int(val) if float(val).is_integer() else val
|
| 371 |
sup = g.labels("support")[0]
|
| 372 |
b.work(sup, [Step("tickets.read", {"ticket_id": a.ticket}),
|
|
|
|
| 624 |
out.append(Checkpoint("no_late_excluded_change", "no out-of-scope record changed after the cancel could "
|
| 625 |
"be acted on", no_late_move, negative=True))
|
| 626 |
nt: Notify = u["told"]
|
| 627 |
+
tickets = {acc[c].ticket: [nt.value(acc[c].qty), *nt.old_values(acc[c].qty)] for c in x}
|
| 628 |
owner = {acc[c].ticket: c for c in x}
|
| 629 |
|
| 630 |
def consistent(w, v):
|
reorgbench/gen/world.py
CHANGED
|
@@ -69,6 +69,8 @@ class Acct:
|
|
| 69 |
billed: int | None = None # seats billing charges for, where that differs from the record
|
| 70 |
charged: dict[str, int] = field(default_factory=dict) # seat lines on the invoice by kind, where it has lines
|
| 71 |
tags: set[str] = field(default_factory=set) # "closed", "namesake", "excluded", ...
|
|
|
|
|
|
|
| 72 |
|
| 73 |
@property
|
| 74 |
def seats(self) -> int:
|
|
@@ -77,8 +79,10 @@ class Acct:
|
|
| 77 |
@property
|
| 78 |
def qty(self) -> int:
|
| 79 |
"""Seats a per-seat refund or notice is worked out on: the overcharged invoice lines where there are any,
|
| 80 |
-
else the record."""
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
@property
|
| 84 |
def bseats(self) -> int:
|
|
|
|
| 69 |
billed: int | None = None # seats billing charges for, where that differs from the record
|
| 70 |
charged: dict[str, int] = field(default_factory=dict) # seat lines on the invoice by kind, where it has lines
|
| 71 |
tags: set[str] = field(default_factory=set) # "closed", "namesake", "excluded", ...
|
| 72 |
+
base: int | None = None # a seat count the notice is worked out against: it is on the record's
|
| 73 |
+
# seats above or below it, not on all of them
|
| 74 |
|
| 75 |
@property
|
| 76 |
def seats(self) -> int:
|
|
|
|
| 79 |
@property
|
| 80 |
def qty(self) -> int:
|
| 81 |
"""Seats a per-seat refund or notice is worked out on: the overcharged invoice lines where there are any,
|
| 82 |
+
else the record (the gap to base, where there is one)."""
|
| 83 |
+
if self.charged:
|
| 84 |
+
return self.charged["seats"] + self.charged.get("added", 0)
|
| 85 |
+
return abs(self.seats - self.base) if self.base is not None else self.seats
|
| 86 |
|
| 87 |
@property
|
| 88 |
def bseats(self) -> int:
|