diff --git a/chellow/e/bill_parsers/haven_edi_tprs.py b/chellow/e/bill_parsers/haven_edi_tprs.py index 60df34be4..5bd4f65f4 100644 --- a/chellow/e/bill_parsers/haven_edi_tprs.py +++ b/chellow/e/bill_parsers/haven_edi_tprs.py @@ -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"] @@ -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 @@ -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") @@ -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"], diff --git a/pyproject.toml b/pyproject.toml index 4ed08d99e..5f30db896 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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} diff --git a/test/e/bill_parsers/test_bill_parser_haven_edi_tprs.py b/test/e/bill_parsers/test_bill_parser_haven_edi_tprs.py index 4643952d1..ac5a5c6c0 100644 --- a/test/e/bill_parsers/test_bill_parser_haven_edi_tprs.py +++ b/test/e/bill_parsers/test_bill_parser_haven_edi_tprs.py @@ -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"], } @@ -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 = {