1
0
forked from erp-dev/erp

feat: prod clean

This commit is contained in:
2026-05-01 22:43:22 +08:00
parent 1afcfde151
commit d7b388e935
19 changed files with 1198 additions and 134 deletions

View File

@@ -0,0 +1,21 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("mission", "0005_mission_unreplied_notification_fields"),
]
operations = [
migrations.AddField(
model_name="mission",
name="extra",
field=models.JSONField(blank=True, null=True, verbose_name="扩展字段"),
),
migrations.AddField(
model_name="missionreply",
name="extra",
field=models.JSONField(blank=True, null=True, verbose_name="扩展字段"),
),
]

View File

@@ -87,6 +87,7 @@ class Mission(ModelBase):
verbose_name="关联对象类型",
)
content_id = models.PositiveBigIntegerField(null=True, blank=True, db_index=True, verbose_name="关联对象ID")
extra = models.JSONField(null=True, blank=True, verbose_name="扩展字段")
content_object = GenericForeignKey("content_type", "content_id")
@property
@@ -184,6 +185,7 @@ class MissionReply(ModelBase):
verbose_name="回应者",
)
content = models.TextField(verbose_name="回应内容")
extra = models.JSONField(null=True, blank=True, verbose_name="扩展字段")
replied_at = models.DateTimeField(default=timezone.now, db_index=True, verbose_name="回应时间")
ends_task = models.BooleanField(default=False, db_index=True, verbose_name="是否结束任务")
is_rejected = models.BooleanField(default=False, db_index=True, verbose_name="是否被撤销")

View File

@@ -141,6 +141,7 @@ def create_mission(
notify_if_unreplied: bool = False,
unreplied_notify_interval_minutes: int | None = None,
unreplied_notify_max_count: int = 5,
extra=None,
) -> Mission:
if creator is None:
raise ValueError("任务创建者不能为空")
@@ -160,6 +161,7 @@ def create_mission(
category=category or _get_default_mission_category(merchant=merchant),
content_type=content_type,
content_id=content_id,
extra=extra,
notify_if_unreplied=notify_if_unreplied,
unreplied_notify_interval_minutes=unreplied_notify_interval_minutes,
unreplied_notify_max_count=unreplied_notify_max_count,
@@ -189,6 +191,7 @@ def update_mission(
notify_if_unreplied=UNSET,
unreplied_notify_interval_minutes=UNSET,
unreplied_notify_max_count=UNSET,
extra=UNSET,
) -> Mission:
mission = Mission.objects.select_for_update().get(pk=mission.pk)
_assert_employee_belongs_to_mission(updated_by, mission, "更新任务的员工")
@@ -210,6 +213,9 @@ def update_mission(
mission.content_type = content_type
mission.content_id = content_id
update_fields.extend(["content_type", "content_id"])
if extra is not UNSET:
mission.extra = extra
update_fields.append("extra")
notify_changed = notify_if_unreplied is not UNSET
interval_changed = unreplied_notify_interval_minutes is not UNSET
@@ -272,6 +278,7 @@ def create_mission_reply(
responder,
content: str,
ends_task: bool = False,
extra=None,
) -> MissionReply:
mission = Mission.objects.select_for_update().get(pk=mission.pk)
_assert_employee_belongs_to_mission(responder, mission, "回应者")
@@ -284,6 +291,7 @@ def create_mission_reply(
responder=responder,
content=content,
ends_task=ends_task,
extra=extra,
)
if ends_task and not mission.is_completed:
mission.is_completed = True