diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index 070e3de..85b7afb 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -71,11 +71,6 @@ def user_registered_sighandler(app, user, confirm_token): @app.before_first_request def before_first_request(): db.create_all() - print(""" - ========================= - TEST - ======================== - """) user_datastore.find_or_create_role(name='admin', description='Role for administrators') user_datastore.find_or_create_role(name='user', description='Role for all users.') db.session.commit() diff --git a/app/rollerverbrauch/templates/pitstops.html b/app/rollerverbrauch/templates/pitstops.html index 88ca8a4..25c7283 100644 --- a/app/rollerverbrauch/templates/pitstops.html +++ b/app/rollerverbrauch/templates/pitstops.html @@ -34,7 +34,13 @@ Costs - {{pitstop.costs}} € + + {% if pitstop.costs %} + {{pitstop.costs}} € + {% else %} + -- € + {% endif %} + {% if loop.first %} diff --git a/app/rollerverbrauch/templates/statistics.html b/app/rollerverbrauch/templates/statistics.html index f559fec..0f1ecd3 100644 --- a/app/rollerverbrauch/templates/statistics.html +++ b/app/rollerverbrauch/templates/statistics.html @@ -162,11 +162,11 @@ ) }} - {{ tab_script('vehicle_' + vehicle.id + '_' + consumable.id + '_tabs') }} + {{ tab_script('vehicle_' + vehicle.id|string + '_' + consumable.id|string + '_tabs') }} {% endfor %} - {{ tab_script('vehicle_' + vehicle.id + '_tabs') }} + {{ tab_script('vehicle_' + vehicle.id|string + '_tabs') }} {% endfor %} diff --git a/app/rollerverbrauch/tools.py b/app/rollerverbrauch/tools.py index aef46d5..00d2862 100644 --- a/app/rollerverbrauch/tools.py +++ b/app/rollerverbrauch/tools.py @@ -1,6 +1,5 @@ import logging from datetime import date -from dis import code_info from rollerverbrauch.entities import \ Pitstop @@ -26,7 +25,6 @@ class ConsumableStats: self.overall_amount += pitstop.amount self.amounts.append(StatsEvent(pitstop.date, pitstop.amount)) self.average_amount_fuelled = self.overall_amount / pitstop_count - print(self.amounts) if pitstop_count > 1: overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer self.average_distance = overall_distance / (pitstop_count - 1) @@ -57,7 +55,8 @@ class VehicleStats: if pitstop_count > 0: for pitstop in vehicle.pitstops: self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer)) - self.overall_costs += pitstop.costs + if pitstop.costs is not None: + self.overall_costs += pitstop.costs if pitstop_count > 1: self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer diff --git a/database_upgrades/upgrade_cathrine_to_danielle.sql b/database_upgrades/upgrade_cathrine_to_danielle.sql new file mode 100644 index 0000000..c221633 --- /dev/null +++ b/database_upgrades/upgrade_cathrine_to_danielle.sql @@ -0,0 +1,28 @@ +CREATE TABLE IF NOT EXISTS `consumable` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `unit` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1; + +INSERT INTO `consumable`(`id`, `name`, `unit`) VALUES (1, 'Super E5', 'l'); + +CREATE TABLE IF NOT EXISTS `vehicles_consumables` ( + `vehicle_id` int(11) DEFAULT NULL, + `consumable_id` int(11) DEFAULT NULL, + KEY `vehicle_id` (`vehicle_id`), + KEY `consumable_id` (`consumable_id`), + CONSTRAINT `vehicles_consumables_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`), + CONSTRAINT `vehicles_consumables_ibfk_2` FOREIGN KEY (`consumable_id`) REFERENCES `consumable` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +ALTER TABLE `pitstop` ADD COLUMN `costs` decimal(5,2) DEFAULT NULL; + +ALTER TABLE `pitstop` CHANGE `litres` `amount`; + +ALTER TABLE `pitstop` ADD COLUMN `consumable_id` int(11); +ALTER TABLE `pitstop` ADD FOREIGN KEY (`consumable_id`) REFERENCES `consumable` (`id`); +UPDATE `pitstop` set `consumable_id`=1; + +INSERT INTO `vehicles_consumables`(`vehicle_id`, `consumable_id`) SELECT `id`, 1 FROM `vehicle`; \ No newline at end of file