From 27e8120c0d870daf6725588f78e9de4edb1a0009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 13 Mar 2025 14:51:16 +0100 Subject: [PATCH 1/5] feat: document field calculation event --- csfunctions/events/__init__.py | 5 ++ csfunctions/events/base.py | 1 + .../events/document_field_calculation.py | 19 +++++ json_schemas/request.json | 71 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 csfunctions/events/document_field_calculation.py diff --git a/csfunctions/events/__init__.py b/csfunctions/events/__init__.py index a2f91b4..89f5e49 100644 --- a/csfunctions/events/__init__.py +++ b/csfunctions/events/__init__.py @@ -3,6 +3,7 @@ from pydantic import Field from .dialog_data import DocumentReleaseDialogData, PartReleaseDialogData +from .document_field_calculation import DocumentFieldCalculationData, DocumentFieldCalculationEvent from .document_release import DocumentReleaseData, DocumentReleaseEvent from .document_release_check import DocumentReleaseCheckData, DocumentReleaseCheckEvent from .dummy import DummyEvent, DummyEventData @@ -17,6 +18,7 @@ Union[ DocumentReleaseEvent, DocumentReleaseCheckEvent, + DocumentFieldCalculationEvent, PartReleaseEvent, PartReleaseCheckEvent, FieldValueCalculationEvent, @@ -30,6 +32,7 @@ EventData = Union[ DocumentReleaseData, DocumentReleaseCheckData, + DocumentFieldCalculationData, PartReleaseData, PartReleaseCheckData, FieldValueCalculationData, @@ -42,6 +45,7 @@ __all__ = [ "DocumentReleaseEvent", "DocumentReleaseCheckEvent", + "DocumentFieldCalculationEvent", "PartReleaseEvent", "PartReleaseCheckEvent", "FieldValueCalculationEvent", @@ -51,6 +55,7 @@ "WorkflowTaskTriggerEvent", "DocumentReleaseData", "DocumentReleaseCheckData", + "DocumentFieldCalculationData", "PartReleaseData", "PartReleaseCheckData", "FieldValueCalculationData", diff --git a/csfunctions/events/base.py b/csfunctions/events/base.py index 282c256..22bc50d 100644 --- a/csfunctions/events/base.py +++ b/csfunctions/events/base.py @@ -7,6 +7,7 @@ class EventNames(str, Enum): DUMMY = "dummy" DOCUMENT_RELEASE = "document_release" DOCUMENT_RELEASE_CHECK = "document_release_check" + DOCUMENT_FIELD_CALCULATION = "document_field_calculation" PART_RELEASE = "part_release" PART_RELEASE_CHECK = "part_release_check" ENGINEERING_CHANGE_RELEASE = "engineering_change_release" diff --git a/csfunctions/events/document_field_calculation.py b/csfunctions/events/document_field_calculation.py new file mode 100644 index 0000000..829db34 --- /dev/null +++ b/csfunctions/events/document_field_calculation.py @@ -0,0 +1,19 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class DocumentFieldCalculationData(BaseModel): + document: Document = Field(..., description="Current state of the document") + action: Literal["create", "modify", "copy", "index"] = Field(..., description="Action being performed") + linked_parts: list[Part] = Field(..., description="Parts that belong to the document") + linked_documents: list[Document] = Field(..., description="Related documents (e.g. source document)") + + +class DocumentFieldCalculationEvent(BaseEvent): + name: Literal[EventNames.DOCUMENT_FIELD_CALCULATION] = EventNames.DOCUMENT_FIELD_CALCULATION + data: DocumentFieldCalculationData diff --git a/json_schemas/request.json b/json_schemas/request.json index 00f5090..d254b91 100644 --- a/json_schemas/request.json +++ b/json_schemas/request.json @@ -731,6 +731,73 @@ "title": "Document", "type": "object" }, + "DocumentFieldCalculationData": { + "properties": { + "document": { + "$ref": "#/$defs/Document", + "description": "Current state of the document" + }, + "action": { + "description": "Action being performed", + "enum": [ + "create", + "modify", + "copy", + "index" + ], + "title": "Action", + "type": "string" + }, + "linked_parts": { + "description": "Parts that belong to the document", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Linked Parts", + "type": "array" + }, + "linked_documents": { + "description": "Related documents (e.g. source document)", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Linked Documents", + "type": "array" + } + }, + "required": [ + "document", + "action", + "linked_parts", + "linked_documents" + ], + "title": "DocumentFieldCalculationData", + "type": "object" + }, + "DocumentFieldCalculationEvent": { + "properties": { + "name": { + "const": "document_field_calculation", + "default": "document_field_calculation", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/DocumentFieldCalculationData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "DocumentFieldCalculationEvent", + "type": "object" + }, "DocumentReleaseCheckData": { "properties": { "documents": { @@ -2749,6 +2816,7 @@ "event": { "discriminator": { "mapping": { + "document_field_calculation": "#/$defs/DocumentFieldCalculationEvent", "document_release": "#/$defs/DocumentReleaseEvent", "document_release_check": "#/$defs/DocumentReleaseCheckEvent", "dummy": "#/$defs/DummyEvent", @@ -2768,6 +2836,9 @@ { "$ref": "#/$defs/DocumentReleaseCheckEvent" }, + { + "$ref": "#/$defs/DocumentFieldCalculationEvent" + }, { "$ref": "#/$defs/PartReleaseEvent" }, From 1c0cfd1f1015ac46eb81cf8fb37a81c321d07930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Thu, 13 Mar 2025 14:55:45 +0100 Subject: [PATCH 2/5] feat: part field calculation event --- csfunctions/events/__init__.py | 5 ++ csfunctions/events/base.py | 1 + csfunctions/events/part_field_calculation.py | 20 ++++++ json_schemas/request.json | 71 ++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 csfunctions/events/part_field_calculation.py diff --git a/csfunctions/events/__init__.py b/csfunctions/events/__init__.py index 89f5e49..13f7370 100644 --- a/csfunctions/events/__init__.py +++ b/csfunctions/events/__init__.py @@ -10,6 +10,7 @@ from .engineering_change_release import EngineeringChangeRelease, EngineeringChangeReleaseData from .engineering_change_release_check import EngineeringChangeReleaseCheck, EngineeringChangeReleaseCheckData from .field_value_calculation import FieldValueCalculationData, FieldValueCalculationEvent +from .part_field_calculation import PartFieldCalculationData, PartFieldCalculationEvent from .part_release import PartReleaseData, PartReleaseEvent from .part_release_check import PartReleaseCheckData, PartReleaseCheckEvent from .workflow_task_trigger import WorkflowTaskTriggerEvent, WorkflowTaskTriggerEventData @@ -21,6 +22,7 @@ DocumentFieldCalculationEvent, PartReleaseEvent, PartReleaseCheckEvent, + PartFieldCalculationEvent, FieldValueCalculationEvent, DummyEvent, EngineeringChangeRelease, @@ -35,6 +37,7 @@ DocumentFieldCalculationData, PartReleaseData, PartReleaseCheckData, + PartFieldCalculationData, FieldValueCalculationData, DummyEventData, EngineeringChangeReleaseData, @@ -48,6 +51,7 @@ "DocumentFieldCalculationEvent", "PartReleaseEvent", "PartReleaseCheckEvent", + "PartFieldCalculationEvent", "FieldValueCalculationEvent", "DummyEvent", "EngineeringChangeRelease", @@ -65,4 +69,5 @@ "WorkflowTaskTriggerEventData", "DocumentReleaseDialogData", "PartReleaseDialogData", + "PartFieldCalculationData", ] diff --git a/csfunctions/events/base.py b/csfunctions/events/base.py index 22bc50d..48f5e12 100644 --- a/csfunctions/events/base.py +++ b/csfunctions/events/base.py @@ -10,6 +10,7 @@ class EventNames(str, Enum): DOCUMENT_FIELD_CALCULATION = "document_field_calculation" PART_RELEASE = "part_release" PART_RELEASE_CHECK = "part_release_check" + PART_FIELD_CALCULATION = "part_field_calculation" ENGINEERING_CHANGE_RELEASE = "engineering_change_release" ENGINEERING_CHANGE_RELEASE_CHECK = "engineering_change_release_check" FIELD_VALUE_CALCULATION = "field_value_calculation" diff --git a/csfunctions/events/part_field_calculation.py b/csfunctions/events/part_field_calculation.py new file mode 100644 index 0000000..6f313fd --- /dev/null +++ b/csfunctions/events/part_field_calculation.py @@ -0,0 +1,20 @@ +from typing import Literal + +from pydantic import BaseModel, Field + +from csfunctions.objects import Document, Part + +from .base import BaseEvent, EventNames + + +class PartFieldCalculationData(BaseModel): + part: Part = Field(..., description="Current state of the part") + action: Literal["create", "modify", "copy", "index"] = Field(..., description="Action being performed") + + linked_documents: list[Document] = Field(..., description="List of documents that are referenced by the parts.") + linked_parts: list[Part] = Field(..., description="Related parts (e.g. source part)") + + +class PartFieldCalculationEvent(BaseEvent): + name: Literal[EventNames.PART_FIELD_CALCULATION] = EventNames.PART_FIELD_CALCULATION + data: PartFieldCalculationData diff --git a/json_schemas/request.json b/json_schemas/request.json index d254b91..2c9759b 100644 --- a/json_schemas/request.json +++ b/json_schemas/request.json @@ -2490,6 +2490,73 @@ "title": "Part", "type": "object" }, + "PartFieldCalculationData": { + "properties": { + "part": { + "$ref": "#/$defs/Part", + "description": "Current state of the part" + }, + "action": { + "description": "Action being performed", + "enum": [ + "create", + "modify", + "copy", + "index" + ], + "title": "Action", + "type": "string" + }, + "linked_documents": { + "description": "List of documents that are referenced by the parts.", + "items": { + "$ref": "#/$defs/Document" + }, + "title": "Linked Documents", + "type": "array" + }, + "linked_parts": { + "description": "Related parts (e.g. source part)", + "items": { + "$ref": "#/$defs/Part" + }, + "title": "Linked Parts", + "type": "array" + } + }, + "required": [ + "part", + "action", + "linked_documents", + "linked_parts" + ], + "title": "PartFieldCalculationData", + "type": "object" + }, + "PartFieldCalculationEvent": { + "properties": { + "name": { + "const": "part_field_calculation", + "default": "part_field_calculation", + "title": "Name", + "type": "string" + }, + "event_id": { + "description": "unique identifier", + "title": "Event Id", + "type": "string" + }, + "data": { + "$ref": "#/$defs/PartFieldCalculationData" + } + }, + "required": [ + "event_id", + "data" + ], + "title": "PartFieldCalculationEvent", + "type": "object" + }, "PartReleaseCheckData": { "properties": { "parts": { @@ -2823,6 +2890,7 @@ "engineering_change_release": "#/$defs/EngineeringChangeRelease", "engineering_change_release_check": "#/$defs/EngineeringChangeReleaseCheck", "field_value_calculation": "#/$defs/FieldValueCalculationEvent", + "part_field_calculation": "#/$defs/PartFieldCalculationEvent", "part_release": "#/$defs/PartReleaseEvent", "part_release_check": "#/$defs/PartReleaseCheckEvent", "workflow_task_trigger": "#/$defs/WorkflowTaskTriggerEvent" @@ -2845,6 +2913,9 @@ { "$ref": "#/$defs/PartReleaseCheckEvent" }, + { + "$ref": "#/$defs/PartFieldCalculationEvent" + }, { "$ref": "#/$defs/FieldValueCalculationEvent" }, From de3ff40774cec0a14c355215ca1b5cfc026f95c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Tue, 18 Mar 2025 12:41:29 +0100 Subject: [PATCH 3/5] remove unneeded linked parts and docs --- csfunctions/events/document_field_calculation.py | 1 - csfunctions/events/part_field_calculation.py | 1 - 2 files changed, 2 deletions(-) diff --git a/csfunctions/events/document_field_calculation.py b/csfunctions/events/document_field_calculation.py index 829db34..831f725 100644 --- a/csfunctions/events/document_field_calculation.py +++ b/csfunctions/events/document_field_calculation.py @@ -11,7 +11,6 @@ class DocumentFieldCalculationData(BaseModel): document: Document = Field(..., description="Current state of the document") action: Literal["create", "modify", "copy", "index"] = Field(..., description="Action being performed") linked_parts: list[Part] = Field(..., description="Parts that belong to the document") - linked_documents: list[Document] = Field(..., description="Related documents (e.g. source document)") class DocumentFieldCalculationEvent(BaseEvent): diff --git a/csfunctions/events/part_field_calculation.py b/csfunctions/events/part_field_calculation.py index 6f313fd..9e0f363 100644 --- a/csfunctions/events/part_field_calculation.py +++ b/csfunctions/events/part_field_calculation.py @@ -12,7 +12,6 @@ class PartFieldCalculationData(BaseModel): action: Literal["create", "modify", "copy", "index"] = Field(..., description="Action being performed") linked_documents: list[Document] = Field(..., description="List of documents that are referenced by the parts.") - linked_parts: list[Part] = Field(..., description="Related parts (e.g. source part)") class PartFieldCalculationEvent(BaseEvent): From 7b3df10d6847f595cc500e7be91985de1b924cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Wed, 19 Mar 2025 09:31:04 +0100 Subject: [PATCH 4/5] schemas --- json_schemas/request.json | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/json_schemas/request.json b/json_schemas/request.json index ad48cf8..4545a66 100644 --- a/json_schemas/request.json +++ b/json_schemas/request.json @@ -805,21 +805,12 @@ }, "title": "Linked Parts", "type": "array" - }, - "linked_documents": { - "description": "Related documents (e.g. source document)", - "items": { - "$ref": "#/$defs/Document" - }, - "title": "Linked Documents", - "type": "array" } }, "required": [ "document", "action", - "linked_parts", - "linked_documents" + "linked_parts" ], "title": "DocumentFieldCalculationData", "type": "object" @@ -2664,21 +2655,12 @@ }, "title": "Linked Documents", "type": "array" - }, - "linked_parts": { - "description": "Related parts (e.g. source part)", - "items": { - "$ref": "#/$defs/Part" - }, - "title": "Linked Parts", - "type": "array" } }, "required": [ "part", "action", - "linked_documents", - "linked_parts" + "linked_documents" ], "title": "PartFieldCalculationData", "type": "object" From 325f76cbf1aec3ed5e3238e60b103cc5392bc547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20K=C3=BCrten?= Date: Wed, 19 Mar 2025 09:46:51 +0100 Subject: [PATCH 5/5] add events to docs --- docs/reference/events.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/reference/events.md b/docs/reference/events.md index f1351a0..436cb1c 100644 --- a/docs/reference/events.md +++ b/docs/reference/events.md @@ -90,6 +90,26 @@ This event is fired **after** a document has been released. Raising an exception |cdb_ec_id|str \| None| Engineering Change ID| +## DocumentFieldCalculationEvent +`csfunctions.events.DocumentFieldCalculationEvent` + +This event is fired when a document is created, modified, copied or indexed. It is triggered after the field calculations defined in the datasheet editor are performed. + +The event expects a DataResponse containing a dictionary of field names and their new values. Fields that are not mentioned in the response are not updated. + + +**DocumentFieldCalculationEvent.name:** document_field_calculation + +**DocumentFieldCalculationEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|document|[Document](objects.md#document)|Current state of the document| +|action|Literal["create", "modify", "copy", "index"]|Action being performed| +|linked_parts|list[[Part](objects.md#part)]|Parts that belong to the document| + + + ## EngineeringChangeReleaseCheck `csfunctions.events.EngineeringChangeReleaseCheck` @@ -215,6 +235,24 @@ This event is fired **after** a part has been released. Raising an exception thu |cdb_ec_id|str \| None| Engineering Change ID| +## PartFieldCalculationEvent +`csfunctions.events.PartFieldCalculationEvent` + +This event is fired when a part is created, modified, copied or indexed. It is triggered after the field calculations defined in the datasheet editor are performed. + +The event expects a DataResponse containing a dictionary of field names and their new values. Fields that are not mentioned in the response are not updated. + +**PartFieldCalculationEvent.name:** part_field_calculation + +**PartFieldCalculationEvent.data:** + +|Attribute|Type|Description| +|-|-|-| +|part|[Part](objects.md#part)|Current state of the part| +|action|Literal["create", "modify", "copy", "index"]|Action being performed| +|linked_documents| list[[Document](objects.md#document)]|List of documents that belong to the part| + + ## WorkflowTaskTriggerEvent `csfunctions.events.WorkflowTaskTriggerEvent`