network_inventory/devices/models/warranty.py

37 lines
879 B
Python
Raw Normal View History

2019-06-10 21:56:21 +02:00
from django.db import models
from core.models import Category
from core.utils import td_format
2020-01-12 16:21:12 +01:00
from .device import Device
2019-06-10 21:56:21 +02:00
class WarrantyType(Category):
description = models.TextField()
class Meta:
verbose_name_plural = "Warranty Types"
class Warranty(models.Model):
device = models.ForeignKey(Device, on_delete=models.CASCADE)
valid_from = models.DateField()
valid_until = models.DateField()
2019-07-19 16:32:24 +02:00
warranty_type = models.ForeignKey(WarrantyType, models.SET_NULL,
blank=True, null=True)
2019-06-10 21:56:21 +02:00
def __str__(self):
return str(self.device)
2019-06-10 21:56:21 +02:00
class Meta:
verbose_name_plural = "Warranties"
@property
def customer(self):
return self.device.customer
@property
def duration_in_years(self):
delta = self.valid_until - self.valid_from
return td_format(delta)