Fixed a bug with editing services / pitstops

The event that was edited should not limit the dates and
odometers for the update.
This commit is contained in:
2018-08-17 07:15:27 +02:00
parent 1d767d65a6
commit 6497d4677f
5 changed files with 24 additions and 41 deletions

View File

@@ -14,16 +14,12 @@ class EditPitstopForm(FlaskForm):
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
submit = SubmitField(label='Update it!')
last_pitstop = None
same_odometer_allowed = True
pitstops = []
def set_pitstops(self, pitstops):
self.pitstops = pitstops
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_consumable(self, consumable):
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
@@ -44,6 +40,7 @@ class EditPitstopForm(FlaskForm):
}
return messages
class CreatePitstopForm(FlaskForm):
date = DateField('Date of Pitstop')
odometer = IntegerField('Odometer (km)', validators=[odometer_date_check])

View File

@@ -43,33 +43,33 @@ class DeleteServiceForm(FlaskForm):
class EditServiceForm(FlaskForm):
date = DateField('Date of Service', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
date = DateField('Date of Service')
odometer = IntegerField('Odometer (km)', validators=[edit_odometer_date_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
description = TextAreaField('Description', validators=[Length(1, 4096)])
submit = SubmitField(label='Do it!')
last_pitstop = None
same_odometer_allowed = True
pitstops = []
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_pitstops(self, pitstops):
self.pitstops = pitstops
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
else:
self.date.default = date.today()
if self.odometer.data:
self.odometer.default = self.odometer.data
else:
self.odometer.default = self.last_pitstop.odometer
if self.costs.data:
self.costs.default = self.costs.data
else:
self.costs.default = 0
if self.description.data:
self.description.default = self.description.data
def get_hint_messages(self):
messages = {
'litres': 'Litres must be higher than 0.01 L.',
'costs': 'Costs must be higher than 0.01 €.'
}
return messages