feat(oa): terminate on return and copy form to start a new instance
Align with DingTalk: returned/rejected/cancelled are terminal; progress shows return on the approver task only; done list includes returned; deprecate same-instance resubmit and source-instance linking. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8b2d8284c7
commit
c9711d0dce
20 files changed
+74586
-32336
No files matched your search
@@ -508,7 +508,7 @@ class TestBuildProgress(unittest.TestCase):
|
||||
comment_text="不同意",
|
||||
resolve_source="users",
|
||||
)
|
||||
for status in ("rejected", "completed", "cancelled"):
|
||||
for status in ("rejected", "completed", "cancelled", "returned"):
|
||||
inst = MagicMock(
|
||||
status=status,
|
||||
initiator_user_id="u0",
|
||||
@@ -528,6 +528,66 @@ class TestBuildProgress(unittest.TestCase):
|
||||
terminal = [x for x in items if x["kind"] == "terminal"]
|
||||
self.assertEqual(len(terminal), 1, f"status={status} should have one terminal")
|
||||
|
||||
def test_progress_returned_has_no_kind_return_node(self):
|
||||
from app.services.oa_engine import build_progress_items
|
||||
|
||||
root = {
|
||||
"id": "s",
|
||||
"type": "start",
|
||||
"child": {
|
||||
"id": "a1",
|
||||
"type": "approval",
|
||||
"name": "审批人",
|
||||
"child": {"id": "e1", "type": "end"},
|
||||
},
|
||||
}
|
||||
ts = datetime(2026, 7, 15, 14, 58, 8)
|
||||
t_approval = MagicMock(
|
||||
id="tA",
|
||||
node_key="a1",
|
||||
node_name="审批人",
|
||||
task_type="approval",
|
||||
status="returned",
|
||||
assignee_user_id="u2",
|
||||
order_num=1,
|
||||
round_no=1,
|
||||
create_time=ts,
|
||||
update_time=ts,
|
||||
comment_text="打回",
|
||||
resolve_source="users",
|
||||
)
|
||||
ret_ev = MagicMock(
|
||||
event_type="return",
|
||||
round_no=1,
|
||||
actor_user_id="u2",
|
||||
create_time=ts,
|
||||
comment_text="打回",
|
||||
node_key="a1",
|
||||
task_id="tA",
|
||||
)
|
||||
inst = MagicMock(
|
||||
status="returned",
|
||||
initiator_user_id="u0",
|
||||
current_round=1,
|
||||
create_time=ts,
|
||||
update_time=ts,
|
||||
)
|
||||
items = build_progress_items(
|
||||
inst=inst,
|
||||
flow_root=root,
|
||||
tasks=[t_approval],
|
||||
name_map={"u0": "发起人", "u2": "审批人"},
|
||||
events=[ret_ev],
|
||||
)
|
||||
self.assertFalse(any(x["kind"] == "return" for x in items))
|
||||
tasks = [x for x in items if x["kind"] == "task"]
|
||||
self.assertEqual(len(tasks), 1)
|
||||
self.assertEqual(tasks[0]["status"], "returned")
|
||||
self.assertEqual(tasks[0]["commentText"], "打回")
|
||||
terminals = [x for x in items if x["kind"] == "terminal"]
|
||||
self.assertEqual(len(terminals), 1)
|
||||
self.assertEqual(terminals[0]["status"], "returned")
|
||||
|
||||
|
||||
class TestReturnAndResubmit(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -643,8 +703,8 @@ class TestReturnAndResubmit(unittest.TestCase):
|
||||
self.assertIsNotNone(ev)
|
||||
self.assertEqual(ev.comment_text, "请补充材料")
|
||||
|
||||
def test_resubmit_starts_new_round(self):
|
||||
from app.services.oa_engine import resubmit_instance, return_task
|
||||
def test_resubmit_raises_deprecated(self):
|
||||
from app.services.oa_engine import OaEngineError, resubmit_instance, return_task
|
||||
|
||||
with patch(
|
||||
"app.services.oa_engine.get_instance_detail",
|
||||
@@ -654,13 +714,7 @@ class TestReturnAndResubmit(unittest.TestCase):
|
||||
self.db, "t1", tenant_no="zkxw", user_id="u1", comment="请补充材料"
|
||||
)
|
||||
|
||||
fake_task = MagicMock()
|
||||
with patch(
|
||||
"app.services.oa_engine._create_tasks_for_node", return_value=[fake_task]
|
||||
), patch(
|
||||
"app.services.oa_engine.get_instance_detail",
|
||||
return_value={"id": "i1", "status": "running"},
|
||||
):
|
||||
with self.assertRaises(OaEngineError) as ctx:
|
||||
resubmit_instance(
|
||||
self.db,
|
||||
"i1",
|
||||
@@ -668,15 +722,21 @@ class TestReturnAndResubmit(unittest.TestCase):
|
||||
user_id="u0",
|
||||
form_data={"x": 1},
|
||||
)
|
||||
inst = self.db.query(self.OaInstance).filter_by(id="i1").first()
|
||||
self.assertEqual(inst.status, "running")
|
||||
self.assertEqual(inst.current_round, 2)
|
||||
submit_ev = (
|
||||
self.db.query(self.OaInstanceEvent)
|
||||
.filter_by(instance_id="i1", event_type="submit", round_no=2)
|
||||
.first()
|
||||
)
|
||||
self.assertIsNotNone(submit_ev)
|
||||
self.assertIn("废弃", str(ctx.exception))
|
||||
|
||||
def test_done_list_includes_returned(self):
|
||||
from app.services.oa_engine import list_tasks, return_task
|
||||
|
||||
with patch(
|
||||
"app.services.oa_engine.get_instance_detail",
|
||||
return_value={"id": "i1", "status": "returned"},
|
||||
):
|
||||
return_task(
|
||||
self.db, "t1", tenant_no="zkxw", user_id="u1", comment="请补充材料"
|
||||
)
|
||||
done = list_tasks(self.db, tenant_no="zkxw", user_id="u1", kind="done")
|
||||
self.assertEqual(len(done), 1)
|
||||
self.assertEqual(done[0]["status"], "returned")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user