chellow 1729081025.0.0__py3-none-any.whl → 1729269304.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chellow might be problematic. Click here for more details.
- chellow/e/bill_parsers/engie_export_xlsx.py +167 -0
- chellow/templates/users.html +0 -8
- {chellow-1729081025.0.0.dist-info → chellow-1729269304.0.0.dist-info}/METADATA +1 -1
- {chellow-1729081025.0.0.dist-info → chellow-1729269304.0.0.dist-info}/RECORD +5 -4
- {chellow-1729081025.0.0.dist-info → chellow-1729269304.0.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from datetime import datetime as Datetime
|
|
2
|
+
from decimal import Decimal, InvalidOperation
|
|
3
|
+
|
|
4
|
+
from dateutil.relativedelta import relativedelta
|
|
5
|
+
|
|
6
|
+
from openpyxl import load_workbook
|
|
7
|
+
|
|
8
|
+
from werkzeug.exceptions import BadRequest
|
|
9
|
+
|
|
10
|
+
from chellow.utils import HH, parse_mpan_core, to_ct, to_utc
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_cell(sheet, col, row):
|
|
14
|
+
try:
|
|
15
|
+
coordinates = f"{col}{row}"
|
|
16
|
+
return sheet[coordinates]
|
|
17
|
+
except IndexError:
|
|
18
|
+
raise BadRequest(f"Can't find the cell {coordinates} on sheet {sheet}.")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_date_ct(sheet, col, row):
|
|
22
|
+
date_str = get_str(sheet, col, row)
|
|
23
|
+
return to_ct(Datetime.strptime(date_str, "%d/%m/%Y"))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def get_str(sheet, col, row):
|
|
27
|
+
return get_cell(sheet, col, row).value.strip()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_dec(sheet, col, row):
|
|
31
|
+
cell = get_cell(sheet, col, row)
|
|
32
|
+
try:
|
|
33
|
+
return Decimal(str(cell.value))
|
|
34
|
+
except InvalidOperation as e:
|
|
35
|
+
raise BadRequest(f"Problem parsing the number at {cell.coordinate}. {e}")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_int(sheet, col, row):
|
|
39
|
+
return int(get_cell(sheet, col, row).value)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
ELEM_LOOKUP = {
|
|
43
|
+
"Admin Fee": {
|
|
44
|
+
"gbp": "admin-gbp",
|
|
45
|
+
"units": None,
|
|
46
|
+
"rate": None,
|
|
47
|
+
},
|
|
48
|
+
"VAT": None,
|
|
49
|
+
"GDUOS Charges": {
|
|
50
|
+
"gbp": "duos-gbp",
|
|
51
|
+
"units": None,
|
|
52
|
+
"rate": None,
|
|
53
|
+
},
|
|
54
|
+
"Power Generation": {
|
|
55
|
+
"gbp": "ssp-gbp",
|
|
56
|
+
"units": "ssp-kwh",
|
|
57
|
+
"rate": "ssp-rate",
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _make_raw_bills(book):
|
|
63
|
+
bills = {}
|
|
64
|
+
mpan_lookup = {}
|
|
65
|
+
sheet = book.worksheets[0]
|
|
66
|
+
for row in range(2, len(sheet["A"]) + 1):
|
|
67
|
+
val = get_cell(sheet, "A", row).value
|
|
68
|
+
if val is None or val == "":
|
|
69
|
+
break
|
|
70
|
+
|
|
71
|
+
description = get_str(sheet, "T", row)
|
|
72
|
+
desc_parts = [d.strip() for d in description.split("-")]
|
|
73
|
+
if len(desc_parts) > 1:
|
|
74
|
+
start_date_ct = to_ct(Datetime.strptime(desc_parts[1], "%b %y"))
|
|
75
|
+
finish_date_ct = start_date_ct + relativedelta(months=1) - HH
|
|
76
|
+
else:
|
|
77
|
+
start_date_ct = get_date_ct(sheet, "M", row)
|
|
78
|
+
finish_date_ct = get_date_ct(sheet, "N", row) + relativedelta(
|
|
79
|
+
hours=23, minutes=30
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
desc_elem = desc_parts[0]
|
|
83
|
+
start_date = to_utc(start_date_ct)
|
|
84
|
+
finish_date = to_utc(finish_date_ct)
|
|
85
|
+
reference = get_str(sheet, "G", row)
|
|
86
|
+
issue_date = to_utc(get_date_ct(sheet, "I", row))
|
|
87
|
+
|
|
88
|
+
bill_key = reference, start_date
|
|
89
|
+
try:
|
|
90
|
+
bill = bills[bill_key]
|
|
91
|
+
except KeyError:
|
|
92
|
+
bill = bills[bill_key] = {
|
|
93
|
+
"bill_type_code": "N",
|
|
94
|
+
"kwh": Decimal(0),
|
|
95
|
+
"vat": Decimal("0.00"),
|
|
96
|
+
"net": Decimal("0.00"),
|
|
97
|
+
"gross": Decimal("0.00"),
|
|
98
|
+
"reads": [],
|
|
99
|
+
"breakdown": {},
|
|
100
|
+
"issue_date": issue_date,
|
|
101
|
+
"start_date": start_date,
|
|
102
|
+
"finish_date": finish_date,
|
|
103
|
+
"reference": reference,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
net = round(get_dec(sheet, "V", row), 2)
|
|
107
|
+
vat = round(get_dec(sheet, "W", row), 2)
|
|
108
|
+
gross = round(get_dec(sheet, "X", row), 2)
|
|
109
|
+
bill["net"] += net
|
|
110
|
+
bill["vat"] += vat
|
|
111
|
+
bill["gross"] += gross
|
|
112
|
+
|
|
113
|
+
mpan_core_str = get_str(sheet, "E", row)
|
|
114
|
+
if len(mpan_core_str) > 0:
|
|
115
|
+
mpan_lookup[reference] = parse_mpan_core(mpan_core_str)
|
|
116
|
+
|
|
117
|
+
mpan_core = mpan_lookup[reference]
|
|
118
|
+
|
|
119
|
+
bill["mpan_core"] = mpan_core
|
|
120
|
+
bill["account"] = mpan_core
|
|
121
|
+
|
|
122
|
+
titles = ELEM_LOOKUP[desc_elem]
|
|
123
|
+
if titles is None:
|
|
124
|
+
continue
|
|
125
|
+
|
|
126
|
+
breakdown = bill["breakdown"]
|
|
127
|
+
breakdown[titles["gbp"]] = net
|
|
128
|
+
|
|
129
|
+
units_title = titles["units"]
|
|
130
|
+
rate_title = titles["rate"]
|
|
131
|
+
units = get_dec(sheet, "P", row)
|
|
132
|
+
rate = get_dec(sheet, "U", row) / Decimal(1000)
|
|
133
|
+
|
|
134
|
+
if units_title is not None:
|
|
135
|
+
breakdown[units_title] = units
|
|
136
|
+
if rate_title is not None:
|
|
137
|
+
breakdown[rate_title] = [rate]
|
|
138
|
+
return bills.values()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class Parser:
|
|
142
|
+
def __init__(self, f):
|
|
143
|
+
self.book = load_workbook(f, data_only=True)
|
|
144
|
+
|
|
145
|
+
self.last_line = None
|
|
146
|
+
self._line_number = None
|
|
147
|
+
self._title_line = None
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def line_number(self):
|
|
151
|
+
return None if self._line_number is None else self._line_number + 1
|
|
152
|
+
|
|
153
|
+
def _set_last_line(self, i, line):
|
|
154
|
+
self._line_number = i
|
|
155
|
+
self.last_line = line
|
|
156
|
+
if i == 0:
|
|
157
|
+
self._title_line = line
|
|
158
|
+
return line
|
|
159
|
+
|
|
160
|
+
def make_raw_bills(self):
|
|
161
|
+
row = bills = None
|
|
162
|
+
try:
|
|
163
|
+
bills = _make_raw_bills(self.book)
|
|
164
|
+
except BadRequest as e:
|
|
165
|
+
raise BadRequest(f"Row number: {row} {e.description}")
|
|
166
|
+
|
|
167
|
+
return bills
|
chellow/templates/users.html
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: chellow
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1729269304.0.0
|
|
4
4
|
Summary: Web Application for checking UK energy bills.
|
|
5
5
|
Project-URL: Homepage, https://github.com/WessexWater/chellow
|
|
6
6
|
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
@@ -49,6 +49,7 @@ chellow/e/bill_parsers/bgb_edi.py,sha256=GuwHeYbAGk7BVg5n19FcTANFDyKI-y0z3f9niQa
|
|
|
49
49
|
chellow/e/bill_parsers/csv.py,sha256=U5zcIaZ6B5QTTpFDAcBnk4G2r8B3j5kJhDPL4AJNkEk,5640
|
|
50
50
|
chellow/e/bill_parsers/edf_export_xlsx.py,sha256=t-M9-dGNWXu3VDI1DbS5Ez1oHW33oopJryNgMTvTjys,6307
|
|
51
51
|
chellow/e/bill_parsers/engie_edi.py,sha256=CTobTskDjzdcqqf_qk2ukDSaTLrVpGZMM0sYlwehog4,14985
|
|
52
|
+
chellow/e/bill_parsers/engie_export_xlsx.py,sha256=oZO0qHdDlOxjJ6J5Ate82CkAoX4bxed1EJyUKHxBcpk,4690
|
|
52
53
|
chellow/e/bill_parsers/engie_xls.py,sha256=jrut2heH_ZWmSjcn7celOydZS9Y49GfpYjDk_EKwamI,14453
|
|
53
54
|
chellow/e/bill_parsers/engie_xlsx.py,sha256=4Hu3ls1uNMH7vjDHgcP6QARlGlvb616CqG3xZVjAKWo,16888
|
|
54
55
|
chellow/e/bill_parsers/gdf_csv.py,sha256=ZfK3Oc6oP28p_P9DIevLNB_zW2WLcEJ3Lvb1gL310YU,7382
|
|
@@ -157,7 +158,7 @@ chellow/templates/system.html,sha256=PP8MN8mieil3AwLS1WlQBcgbl0J61bksN-Cy4toYNqo
|
|
|
157
158
|
chellow/templates/tester.html,sha256=4DYrtcnFY0y6o3K6_tSmFpPlCRngZj1zo8nJ1NI4pk8,623
|
|
158
159
|
chellow/templates/user.html,sha256=bv1AuqnU_GFELaIbDaXSZ3FK6XJaM8so5fOkE8pVpPY,2480
|
|
159
160
|
chellow/templates/user_roles.html,sha256=Pfjr4uApEmJl8t9s0qJTxigQcAVYw7gpV_ECE8c0Cto,399
|
|
160
|
-
chellow/templates/users.html,sha256=
|
|
161
|
+
chellow/templates/users.html,sha256=8jZTeMlV0Bg5FhLJrIVhsMggQUnd9ipc1dw6-SXdVP8,1601
|
|
161
162
|
chellow/templates/e/asset_comparison.html,sha256=QyN3WMw8YoFaSWUvD2NOnRLdLdB3Kv6m3t8Id8Mb6_A,678
|
|
162
163
|
chellow/templates/e/channel.html,sha256=R5fhdsHvhB7k57Rw_gviUQ7_EXBGwP05E691V1BUNSQ,2056
|
|
163
164
|
chellow/templates/e/channel_add.html,sha256=szwQJBHx2kAoSFomXDHD0N_7PSd4drqOoAWhM-jvSqM,1676
|
|
@@ -369,6 +370,6 @@ chellow/templates/g/supply_note_edit.html,sha256=b8mB6_ucBwoljp03iy6AgVaZUhGw3-1
|
|
|
369
370
|
chellow/templates/g/supply_notes.html,sha256=6epNmZ3NKdXZz27fvmRUGeffg_oc1kmwuBeyRzQe3Rg,854
|
|
370
371
|
chellow/templates/g/unit.html,sha256=KouNVU0-i84afANkLQ_heJ0uDfJ9H5A05PuLqb8iCN8,438
|
|
371
372
|
chellow/templates/g/units.html,sha256=p5Nd-lAIboKPEOO6N451hx1bcKxMg4BDODnZ-43MmJc,441
|
|
372
|
-
chellow-
|
|
373
|
-
chellow-
|
|
374
|
-
chellow-
|
|
373
|
+
chellow-1729269304.0.0.dist-info/METADATA,sha256=OwkMhByEZZ_kZ86oUHDEOo73f69mk8jiX9KoFziS20M,12204
|
|
374
|
+
chellow-1729269304.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
375
|
+
chellow-1729269304.0.0.dist-info/RECORD,,
|
|
File without changes
|