class AssetPurchaseDetail(BaseModel): invoice_number = models.CharField(max_length=255, null=True, blank=True, verbose_name='Invoice Number') purchase_date = models.DateTimeField(null=True, blank=True, verbose_name='Purchase Date') asset_purchase_price = models.DecimalField(default=0, max_digits=10, decimal_places=2, verbose_name='Purchase Price') vat = models.DecimalField(default=0, max_digits=10, decimal_places=2, verbose_name='VAT') total_price = models.DecimalField(default=0, max_digits=10, decimal_places=2, verbose_name='Total Price') created_by = ProtectedForeignKey( 'operations.OperationsUser', null=False, blank=False, related_name='created_purchase_detail_asset') modified_by = ProtectedForeignKey( 'operations.OperationsUser', null=True, blank=True, related_name='modified_purchase_detail_asset') history = HistoricalRecords()
class AssetDetail(BaseModel): DEPARTMENT_LISTS = (('administration', 'Administration'), ('client_services', 'Client Services'), ('finance', 'Finance'), ('human_resources', 'Human Resources'), ('it', 'IT'), ('marketing', 'Marketing'), ('operations', 'Operations'), ('sales', 'Sales')) quantity = models.IntegerField(null=True, blank=True, validators=[MinValueValidator(1)]) user = models.CharField(max_length=255, null=True, blank=True) department = models.CharField(max_length=50, null=True, blank=True, choices=DEPARTMENT_LISTS) region = ProtectedForeignKey('operations.Region', null=True, blank=True, related_name='region_asset_detail') district = ProtectedForeignKey('operations.Branch', null=True, blank=True, related_name='district_asset_detail') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_asset_detail') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_asset_detail') history = HistoricalRecords()
class StockTransaction(BaseModel): STOCK_TRANSACTION_TYPES = (('allocated','Allocated'), ('received','Received')) stock_item = ProtectedForeignKey('StockItem', null=True, blank=True, related_name="stock_item_stock_recieved", verbose_name='Stock Item') reference = models.CharField(max_length=255, null=False, blank=False) transaction_type = models.CharField(max_length=255, null=False, blank=False, choices=STOCK_TRANSACTION_TYPES) opening_stock = models.IntegerField(null=True, blank=True, verbose_name='Opening Stock', validators=[MinValueValidator(0)]) quantity = models.IntegerField(null=True, blank=True, verbose_name='Quantity', validators=[MinValueValidator(0)]) transaction_date = models.DateTimeField(null=True, blank=True, verbose_name='Transaction Date') supplier = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='supplier_stock_received') district = ProtectedForeignKey('operations.Branch', null = True, blank = True, related_name='district_stock_allocation') comment = models.TextField(null=True, blank=True) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_stock_received') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_stock_received') @property def stock_balance(self): if self.transaction_type == 'allocated': stock_bal = self.opening_stock - self.quantity else: stock_bal = self.opening_stock + self.quantity return stock_bal
class FuelCardDocument(BaseModel): fuel_card = ProtectedForeignKey('FuelCard', null=False, blank=False, related_name='fuel_card_documents') document = ProtectedForeignKey('operations.Document', null=False, blank=False) document_type = models.ManyToManyField(FuelCardDocumentUploads, verbose_name='Document Type') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_fuel_card_documents') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_fuel_card_documents')
class ServiceProvider(BaseModel): name = models.CharField(max_length=255, null=False, unique=True, blank=False, verbose_name='Service Provider') contact_person = ProtectedForeignKey( 'operations.Contact', null=True, blank=True, related_name='service_provider_contact') address = ProtectedForeignKey('operations.Address', null=True, blank=True, related_name='service_provider_address') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_service_provider') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_service_provider') def __unicode__(self): return self.name
class VehicleFuelCard(BaseModel): vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='vehicle_fuel_card') fuel_card = ProtectedForeignKey('FuelCard', null=False, blank=False, related_name='fuel_card_vehicle') start_date = models.DateTimeField(null=False, blank=False, verbose_name='Start Date') end_date = models.DateTimeField(null=True, blank=True, verbose_name='End Date') reason = models.CharField(max_length=255, null=True, blank=True) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_vehiclefuelcard') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_vehiclefuelcard') def save(self, *args, **kwargs): curr_fuel_card = self.vehicle.current_fuel_card if curr_fuel_card: curr_fuel_card.end_date = self.start_date curr_fuel_card.modified_by_id = self.created_by_id super(VehicleFuelCard, curr_fuel_card).save(*args, **kwargs) fuel_card = curr_fuel_card.fuel_card fuel_card.status = "cancelled" fuel_card.cancelled_date = self.start_date fuel_card.save() new_vehicle_driver = self super(VehicleFuelCard, self).save(*args, **kwargs) return self
class Insurer(BaseModel): name = models.CharField(max_length=255, null=False, unique=True, blank=False, verbose_name='Insurer Name') contact_person = ProtectedForeignKey('operations.Contact', null=True, blank=True, related_name='insurer_contact') address = ProtectedForeignKey('operations.Address', null=True, blank=True, related_name='insurer_address') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_insurer') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_insurer') def insured_vehicles(self): iv = Insurance.objects.filter(insurer=self).count() return iv def __unicode__(self): return self.name
class Branch(BaseModel): OFFICE_TYPES = (('Head Office', 'Head Office'), ('Regional', 'Regional'), ('Satelite', 'Satelite')) code = models.CharField(max_length=255, unique=True, null=False, blank=False) description = models.CharField(max_length=255, null=False, blank=False) office_type = models.CharField(max_length=50, null=True, blank=True, default='new', choices=OFFICE_TYPES, db_index=True) region = ProtectedForeignKey('operations.Region', null=True, blank=True, related_name='branch_region') contact_person = ProtectedForeignKey('operations.Contact', null=True, blank=True, related_name='branch_contact') address = ProtectedForeignKey('operations.Address', null=True, blank=True, related_name='branch_address') def __unicode__(self): return "{} - {}".format(self.code, self.description) @property def branch_name(self): return "{} - {}".format(self.code, self.description)
class ServiceBooking(BaseModel): service = models.BooleanField(default=False) maintenance = models.BooleanField(default=False) vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='service_bookings') comment = models.TextField(null=True, blank=True) booking_date = models.DateTimeField(null=True, blank=True, verbose_name='Booking Date') service_date = models.DateTimeField(null=True, blank=True, verbose_name='Service Date') current_mileage = models.IntegerField(null=True, blank=True, default=0, validators=[MinValueValidator(0)], verbose_name='Current Mileage') brakes = models.BooleanField(default=False) clutch = models.BooleanField(default=False) tyres = models.BooleanField(default=False) other = models.BooleanField(default=False) long_term_repairs = models.BooleanField(default=False, verbose_name='Long Term Repairs') follow_up_date = models.DateTimeField(null=True, blank=True, verbose_name='Follow-up Date') status = models.CharField(max_length=255, null=True, blank=True) balance = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True) service_interval = models.CharField(max_length=255, null=True, blank=True, verbose_name='Service Interval') document_received = models.CharField(max_length=255, null=True, blank=True, verbose_name='Document Type') document_number = models.CharField(max_length=50, null=True, blank=True, verbose_name='Document Number') document_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True, validators=[MinValueValidator(0.00)], verbose_name='cost') document_date = models.DateTimeField(null=True, blank=True, verbose_name='Document Date') vendor = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='service_bookings_vendor') created_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='created_service_bookings') authorised_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='authorised_service_bookings')
class InsuranceClaimDocument(BaseModel): insurance_claim = ProtectedForeignKey('InsuranceClaim', null=False, blank=False, related_name='insurance_claim_documents') document = ProtectedForeignKey('operations.Document', null=False, blank=False) document_type = models.ManyToManyField(InsuranceClaimDocumentTypes, verbose_name='Document Type') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_insurance_claim_documents') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_insurance_claim_documents')
class BaseTicket(BaseModel): TICKET_STATUS = (('new', 'New'), ('pending', 'Pending'), ('closed', 'Closed')) CATEGORIES = (('fleet management', 'Fleet Management'), ('inventory', 'Inventory'), ('property and facilities', 'Property & Facilities'), ('offices', 'Offices')) number = models.CharField(max_length=255, null=False, blank=False, unique=True, db_index=True) category = models.CharField(max_length=50, null=False, blank=False, default='new', choices=CATEGORIES, db_index=True) subject = models.CharField(max_length=255, null=False, blank=False, db_index=True) status = models.CharField(max_length=50, null=False, blank=False, default='new', choices=TICKET_STATUS, db_index=True) employee = ProtectedForeignKey('employees.Employee', null=True, blank=True, db_index=True) technician = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, db_index=True, related_name='baseticket_technician') description = models.TextField(null=False, blank=False) is_closed = models.BooleanField(default=False) possible_fix = ProtectedForeignKey('TicketFixOption', null=True, blank=True) created_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, db_index=True, related_name='baseticket_creator')
class ResidualRisk(models.Model): class Meta: db_table = "idt_residual_risk" CHOICES = ( ('estimates', 'Estimates'), ('data', 'Data'), ('supply', 'Supply'), ) choice = models.CharField(choices=CHOICES, max_length=255, null=False, default='estimates') user = OneToOneOrNoneField('cephia.CephiaUser', null=True, blank=True) residual_risk = models.FloatField(null=False, default=0) residual_risk_input = models.FloatField(null=False, default=0) infectious_period = models.FloatField(null=False) infectious_period_input = models.FloatField( null=False, blank=False, default=0, verbose_name='Start of infectious period') viral_growth_rate = models.FloatField(null=True, blank=False) origin_viral_load = models.FloatField( null=True, blank=False, verbose_name='Viral load at origin/zero') viral_load = models.FloatField( null=True, blank=False, verbose_name='Viral load at start of infectious period') confirmed_transmissions = models.IntegerField(null=True, blank=False) screening_test = ProtectedForeignKey('IDTDiagnosticTest', null=True, related_name='screening') positive_test = ProtectedForeignKey('IDTDiagnosticTest', null=True, related_name='positive') negative_test = ProtectedForeignKey('IDTDiagnosticTest', null=True, related_name='negative') ci_lower_bound = models.FloatField(null=True) ci_upper_bound = models.FloatField(null=True) graph_file_probability = models.FileField(upload_to="graphs", max_length=255, null=True) graph_file_donations = models.FileField(upload_to="graphs", max_length=255, null=True) upper_limit = models.FloatField(null=False, default=0)
class TestPropertyMapping(models.Model): class Meta: db_table = "idt_test_property_mapping" unique_together = ('code', 'user') code = models.CharField(max_length=255) test = ProtectedForeignKey('IDTDiagnosticTest', null=True, blank=True) test_property = ProtectedForeignKey('IDTTestPropertyEstimate', null=True, blank=True) user = ProtectedForeignKey('cephia.CephiaUser')
class Branding(BaseModel): vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='branding') supplier = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='branding_supplier') installer = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='branding_installer') installation_date = models.DateTimeField(null=True, blank=True, verbose_name='Installation Date') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_trackers') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_trackers') history = HistoricalRecords()
class InsuranceClaim(BaseModel): CLAIMTYPES = (('accident claim', 'Accident Claim'), ('vehicle theft', 'Vehicle Theft'), ('windscreen', 'Windscreen'), ('other', 'Other')) INSURANCECLAIM_STATUSES = (('captured','Captured'), ('paid','Paid'), ('rejected','Rejected'), ('submitted for payment','Submit For Payment')) CO_PAYMENTS = (('yes','Yes'),('no','No')) # incident = ProtectedForeignKey('Incident', null=False, blank=False, related_name='insurance_claim') vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='insurance_vehicle') incident_date = models.DateTimeField(null=False, blank=False, verbose_name='Incident Date') driver = ProtectedForeignKey('employees.Employee', null=True, blank=True, related_name='insurance_claim_driver') claim_type = models.CharField(max_length=50, null=False, blank=False, choices=CLAIMTYPES, verbose_name='Claim Type') reason_other = models.CharField(max_length=255, null=True, blank=True, verbose_name="Reason") quote_reference_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Quote Reference Number") quote_amount = models.CharField(max_length=50, null=True, blank=True, validators=[MinValueValidator(0)], verbose_name='Quote Amount') damage_description = models.TextField(null=False, blank=False, verbose_name="Damage Description") incident_description = models.TextField(null=False, blank=False, verbose_name="Incident Description") submission_date = models.DateTimeField(null=True, blank=True, verbose_name='Insurance Submission Date') insurance_reference_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Claim Reference Number") insurance_date_recieved = models.DateTimeField(null=True, blank=True, verbose_name='Insurance Date Recieved') insurance_comment = models.TextField(null=True, blank=True, verbose_name="Insurance Comment") claim_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Claim Number") claim_date_recieved = models.DateTimeField(null=True, blank=True, verbose_name='Claim Date Recieved') claim_comment = models.TextField(null=True, blank=True, verbose_name="Claim Comment") vendor = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='insurance_claim_vendor') status = models.CharField(max_length=255, null=True, blank=True, choices=INSURANCECLAIM_STATUSES) invoice_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2, verbose_name="Invoice Amount") invoice_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Invoice Number") driver_co_payment = models.CharField(max_length=255, null=True, blank=True, choices=CO_PAYMENTS, verbose_name="Driver Co Payment") percentage = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True) share_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True, verbose_name="Share Amount") created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_insurance_claims') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_insurance_claims') def get_share_amount(self): result = (self.invoice_amount * self.percentage)/100 return result def save(self, *args, **kwargs): if self.driver_co_payment == 'yes': self.share_amount = self.get_share_amount() super(InsuranceClaim, self).save(*args, **kwargs)
class StockItem(BaseModel): STOCK_CATEGORIES = (('consumables', 'Consumables'), ('sanitary', 'Sanitary'), ('stationery', 'Stationery')) item_name = models.CharField(max_length=255, unique=True, null=False, blank=False, verbose_name="Item Name") category = models.CharField(max_length=255, null=False, blank=False, choices=STOCK_CATEGORIES) stock_quantity = models.IntegerField(null=True, blank=True, verbose_name='Stock Quantity', validators=[MinValueValidator(0)]) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_stock_item') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_stock_item') def __unicode__(self): return self.item_name
class VehicleDocument(BaseModel): DOCUMENT_TYPES = (('contract','Contract'), ('invoice','Invoice'), ('lease','Lease Agreement'), ('natis','Natis Document'), ('quotation','Quotation'), ('other', 'Other')) vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='documents') document = ProtectedForeignKey('operations.Document', null=False, blank=False) document_type = models.CharField(max_length=255, null=False, blank=False, choices=DOCUMENT_TYPES) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_documents') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_documents')
class Vendor(BaseModel): TYPE_LIST = (('branding', 'Branding'), ('dealer', 'Dealer'), ('fuel card supplier', 'Fuel Card Supplier'), ('installer', 'Installer'), ('insurance', 'Insurance'), ('service provider', 'Service Provider'), ('tracker', 'Tracker')) ACCOUNT_TYPE = (('cash', 'Cash'), ('credit', 'Credit'), ('debit', 'Debit')) name = models.CharField(max_length=255, null=False, unique=True, blank=False, verbose_name='Vendor') vendor_type = models.CharField(max_length=50, null=False, blank=False, choices=TYPE_LIST, db_index=True, verbose_name='Vendor Type') account_type = models.CharField(max_length=50, null=True, blank=True, choices=ACCOUNT_TYPE, verbose_name='Account Type') balance = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True) contact_person = ProtectedForeignKey('operations.Contact', null=True, blank=True, related_name='vendor_contact') address = ProtectedForeignKey('operations.Address', null=True, blank=True, related_name='vendor_address') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_vendor') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_vendor') def __unicode__(self): return self.name
class FuelCardUsage(BaseModel): USAGE_TYPES = (('import','Import'),('manual','Manual')) TRAN_TYPES = (('CARD FEE','CARD FEE'), ('COURIER SERVICE','COURIER SERVICE'), ('DAMAGED CRD_FEE','DAMAGED CRD_FEE'), ('EFT','EFT'), ('FUEL','FUEL'), ('MAINTENANCE','MAINTENANCE'), ('OIL','OIL'), ('TOLL-GATE','TOLL-GATE'), ('TRANSACTION FEE','TRANSACTION FEE'), ('VAT OF SER FEES','VAT OF SER FEES')) fuel_card = ProtectedForeignKey('FuelCard', null=True, blank=True, verbose_name='Fuel Card Number', related_name='fuel_card_usage') transaction_date = models.DateTimeField(null=False, blank=False, verbose_name='Transaction Date',) usage_type = models.CharField(max_length=255, null=False, blank=False, verbose_name='Usage Type', default='import', choices=USAGE_TYPES) transaction_type = models.ManyToManyField(FuelCardUsageTransactionType, verbose_name='Transaction Type', related_name='fuel_usage_transaction_types') transaction_number = models.CharField(max_length=255, null=True, blank=True, verbose_name='Transaction Number') transaction_code = models.CharField(max_length=255, null=True, blank=True, verbose_name='Transaction Code') merchant_name = models.CharField(max_length=255, null=True, blank=True, verbose_name='Merchant Name') quantity = models.DecimalField(default=0, max_digits=10, decimal_places=2) amount = models.DecimalField(default=0, max_digits=10, decimal_places=2) driver = ProtectedForeignKey('employees.Employee', null=True, blank=True, related_name='fuel_usage_driver') vehicle = ProtectedForeignKey('Vehicle', null=True, blank=True, related_name='fuel_usage_vehicle') comment = models.CharField(max_length=255, null=True, blank=True, verbose_name='Comments') @property def total_usage(self): return FuelCardUsage.objects.filter(fuel_card=self.pk, transaction_type__description__in=['FUEL', 'OIL','TOLL-GATE'],)\ .aggregate(Sum('amount'))['amount__sum'] or 0 def fuel_usage(self): first_of_month = self.transaction_date.replace(day=1) if self.transaction_date.month == 12: last_of_month = self.transaction_date.replace(day=31) else: last_of_month = self.transaction_date.replace(month=self.transaction_date.month+1, day=1) - timedelta(days=1) transaction_types = FuelCardUsageTransactionType.objects.filter(description__in=['FUEL', 'OIL','TOLL-GATE']) usage = FuelCardUsage.objects.filter(fuel_card=self.fuel_card, transaction_type__in=transaction_types, transaction_date__gte=first_of_month, transaction_date__lte=self.transaction_date)\ .aggregate(Sum('amount'))['amount__sum'] or 0 return usage @property def balance(self): return self.fuel_card.card_limit - self.fuel_usage()
class Document(BaseModel): FILE_TYPES = (('document', 'Document'), ('photo', 'Photo')) document_name = models.CharField(max_length=255, null=False, blank=False, db_index=True) document = models.FileField(null=True, blank=True, upload_to='uploads/documents') image = models.ImageField(null=True, blank=True, upload_to="uploads/images") thumbnail = ThumbnailImageField(source="image") file_type = models.CharField(max_length=50, null=False, blank=False, choices=FILE_TYPES, db_index=True) description = models.TextField(null=True, blank=True) created_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, db_index=True)
class VehicleDriver(BaseModel): REASONS = (('discretionary change','Discretionary Vehicle Change'), ('new employee','New Employee'), ('pool car','Pool Car'), ('relocation','Relocation'), ('temp vehicle','Temp Vehicle')) UNASSIGN_REASONS = (('adsconded', 'Absconded'), ('discretionary change','Discretionary Vehicle Change'), ('dismissed','Dismissal'), ('long term repair','Long-term Maintenance/Repairs'), ('relocation','Relocation'), ('resignation','Resignation'), ('suspend','Suspension'), ('temp vehicle','Temp Vehicle'), ('insurance pending','Insurance Claim - Pending'), ('insurance repairs','Insurance Claim - Repairs')) vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='vehicle_driver') driver = ProtectedForeignKey('employees.Employee', null=False, blank=False, related_name='driver_vehicle') start_date = models.DateTimeField(null=False, blank=False, verbose_name='Start Date') end_date = models.DateTimeField(null=True, blank=True, verbose_name='End Date') reason = models.CharField(max_length=255, null=False, blank=False) status = models.CharField(max_length=255, null=True, blank=True) unassign_reason = models.CharField(max_length=255, null=True, blank=True) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_vehicle_drivers') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_vehicle_drivers') history = HistoricalRecords() def save(self, *args, **kwargs): curr_vehicle_driver = self.vehicle.current_vehicle_driver if curr_vehicle_driver: curr_vehicle_driver.end_date = self.start_date curr_vehicle_driver.modified_by_id = self.created_by_id super(VehicleDriver, curr_vehicle_driver).save(*args, **kwargs) new_vehicle_driver = self super(VehicleDriver, self).save(*args, **kwargs) return self def __unicode__(self): return self.reason
class VehicleMaintenance(BaseModel): vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='maintenance_plan') end_date = models.DateTimeField(null=True, blank=True, verbose_name='End Date') end_mileage = models.IntegerField(null=True, blank=True, default=0, validators=[MinValueValidator(0)], verbose_name='End Mileage') service_interval = models.IntegerField(null=True, blank=True, default = 0, verbose_name='Service Interval') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_vehicle_maintenance') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_vehicle_maintenance') history = HistoricalRecords() @property def registration_number(self): try: return self.registration_number.get(end_date__isnull=True).registration_number except Vehicle.DoesNotExist: return None
class VehicleTyre(BaseModel): vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name="tyres") make = models.CharField(max_length=255, null=False, blank=False, verbose_name='Make') size = models.CharField(max_length=255, null=False, blank=False, verbose_name='Size') position = models.CharField(max_length=50, null=False, blank=False, verbose_name='Position', choices=(('fr','Front Right'),('fl','Front Left'), ('rr','Rear Right'),('rl','Rear Left'), ('spare','Spare'))) serial_number = models.CharField(max_length=255, null=True, blank=True, verbose_name='Serial Number') mileage_at_replacement = models.IntegerField(null=True, blank=True, verbose_name='Mileage At Replacement', validators=[MinValueValidator(0)]) in_use = models.BooleanField(default=False) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_tyres') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_tyres') history = HistoricalRecords()
class Incident(BaseModel): INCIDENT_TYPES = (('vehicle','Vehicle'), ('windscreen','Windscreen'), ('tyres','Tyres'), ('other','Other')) INCIDENT_STATUSES = (('captured','Captured'), ('paid','Paid'), ('rejected','Rejected'), ('submitted for payment','Submit For Payment')) CO_PAYMENTS = (('yes','Yes'),('no','No')) incident_date = models.DateTimeField(null=False, blank=False, verbose_name='Incident Date') incident_type = models.CharField(max_length=255, null=False, blank=False, choices=INCIDENT_TYPES, verbose_name='Incident Type') description = models.TextField(null=False, blank=False) cost = models.DecimalField(default=0, max_digits=10, decimal_places=2) driver = ProtectedForeignKey('employees.Employee', null=True, blank=True, related_name='incident_driver') vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='incident_vehicle') reference_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Reference Number") resolved = models.BooleanField(default=False) status = models.CharField(max_length=255, null=True, blank=True, choices=INCIDENT_STATUSES) invoice_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2, verbose_name="Invoice Amount") invoice_number = models.CharField(max_length=255, null=True, blank=True, verbose_name="Invoice Number") driver_co_payment = models.CharField(max_length=255, null=True, blank=True, choices=CO_PAYMENTS, verbose_name="Driver Co Payment") percentage = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True) share_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2, null=True, blank=True, verbose_name="Share Amount") date_recieved_by_fleet = models.DateTimeField(null=True, blank=True, verbose_name='Date Recieved By Fleet') date_sent_to_finance = models.DateTimeField(null=True, blank=True, verbose_name='Date Sent Through To Finance') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_incidents') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_incidents') history = HistoricalRecords() def __unicode__(self): return self.incident_type def get_share_amount(self): result = (self.invoice_amount * self.percentage)/100 return result def save(self, *args, **kwargs): if self.driver_co_payment == 'yes': self.share_amount = self.get_share_amount() super(Incident, self).save(*args, **kwargs)
class CredibilityInterval(models.Model): calculate_ci = models.BooleanField(blank=False, default=False) alpha = models.FloatField( null=False, blank=False, default=0.05, verbose_name='Significance level (alpha) for credibility intervals') user = ProtectedForeignKey('cephia.CephiaUser', null=True, blank=True, unique=True)
class FinanceDetail(BaseModel): purchase_detail = ProtectedForeignKey('PurchaseDetail', null=False, blank=False, related_name='finance_detail') financier = models.CharField(max_length=255, null=True, blank=True) contract_number = models.CharField(max_length=255, null=False, blank=False, verbose_name='Contract Number') contract_term_months = models.IntegerField(null=True, blank=True, verbose_name='Contract Term Months', validators=[MinValueValidator(0)]) deposit = models.IntegerField(null=False, blank=False, default=0, validators=[MinValueValidator(0)]) installment = models.IntegerField(null=False, blank=False, default=0, validators=[MinValueValidator(0)]) settlement_amount = models.IntegerField(null=True, blank=True, default=0, verbose_name='Settlement Amount', validators=[MinValueValidator(0)]) settlement_amount_date = models.DateTimeField(null=True, blank=True, verbose_name='Settlement Amount Date') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_finance_detail') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_finance_detail') history = HistoricalRecords()
class Attachment(models.Model): file_attachment = models.FileField(storage=get_storage(), upload_to='mail-queue/attachments', null=True, max_length=255) email = ProtectedForeignKey(MailerMessage, blank=True, null=True) name = models.CharField(blank=True, null=True, max_length=255) inline_content_id = models.CharField(max_length=255, null=True) class Meta: verbose_name = _('Attachment') verbose_name_plural = _('Attachments') def __str__(self): return self.file_attachment.name
class PurchaseDetail(BaseModel): PURCHASE_TYPES = (('cash','Cash'),('hp','HP - Hire Purchase'), ('lease','Lease')) vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='purchase_detail') vendor = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='purchase_details_dealer') invoice_number = models.CharField(max_length=255, null=False, blank=False, verbose_name='Invoice Number') purchase_amount = models.IntegerField(null=False, blank=False, verbose_name='Purchase Amount', validators=[MinValueValidator(0)]) purchase_date = models.DateTimeField(null=True, blank=True, verbose_name='Purchase Date') purchase_type = models.CharField(max_length=50, null=False, blank=False, verbose_name='Purchase Type', choices=PURCHASE_TYPES) created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_purchase_detail') modified_by = ProtectedForeignKey('operations.OperationsUser', null=True, blank=True, related_name='modified_purchase_detail') history = HistoricalRecords()
class Insurance(BaseModel): COVER_TYPES = (('insurance','Insurance'), ('shortfall','Shortfall Cover')) vehicle = ProtectedForeignKey('Vehicle', null=False, blank=False, related_name='insurance') broker_name = models.CharField(max_length=255, null=True, blank=True, verbose_name='Broker Name') broker_contact_person = ProtectedForeignKey('operations.Contact', null=True, blank=True, related_name='insurance_broker_contact') broker_address = ProtectedForeignKey('operations.Address', null=True, blank=True, related_name='insurance_broker_address') insurance_type = models.CharField(max_length=255, null=False, blank=False, verbose_name='Insurance Type',choices=COVER_TYPES) insured_amount = models.IntegerField(null=False, blank=False, default=0, verbose_name='Insured Amount', validators=[MinValueValidator(0)]) installment = models.IntegerField(null=False, blank=False, default=0, validators=[MinValueValidator(0)]) vendor = ProtectedForeignKey('operations.Vendor', null = True, blank = True, related_name='insurance_insurer') created_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='created_insurance') modified_by = ProtectedForeignKey('operations.OperationsUser', null=False, blank=False, related_name='modified_insurance') history = HistoricalRecords()
class IDTDiagnosticTestHistory(models.Model): class Meta: db_table = "idt_diagnostic_test_history" subject = ProtectedForeignKey('IDTSubject', null=True, blank=False, related_name='idt_test_history') data_file = ProtectedForeignKey('IDTFileInfo', null=False, blank=False, related_name='test_history') test_code = models.CharField(max_length=255, null=True, blank=True) test_date = models.DateField(null=True, blank=False) adjusted_date = models.DateField(null=True, blank=False) test_result = models.CharField(max_length=15, null=True, blank=False) diagnostic_delay = models.FloatField(null=True, blank=True) sigma = models.FloatField(null=True, blank=True) warning = models.CharField(max_length=255, null=True, blank=True) def __unicode__(self): return u'%s - %s' % (self.test_date, self.test_result)