Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate that warranty start and end dates make sense #140

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions netbox_inventory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def warranty_progress(self):

def clean(self):
self.clean_delivery()
self.clean_warranty_dates()
self.validate_hardware_types()
self.validate_hardware()
self.update_status()
Expand Down Expand Up @@ -361,6 +362,10 @@ def clean_delivery(self):
if self.delivery and self.delivery.purchase != self.purchase:
raise ValidationError(f'Assigned delivery must belong to selected purchase ({self.purchase}).')

def clean_warranty_dates(self):
if self.warranty_start and self.warranty_end and self.warranty_end <= self.warranty_start:
raise ValidationError({'warranty_end': f'Warranty end date must be after warranty start date.'})

def get_absolute_url(self):
return reverse('plugins:netbox_inventory:asset', args=[self.pk])

Expand Down