Make transaction.meter_end required and force tz utc for all datetimes
This commit is contained in:
parent
4272f2878e
commit
8e42205301
8 changed files with 32 additions and 10 deletions
|
@ -21,19 +21,23 @@ async def create_transaction(
|
|||
with SessionLocal() as db:
|
||||
chargepoint = db.query(ChargePoint).filter(ChargePoint.identity == chargepoint_identity).first()
|
||||
meter_start=0
|
||||
meter_end=0
|
||||
if "meter_value" in transaction_data.keys():
|
||||
for meter_value_entry in transaction_data['meter_value']:
|
||||
for sampled_value in meter_value_entry['sampled_value']:
|
||||
if "measurand" in sampled_value.keys():
|
||||
if sampled_value['measurand'] == str(Measurand.ENERGY_ACTIVE_IMPORT_REGISTER):
|
||||
meter_start = sampled_value['value']
|
||||
meter_end = sampled_value['value']
|
||||
else:
|
||||
meter_start = sampled_value['value']
|
||||
meter_end = sampled_value['value']
|
||||
transaction = Transaction(
|
||||
id=transaction_info["transaction_id"],
|
||||
status=TransactionStatus.ONGOING,
|
||||
started_at=timestamp,
|
||||
meter_start=meter_start,
|
||||
meter_end=meter_end,
|
||||
price=chargepoint.price,
|
||||
chargepoint_id=chargepoint.id,
|
||||
user_id=user_id
|
||||
|
@ -55,6 +59,12 @@ async def update_transaction(
|
|||
transaction_id=transaction.id,
|
||||
meter_value_data=meter_value_entry
|
||||
)
|
||||
# Update current meter_end value
|
||||
for sampled_value in meter_value_entry['sampled_value']:
|
||||
if "measurand" in sampled_value.keys():
|
||||
if sampled_value['measurand'] == str(Measurand.ENERGY_ACTIVE_IMPORT_REGISTER):
|
||||
transaction.meter_end = sampled_value['value']
|
||||
db.commit()
|
||||
|
||||
async def end_transaction(
|
||||
transaction_id: str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue