class Employee(models.Model): MALE = 'male' FEMALE = 'female' OTHER = 'other' NOT_KNOWN = 'Not Known' GENDER = ( (MALE, 'Male'), (FEMALE, 'Female'), (OTHER, 'Other'), (NOT_KNOWN, 'Not Known'), ) MR = 'Mr' MRS = 'Mrs' MSS = 'Mss' DR = 'Dr' SIR = 'Sir' MADAM = 'Madam' TITLE = ( (MR, 'Mr'), (MRS, 'Mrs'), (MSS, 'Mss'), (DR, 'Dr'), (SIR, 'Sir'), (MADAM, 'Madam'), ) FULL_TIME = 'Full-Time' PART_TIME = 'Part-Time' CONTRACT = 'Contract' INTERN = 'Intern' EMPLOYEETYPE = ( (FULL_TIME, 'Full-Time'), (PART_TIME, 'Part-Time'), (CONTRACT, 'Contract'), (INTERN, 'Intern'), ) OLEVEL = 'O-LEVEL' SENIORHIGH = 'Senior High' JUNIORHIGH = 'Junior High' TERTIARY = 'Tertiary' PRIMARY = 'Primary Level' OTHER = 'Other' EDUCATIONAL_LEVEL = ( (SENIORHIGH, 'Senior High School'), (JUNIORHIGH, 'Junior High School'), (PRIMARY, 'Primary School'), (TERTIARY, 'Tertiary/University/Polytechnic'), (OLEVEL, 'OLevel'), (OTHER, 'Other'), ) AHAFO = 'Ahafo' ASHANTI = 'Ashanti' BONOEAST = 'Bono East' BONO = 'Bono' CENTRAL = 'Central' EASTERN = 'Eastern' GREATER = 'Greater Accra' NORTHEAST = 'North East' NORTHERN = 'Northen' OTI = 'Oti' SAVANNAH = 'Savannah' UPPEREAST = 'Upper East' UPPERWEST = 'Upper West' VOLTA = 'Volta' WESTERNNORTH = 'Western North' WESTERN = 'Western' GHANA_REGIONS = ( (AHAFO, 'Ahafo'), (ASHANTI, 'Ashanti'), (BONOEAST, 'Bono East'), (BONO, 'Bono'), (CENTRAL, 'Central'), (EASTERN, 'Eastern'), (GREATER, 'Greater Accra'), (NORTHEAST, 'Northen East'), (NORTHERN, 'Northen'), (OTI, 'Oti'), (SAVANNAH, 'Savannah'), (UPPEREAST, 'Upper East'), (UPPERWEST, 'Upper West'), (VOLTA, 'Volta'), (WESTERNNORTH, 'Western North'), (WESTERN, 'Western'), ) # PERSONAL DATA user = models.ForeignKey(User, on_delete=models.CASCADE, default=1) title = models.CharField(_('Title'), max_length=4, default=MR, choices=TITLE, blank=False, null=True) image = models.FileField(_('Profile Image'), upload_to='profiles', default='default.png', blank=True, null=True, help_text='upload image size less than 2.0MB' ) #work on path username-date/image firstname = models.CharField(_('Firstname'), max_length=125, null=False, blank=False) lastname = models.CharField(_('Lastname'), max_length=125, null=False, blank=False) othername = models.CharField(_('Othername (optional)'), max_length=125, null=True, blank=True) sex = models.CharField(_('Gender'), max_length=8, default=MALE, choices=GENDER, blank=False) email = models.CharField(_('Email (optional)'), max_length=255, default=None, blank=True, null=True) tel = PhoneNumberField( default='+233240000000', null=False, blank=False, verbose_name='Phone Number (Example +233240000000)', help_text='Enter number with Country Code Eg. +233240000000') bio = models.CharField( _('Bio'), help_text= 'your biography,tell me something about yourself eg. i love working ...', max_length=255, default='', null=True, blank=True) birthday = models.DateField(_('Birthday'), blank=False, null=False) religion = models.ForeignKey(Religion, verbose_name=_('Religion'), on_delete=models.SET_NULL, null=True, default=None) nationality = models.ForeignKey(Nationality, verbose_name=_('Nationality'), on_delete=models.SET_NULL, null=True, default=None) hometown = models.CharField(_('Hometown'), max_length=125, null=True, blank=True) region = models.CharField( _('Region'), help_text='what region of the country(Ghana) are you from ?', max_length=20, default=GREATER, choices=GHANA_REGIONS, blank=False, null=True) residence = models.CharField(_('Current Residence'), max_length=125, null=False, blank=False) address = models.CharField(_('Address'), help_text='address of current residence', max_length=125, null=True, blank=True) education = models.CharField( _('Education'), help_text= 'highest educational standard ie. your last level of schooling', max_length=20, default=SENIORHIGH, choices=EDUCATIONAL_LEVEL, blank=False, null=True) lastwork = models.CharField( _('Last Place of Work'), help_text='where was the last place you worked ?', max_length=125, null=True, blank=True) position = models.CharField( _('Position Held'), help_text='what position where you in your last place of work ?', max_length=255, null=True, blank=True) ssnitnumber = models.CharField(_('SSNIT Number'), max_length=30, null=True, blank=True) tinnumber = models.CharField(_('TIN'), max_length=15, null=True, blank=True) # COMPANY DATA department = models.ForeignKey(Department, verbose_name=_('Department'), on_delete=models.SET_NULL, null=True, default=None) role = models.ForeignKey(Role, verbose_name=_('Role'), on_delete=models.SET_NULL, null=True, default=None) startdate = models.DateField(_('Employement Date'), help_text='date of employement', blank=False, null=True) employeetype = models.CharField(_('Employee Type'), max_length=15, default=FULL_TIME, choices=EMPLOYEETYPE, blank=False, null=True) employeeid = models.CharField(_('Employee ID Number'), max_length=10, null=True, blank=True) dateissued = models.DateField(_('Date Issued'), help_text='date staff id was issued', blank=False, null=True) #app related is_blocked = models.BooleanField( _('Is Blocked'), help_text='button to toggle employee block and unblock', default=False) is_deleted = models.BooleanField( _('Is Deleted'), help_text='button to toggle employee deleted and undelete', default=False) created = models.DateTimeField(verbose_name=_('Created'), auto_now_add=True, null=True) updated = models.DateTimeField(verbose_name=_('Updated'), auto_now=True, null=True) #PLUG MANAGERS objects = EmployeeManager() class Meta: verbose_name = _('Employee') verbose_name_plural = _('Employees') ordering = ['-created'] def __str__(self): return self.get_full_name @property def get_full_name(self): fullname = '' firstname = self.firstname lastname = self.lastname othername = self.othername if (firstname and lastname) or othername is None: fullname = firstname + ' ' + lastname return fullname elif othername: fullname = firstname + ' ' + lastname + ' ' + othername return fullname return @property def get_age(self): current_year = datetime.date.today().year dateofbirth_year = self.birthday.year if dateofbirth_year: return current_year - dateofbirth_year return @property def can_apply_leave(self): pass @property def get_pretty_birthday(self): if self.birthday: return self.birthday.strftime( '%A,%d %B') # Thursday,04 May -> staffs age privacy return @property def birthday_today(self): ''' returns True, if birthday is today else False ''' return self.birthday.day == datetime.date.today().day @property def days_check_date_fade(self): ''' Check if Birthday has already been celebrated ie in the Past ie. 4th May & today 8th May 4 < 8 -> past else present or future ''' return self.birthday.day < datetime.date.today( ).day #Assumption made,If that day is less than today day,in the past def birthday_counter(self): ''' This method counts days to birthday -> 2 day's or 1 day ''' today = datetime.date.today() current_year = today.year birthday = self.birthday # eg. 5th May 1995 future_date_of_birth = datetime.date( current_year, birthday.month, birthday.day) #assuming born THIS YEAR ie. 5th May 2019 if birthday: if (future_date_of_birth - today).days > 1: return str((future_date_of_birth - today).days) + ' day\'s' else: return ' tomorrow' return def save(self, *args, **kwargs): ''' overriding the save method - for every instance that calls the save method perform this action on its employee_id added : March, 03 2019 - 11:08 PM ''' get_id = self.employeeid #grab employee_id number from submitted form field data = code_format(get_id) self.employeeid = data #pass the new code to the employee_id as its orifinal or actual code super().save(*args, **kwargs) # call the parent save method
class Employee(models.Model): id = models.AutoField(primary_key=True) MALE = 'male' FEMALE = 'female' OTHER = 'other' NOT_KNOWN = 'Not Known' GENDER = ( (MALE,'Male'), (FEMALE,'Female'), (OTHER,'Other'), (NOT_KNOWN,'Not Known'), ) MR = 'Mr' MRS = 'Mrs' MSS = 'Mss' DR = 'Dr' SIR = 'Sir' MADAM = 'Madam' TITLE = ( (MR,'Mr'), (MRS,'Mrs'), (MSS,'Mss'), (DR,'Dr'), (SIR,'Sir'), (MADAM,'Madam'), ) FULL_TIME = 'Full-Time' PART_TIME = 'Part-Time' CONTRACT = 'Contract' INTERN = 'Intern' EMPLOYEETYPE = ( (FULL_TIME,'Full-Time'), (PART_TIME,'Part-Time'), (CONTRACT,'Contract'), (INTERN,'Intern'), ) # PERSONAL DATA user = models.ForeignKey(User,on_delete=models.CASCADE,default=1) image = models.FileField(_('Profile Image'),upload_to='profiles',default='default.png',blank=True,null=True,help_text='upload image size less than 2.0MB')#work on path username-date/image firstname = models.CharField(_('Firstname'),max_length=125,null=False,blank=False) lastname = models.CharField(_('Lastname'),max_length=125,null=False,blank=False) othername = models.CharField(_('Othername (optional)'),max_length=125,null=True,blank=True) birthday = models.DateField(_('Birthday'),blank=False,null=False) department = models.ForeignKey(Department,verbose_name =_('Department'),on_delete=models.SET_NULL,null=True,default=None) role = models.ForeignKey(Role,verbose_name =_('Role'),on_delete=models.SET_NULL,null=True,default=None) startdate = models.DateField(_('Employement Date'),help_text='date of employement',blank=False,null=True) employeetype = models.CharField(_('Employee Type'),max_length=15,default=FULL_TIME,choices=EMPLOYEETYPE,blank=False,null=True) employeeid = models.CharField(_('Employee ID Number'),max_length=10,null=True,blank=True) line_manager_staff_id = models.CharField(_('Line Manager ID Number'),max_length=10,null=True,blank=True) Name_of_relief_person = models.CharField(_('Delegation of Authority(DOA)'),max_length=10,null=True,blank=True) date_issued = models.DateField(_('Date Issued'),help_text='date staff id was issued',blank=False,null=True) # app related is_blocked = models.BooleanField(_('Is Blocked'),help_text='button to toggle employee block and unblock',default=False) is_deleted = models.BooleanField(_('Is Deleted'),help_text='button to toggle employee deleted and undelete',default=False) created = models.DateTimeField(verbose_name=_('Created'),auto_now_add=True,null=True) updated = models.DateTimeField(verbose_name=_('Updated'),auto_now=True,null=True) #PLUG MANAGERS objects = EmployeeManager() class Meta: verbose_name = _('Employee') verbose_name_plural = _('Employees') ordering = ['-created'] def __str__(self): return self.get_full_name @property def get_full_name(self): fullname = '' firstname = self.firstname lastname = self.lastname othername = self.othername if (firstname and lastname) or othername is None: fullname = firstname +' '+ lastname return fullname elif othername: fullname = firstname + ' '+ lastname +' '+othername return fullname return @property def get_age(self): current_year = datetime.date.today().year dateofbirth_year = self.birthday.year if dateofbirth_year: return current_year - dateofbirth_year return @property def can_apply_leave(self): pass def save(self,*args,**kwargs): ''' overriding the save method - for every instance that calls the save method perform this action on its employee_id added : March, 03 2019 - 11:08 PM ''' get_id = self.employeeid #grab employee_id number from submitted form field data = code_format(get_id) self.employeeid = data #pass the new code to the employee_id as its original or actual code super().save(*args,**kwargs) # call the parent save method
class Employee(models.Model): CONTRACT_TYPE = (('DW', 'Daily Worker'), ('Staff', 'Staff'), ('Unknown', 'Unknown')) reg_number = models.CharField(verbose_name=_("NIK"), max_length=9, unique=True) person = models.ForeignKey(Person, verbose_name=_("Person"), on_delete=models.CASCADE, limit_choices_to={'status': 'hired'}) no_bpjstk = models.CharField(verbose_name=_("No BPJS Ketenagakerjaan"), max_length=20, null=True, blank=True) no_bpjskes = models.CharField(verbose_name=_("No BPJS Kesehatan"), max_length=20, null=True, blank=True) date_of_hired = models.DateField(verbose_name=_("Date of hired")) is_permanent = models.BooleanField(verbose_name=_("Permanent"), default=False) type = models.CharField(verbose_name=_("Employment type"), choices=CONTRACT_TYPE, max_length=7, default='Unknown') job_title = models.ForeignKey(JobTitle, verbose_name=_("Job title"), on_delete=models.PROTECT, null=True, blank=True) department = models.ForeignKey(Department, verbose_name=_("Department"), on_delete=models.PROTECT, null=True, blank=True) job_role = models.ForeignKey(JobRole, verbose_name=_("Job Role"), on_delete=models.PROTECT, null=True, blank=True) division = models.ForeignKey(Division, verbose_name=_("Division"), on_delete=models.PROTECT, null=True, blank=True) objects = EmployeeManager() class Meta: verbose_name = _("Employee") verbose_name_plural = _("2.1. Employee List") def __str__(self): return '{} - {}'.format(self.reg_number, self.person.name) @staticmethod def autocomplete_search_fields(): return ( 'id__iexact', 'person__name__icontains', ) def contract_count(self): return self.contract_set.all().count() contract_count.short_description = _("Contract Count") def last_contract_end_date(self): if self.contract_set.exists(): contract = self.contract_set.all().order_by('-end_date')[0] return contract.end_date return "-" last_contract_end_date.short_description = _("End Date")