1
0
mirror of https://github.com/fspc/workstand.git synced 2025-02-23 17:23:24 -05:00

Include available states to transition to.

This commit is contained in:
Drew Larson 2017-01-28 22:39:56 -06:00
parent 5d85579a4f
commit 1e0f1cd496
2 changed files with 11 additions and 2 deletions

View File

@ -78,8 +78,9 @@ class Bike(models.Model):
return self.stolen is False and self.cpic_searched_at is not None and self.serial_number is not None return self.stolen is False and self.cpic_searched_at is not None and self.serial_number is not None
def can_claim(self): def can_claim(self):
return self.claimed_by is None or not (self.claimed_by is not None and self.last_worked_on > timezone.now() - timedelta( return self.claimed_by is None or not (
weeks=4)) or self.last_worked_on is None self.claimed_by is not None and self.last_worked_on > timezone.now() - timedelta(
weeks=4)) or self.last_worked_on is None
def can_purchase(self): def can_purchase(self):
if self.claimed_by: if self.claimed_by:
@ -122,3 +123,10 @@ class Bike(models.Model):
@transition(field=state, source=[BikeState.ASSESSED, BikeState.RECEIVED], conditions=[can_transfer_to_police]) @transition(field=state, source=[BikeState.ASSESSED, BikeState.RECEIVED], conditions=[can_transfer_to_police])
def transfer_to_police(self): def transfer_to_police(self):
pass pass
@property
def available_states(self):
states = [state_transition.name
for state_transition in self.get_available_state_transitions()]
return states

View File

@ -10,3 +10,4 @@ class BikeSerializer(serializers.HyperlinkedModelSerializer):
created_at = serializers.ReadOnlyField() created_at = serializers.ReadOnlyField()
state = serializers.ReadOnlyField() state = serializers.ReadOnlyField()
available_states = serializers.ReadOnlyField()