services and pitstops each now respect their data on creation
On creation, the tupels of date and odometer are checked that the service or pitstop does not violate the ordering in.
This commit is contained in:
parent
bf4bb607d5
commit
6397d050ae
|
@ -64,7 +64,7 @@ class CreatePitstopForm(FlaskForm):
|
||||||
|
|
||||||
if self.litres.data:
|
if self.litres.data:
|
||||||
self.litres.default = self.litres.data
|
self.litres.default = self.litres.data
|
||||||
elif len(self.pitstops) > 0:
|
elif len(self.pitstops) > 0 and 'amount' in self.pitstops[-1].__dict__:
|
||||||
self.litres.default = self.pitstops[-1].amount
|
self.litres.default = self.pitstops[-1].amount
|
||||||
else:
|
else:
|
||||||
self.litres.default = 0
|
self.litres.default = 0
|
||||||
|
|
|
@ -6,15 +6,15 @@ from .checks import *
|
||||||
|
|
||||||
|
|
||||||
class CreateServiceForm(FlaskForm):
|
class CreateServiceForm(FlaskForm):
|
||||||
date = DateField('Date of Service', validators=[date_check])
|
date = DateField('Date of Pitstop')
|
||||||
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
odometer = IntegerField('Odometer (km)', validators=[odometer_date_check])
|
||||||
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
|
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
|
||||||
description = TextAreaField('Description', validators=[Length(1, 4096)])
|
description = TextAreaField('Description', validators=[Length(1, 4096)])
|
||||||
submit = SubmitField(label='Do it!')
|
submit = SubmitField(label='Do it!')
|
||||||
last_pitstop = None
|
pitstops = []
|
||||||
|
|
||||||
def set_pitstop(self, last_pitstop):
|
def set_pitstops(self, pitstops):
|
||||||
self.last_pitstop = last_pitstop
|
self.pitstops = pitstops
|
||||||
|
|
||||||
def preinit_with_data(self):
|
def preinit_with_data(self):
|
||||||
if self.date.data:
|
if self.date.data:
|
||||||
|
@ -24,8 +24,10 @@ class CreateServiceForm(FlaskForm):
|
||||||
|
|
||||||
if self.odometer.data:
|
if self.odometer.data:
|
||||||
self.odometer.default = self.odometer.data
|
self.odometer.default = self.odometer.data
|
||||||
|
elif len(self.pitstops) > 0:
|
||||||
|
self.odometer.default = self.pitstops[-1].odometer
|
||||||
else:
|
else:
|
||||||
self.odometer.default = self.last_pitstop.odometer
|
self.odometer.default = 0
|
||||||
|
|
||||||
if self.costs.data:
|
if self.costs.data:
|
||||||
self.costs.default = self.costs.data
|
self.costs.default = self.costs.data
|
||||||
|
|
|
@ -64,7 +64,7 @@ def create_pit_stop_form(vid, cid):
|
||||||
|
|
||||||
data = get_event_line_for_vehicle(vehicle)
|
data = get_event_line_for_vehicle(vehicle)
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
form.set_pitstops(vehicle.pitstops)
|
form.set_pitstops(data)
|
||||||
form.same_odometer_allowed = (type(data[-1]) != Pitstop) or (data[-1].consumable.id != cid)
|
form.same_odometer_allowed = (type(data[-1]) != Pitstop) or (data[-1].consumable.id != cid)
|
||||||
else:
|
else:
|
||||||
form.set_pitstops([])
|
form.set_pitstops([])
|
||||||
|
|
|
@ -19,10 +19,10 @@ def create_service_for_vehicle(vid):
|
||||||
|
|
||||||
data = get_event_line_for_vehicle(vehicle)
|
data = get_event_line_for_vehicle(vehicle)
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
form.set_pitstop(Service(data[-1].date, data[-1].odometer, vid, 0, ''))
|
form.set_pitstops(data)
|
||||||
form.same_odometer_allowed = type(data[-1]) != Service
|
form.same_odometer_allowed = type(data[-1]) != Service
|
||||||
else:
|
else:
|
||||||
form.set_pitstop(Service(date(1970, 1, 1), 0, vid, 0, ''))
|
form.set_pitstops([])
|
||||||
form.same_odometer_allowed = True
|
form.same_odometer_allowed = True
|
||||||
|
|
||||||
form.preinit_with_data()
|
form.preinit_with_data()
|
||||||
|
|
Loading…
Reference in New Issue