|
@@ 480-506 (lines=27) @@
|
| 477 |
|
(id_, block['start_amount'], block['end_amount'], block['price'])) |
| 478 |
|
cnx.commit() |
| 479 |
|
elif tariff_type == 'timeofuse': |
| 480 |
|
if 'timeofuse' not in new_values['data'].keys() or new_values['data']['timeofuse'] is None: |
| 481 |
|
cursor.close() |
| 482 |
|
cnx.disconnect() |
| 483 |
|
raise falcon.HTTPError(falcon.HTTP_400, |
| 484 |
|
title='API.BAD_REQUEST', |
| 485 |
|
description='API.INVALID_TARIFF_TIME_OF_USE_PRICING') |
| 486 |
|
else: |
| 487 |
|
# remove all (possible) exist prices |
| 488 |
|
cursor.execute(" DELETE FROM tbl_tariffs_blocks " |
| 489 |
|
" WHERE tariff_id = %s ", |
| 490 |
|
(id_,)) |
| 491 |
|
|
| 492 |
|
cursor.execute(" DELETE FROM tbl_tariffs_timeofuses " |
| 493 |
|
" WHERE tariff_id = %s ", |
| 494 |
|
(id_,)) |
| 495 |
|
cnx.commit() |
| 496 |
|
|
| 497 |
|
for timeofuse in new_values['data']['timeofuse']: |
| 498 |
|
add_timeofuse = (" INSERT INTO tbl_tariffs_timeofuses " |
| 499 |
|
" (tariff_id, start_time_of_day, end_time_of_day, peak_type, price) " |
| 500 |
|
" VALUES (%s, %s, %s, %s, %s) ") |
| 501 |
|
cursor.execute(add_timeofuse, (id_, |
| 502 |
|
timeofuse['start_time_of_day'], |
| 503 |
|
timeofuse['end_time_of_day'], |
| 504 |
|
timeofuse['peak_type'], |
| 505 |
|
timeofuse['price'])) |
| 506 |
|
cnx.commit() |
| 507 |
|
|
| 508 |
|
cursor.close() |
| 509 |
|
cnx.disconnect() |
|
@@ 456-478 (lines=23) @@
|
| 453 |
|
|
| 454 |
|
# update prices of the tariff |
| 455 |
|
if tariff_type == 'block': |
| 456 |
|
if 'block' not in new_values['data'].keys() or new_values['data']['block'] is None: |
| 457 |
|
cursor.close() |
| 458 |
|
cnx.disconnect() |
| 459 |
|
raise falcon.HTTPError(falcon.HTTP_400, |
| 460 |
|
title='API.BAD_REQUEST', |
| 461 |
|
description='API.INVALID_TARIFF_BLOCK_PRICING') |
| 462 |
|
else: |
| 463 |
|
# remove all (possible) exist prices |
| 464 |
|
cursor.execute(" DELETE FROM tbl_tariffs_blocks " |
| 465 |
|
" WHERE tariff_id = %s ", |
| 466 |
|
(id_,)) |
| 467 |
|
|
| 468 |
|
cursor.execute(" DELETE FROM tbl_tariffs_timeofuses " |
| 469 |
|
" WHERE tariff_id = %s ", |
| 470 |
|
(id_,)) |
| 471 |
|
cnx.commit() |
| 472 |
|
|
| 473 |
|
for block in new_values['data']['block']: |
| 474 |
|
cursor.execute(" INSERT INTO tbl_tariffs_blocks " |
| 475 |
|
" (tariff_id, start_amount, end_amount, price) " |
| 476 |
|
" VALUES (%s, %s, %s, %s) ", |
| 477 |
|
(id_, block['start_amount'], block['end_amount'], block['price'])) |
| 478 |
|
cnx.commit() |
| 479 |
|
elif tariff_type == 'timeofuse': |
| 480 |
|
if 'timeofuse' not in new_values['data'].keys() or new_values['data']['timeofuse'] is None: |
| 481 |
|
cursor.close() |