Skip to content

Commit

Permalink
Fix for null gas in dsmr_stats_recalculate_prices #1449
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Sep 28, 2021
1 parent 96ebf48 commit 491e984
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions dsmr_stats/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def recalculate_prices() -> NoReturn:
print(' !!! No prices found, using zero fallback')
prices = dsmr_consumption.services.get_fallback_prices()

current_day.fixed_cost = prices.fixed_daily_cost
current_day.electricity1_cost = dsmr_consumption.services.round_decimal(
current_day.electricity1 * prices.electricity_delivered_1_price -
current_day.electricity1_returned * prices.electricity_returned_1_price
Expand All @@ -427,18 +428,15 @@ def recalculate_prices() -> NoReturn:
current_day.electricity2_returned * prices.electricity_returned_2_price
)

total_cost = current_day.electricity1_cost + current_day.electricity2_cost + current_day.fixed_cost

if current_day.gas is not None:
current_day.gas_cost = dsmr_consumption.services.round_decimal(
current_day.gas * prices.gas_price
)
total_cost += current_day.gas_cost

current_day.fixed_cost = prices.fixed_daily_cost
current_day.total_cost = dsmr_consumption.services.round_decimal(
current_day.electricity1_cost or 0 +
current_day.electricity2_cost or 0 +
current_day.gas_cost or 0 +
current_day.fixed_cost or 0
)
current_day.total_cost = dsmr_consumption.services.round_decimal(total_cost)
current_day.save()


Expand Down

0 comments on commit 491e984

Please sign in to comment.