Skip to content

Commit 61927db

Browse files
committed
Add back in support for charges to be applied to specific custom meters
1 parent 9f5bf9b commit 61927db

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tariffs/tariff.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ class Charge(odin.Resource):
147147
season = odin.ObjectAs(Season, null=True)
148148
type = odin.StringField(choices=CHARGE_TYPE_CHOICES, null=True, default='consumption',
149149
use_default_if_not_provided=True)
150+
meter = odin.StringField(null=True)
150151

151152
@odin.calculated_field
152153
def name(self):
153154
season = self.season.name if self.season else None
154155
time = self.time.name if self.time else None
155156
scheduled = 'scheduled' if self.rate_schedule else None
156-
return str(self.code) + str(self.type or '') + str(season or '') + str(time or '') + str(scheduled or '')
157+
return str(self.code or '') + str(self.type or '') + str(season or '') + str(time or '') + str(scheduled or '')
157158

158159

159160
class Times(odin.Resource):
@@ -225,14 +226,14 @@ def charge_types(self):
225226

226227
def calc_charge(self, name, row, charge, cost_items, block_accum_dict):
227228
if charge.rate:
228-
cost_items[name]['cost'] += charge.rate * float(row[charge.type])
229+
cost_items[name]['cost'] += charge.rate * float(row[charge.meter or charge.type])
229230
if charge.rate_bands:
230231
charge_time_step = float()
231232
for rate_band_index, rate_band in enumerate(charge.rate_bands):
232233
if block_accum_dict[name] > rate_band.limit:
233234
continue
234235
block_usage = max((min(
235-
(rate_band.limit - block_accum_dict[name], row[charge.type] - block_accum_dict[name])), 0.0))
236+
(rate_band.limit - block_accum_dict[name], row[charge.meter or charge.type] - block_accum_dict[name])), 0.0))
236237
charge_time_step += rate_band.rate * block_usage
237238
block_accum_dict[name] += block_usage
238239
cost_items[name]['cost'] += charge_time_step

0 commit comments

Comments
 (0)