Skip to content

Commit

Permalink
Haven EDI TPRS: Ignore kwh based on description
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Aug 31, 2023
1 parent e36d6d2 commit 7d7d9ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 57 deletions.
32 changes: 20 additions & 12 deletions chellow/e/bill_parsers/haven_edi_tprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def _process_CCD1(elements, headers):
pres_read_date = to_finish_date(prdt[0])
prev_read_date = to_finish_date(pvdt[0])

tcod = elements["TCOD"]
if tcod[0] == "EBRSD":
return
tmod = elements["TMOD"]
mtnr = elements["MTNR"]
mloc = elements["MLOC"]
Expand Down Expand Up @@ -204,6 +201,8 @@ def _decimal(elements, element_name):
def _process_CCD3(elements, headers):
breakdown = headers["breakdown"]

tcod = elements["TCOD"]
tcod0 = tcod[1]
tmod = elements["TMOD"]
tmod0 = tmod[0]
ignore_rate = ignore_kwh = False
Expand All @@ -222,7 +221,16 @@ def _process_CCD3(elements, headers):
prefix = "ebrs"
ignore_rate = ignore_kwh = True
else:
prefix = tmod0
if tcod0 == "Energy and Trade Intensive Industries":
prefix = "ebrs"
ignore_rate = ignore_kwh = True
elif tcod0 in (
"Energy Bill Discount Scheme",
"Energy Bill Relief Scheme Discount",
):
prefix = "ebrs"
else:
prefix = tmod0

if not ignore_kwh and "NUCT" in elements and len(elements["NUCT"][0]) > 0:
kwh = _decimal(elements, "NUCT") / Decimal("1000")
Expand Down Expand Up @@ -274,14 +282,14 @@ def _process_MTR(elements, headers):
if r["pres_type_code"] == "C":
r["pres_type_code"] = "E"

dup_reads = set()
new_reads = []
for r in reads:
k = tuple(v for n, v in sorted(r.items()))
if k in dup_reads:
continue
dup_reads.add(k)
new_reads.append(r)
dup_reads = set()
new_reads = []
for r in reads:
k = tuple(v for n, v in sorted(r.items()))
if k in dup_reads:
continue
dup_reads.add(k)
new_reads.append(r)

raw_bill = {
"bill_type_code": headers["bill_type_code"],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ setenv =
commands =
black --check .
flake8 .
pytest --exitfirst -W error -W ignore::DeprecationWarning test/test_models.py
pytest --exitfirst -W error -W ignore::DeprecationWarning
echo PGPORT is {env:PGPORT:unset}
echo PGUSER is {env:PGUSER:unset}
echo Test database is {env:PGDATABASE:unset} on {env:PGHOST:unset}
Expand Down
45 changes: 1 addition & 44 deletions test/e/bill_parsers/test_bill_parser_haven_edi_tprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,33 +270,10 @@ def test_process_CCD3(mocker):
assert headers == expected_headers


def test_process_CCD3_ebrs(mocker):
elements = {
"CCDE": ["3", "", "NRG"],
"TMOD": ["823408"],
"CPPU": ["028381"],
"CTOT": ["47119"],
"NUCT": ["4127137"],
}

headers = {"kwh": Decimal("0"), "breakdown": defaultdict(int, {})}

_process_CCD3(elements, headers)

expected_headers = {
"kwh": Decimal("0"),
"breakdown": {
"ebrs-gbp": Decimal("471.19"),
"ebrs-kwh": Decimal("4127.137"),
"ebrs-rate": {Decimal("0.28381")},
},
}
assert headers == expected_headers


def test_process_CCD3_ebrs_kwh(mocker):
elements = {
"CCDE": ["3", "", "NRG"],
"TCOD": ["R10001", "Day"],
"TMOD": ["823408"],
"NUCT": ["4127137"],
}
Expand Down Expand Up @@ -358,26 +335,6 @@ def test_process_CCD_1(mocker):
assert headers == expected_headers


def test_process_CCD1_ebrs(mocker):
elements = {
"PRDT": ["200301"],
"PVDT": ["200331"],
"TCOD": ["EBRSD", "Energy Bill Relief Scheme Discount"],
"TMOD": ["453043"],
"MTNR": ["hgl"],
"MLOC": ["2275834732592"],
"PRRD": ["0", "00", "1", "00"],
"ADJF": ["", "1"],
}

headers = {}

_process_CCD1(elements, headers)

expected_headers = {}
assert headers == expected_headers


def test_process_VAT(mocker):
elements = {"UVLA": ["600"], "UVTT": ["150"], "UCSI": ["850"], "VATP": ["20000"]}
headers = {
Expand Down

0 comments on commit 7d7d9ad

Please sign in to comment.