我有一个叫出勤的Django模型,它有一个员工的打卡时间和打卡时间,以及该条目的状态,以查看它是否被授权。然后,我在做另一个模型叫工资单。我想这里面的考勤条目检查,看看所有授权的条目,然后对他们做一些行动。如何检查所有考勤条目的所有状态字段?你知道吗
编辑:更新以更好地阐述我的问题。
为了更好地阐述我的问题,以下是我如何设置考勤模型的:
class CWorkAttendance(models.Model):
AUTO_ATT = "AU"
MANUAL_ATT = "MA"
WORK_ENTRY_TYPES = (
(AUTO_ATT, "Auto-Attendance"),
(MANUAL_ATT, "Manual-Attendance"),
)
AUTHORIZED = "AU"
UNAUTHORIZED = "UA"
WORK_ENTRY_STATUSES = (
(AUTHORIZED, "Athorized"),
(UNAUTHORIZED, "Un-Authorized"),
)
#Thank you motatoes
def face_locations_in(self, instance):
now = datetime.datetime.now()
return "attendance/{}/{}/in".format(instance.work_employee, now.strftime("%Y/%m/%d"))
def face_locations_out(self, instance):
now = datetime.datetime.now()
return "attendance/{}/{}/out".format(instance.work_employee, now.strftime("%Y/%m/%d"))
work_employee = models.ForeignKey('CEmployees', on_delete=models.CASCADE,)
work_start_time = models.DateTimeField()
work_end_time = models.DateTimeField(null=True)
work_duration = models.IntegerField(null=True)
work_entry_type = models.CharField(max_length=2,choices=WORK_ENTRY_TYPES)
work_entry_status = models.CharField(max_length=2, choices=WORK_ENTRY_STATUSES, default=WORK_ENTRY_STATUSES[1][0])
employee_face_captured_in = models.ImageField(upload_to=face_locations_in,)#////////
employee_face_captured_out = models.ImageField(upload_to=face_locations_out,)
如果仔细查看work_entry_status
,它是一个choice CharField,它将包含条目的状态(默认情况下未授权)。你知道吗
我想创建一个Payroll模型,它将检查CWorkAttendance
模型中的所有行,并检查它们的work_entry_status
字段以查看它们是否被授权,这是我想学习的方法。你知道吗
如果这些字段被授权,我需要抓取行的work_employee
、work_duration
,以及雇员的原始CEmployees
行的一些细节。你知道吗
我希望我的工资单/工资单模型如下所示:
class Payslip(models.Model):
GENERATED = "GEN"
CONFIRMED = "CON"
PAYSLIP_STATUS = (
(GENERATED, "Generated-UNSAVED"),
(CONFIRMED, "Confirmed-SAVED"),
)
payslip_number = models.IntegerField()#MM/YY/AUTO_GENERATED_NUMBER(AUTO_INCREMENT)
payslip_employee = models.ForeignKey('CEmployees', on_delete=models.CASCADE,)#Choose the employee from the master table CEmployees
payslip_generation_date = models.DateTimeField(default=datetime.datetime.now())#Date of the payroll generation
payslip_total_hours = models.IntegerField()#Total hours that the employee worked
payslip_from_date = models.DateField()"""The date from when the payslip will be made. The payslip will be manual for now, so generate it after choosing a a date to generate from."""
payslip_total_basic_seconds = models.IntegerField()#Total seconds the employee worked
payslip_total_ot_seconds = models.IntegerField()#Total overtime seconds the employee worked
payslip_basic_hourly_rate = models.IntegerField()#The basic hourly rate of the employee mentioned here. Take from the master employees table.
payslip_basic_ot_rate = models.IntegerField()#Taking the basic overtime rate from the master table
payslip_total_amount = models.FloatField()#The total amount of the payslip
payslip_entry_status = models.CharField(max_length=3, default=GENERATED)#The status of the pay slip.
谢谢你
我不确定我是否理解你的要求,所以如果我误解了请告诉我。你知道吗
更新
既然您想手动执行,我建议您使用一个单独的视图来生成工资单。重要的是要知道这个工资单的
date_from
和date_to
。我想是管理者可以访问这个视图,所以您需要为它设置适当的访问控制。我还认为您需要有一个payslip_to_date
,即使您要在当前日期之前生成它,这将有助于保存记录。我假设你在下面的代码中有这个列。你知道吗你知道吗视图.py地址:
如果您希望以后自动生成工资单,您可能希望每月自动生成一次工资单。为此,您可以使用类似芹菜的东西为每个员工在后台运行定期任务。如果是这种情况,您可以将上面的代码移到
utils.py
这样的文件中。您可以创建一个方法,该方法采用employee\u id,从\u date到\u date,然后生成payslip对象,将payslip\u id返回给调用方法相关问题 更多 >
编程相关推荐