Tool Replacement
Model
- class pytm4srv.models.tool.ToolReplacement
Represents one time a tool has been replaced.
- assembly_id: Mapped[int | None]
The ID of the assembly this tool belonged to at the time of replacement.
Will be NULL if the tool was not in an assembly at the time of replacement.
- condition: Mapped[int]
The specific condition of the tool prior to replacement.
This is a bitfield (of length 16), so multiple condition flags can be selected by combining their values with bitwise OR.
The following condition flags are supported:
Value
Binary
Description
0
0000 0000
(Not specified)
1
0000 0001
Snapped
2
0000 0010
Corner fracture
4
0000 0100
Side fracture
8
0000 1000
Large fracture
16
0001 0000
Normal wear
32
0010 0000
Could have run longer
- day_count: Mapped[int]
The day count at the time the tool was replaced.
- id: MappedColumn object at 0x782a7bd71d80>]]
Unique, numeric ID for this replacement in OnTakt.
- image: Mapped[bytes | None]
A user-provided image of this tool replacement.
- image_type: Mapped[str | None]
The MIME type of the file stored in
image
.
- indexed: Mapped[bool | None]
Whether the replacement was actually a tool index.
- inventory_item_id: Mapped[int | None]
The ID of the inventory item that was consumed when this replacement was created.
Used for comparing performance between interchangeable inventory items and undoing replacements.
Will be NULL for replacements before this column was added, replacements of tools without an inventory item assigned, and for replacements whose inventory items have since been deleted.
- inventory_point_id: Mapped[int | None]
ID of the inventory point this tool replacement came from.
Used for undoing replacements.
- life_record_id: Mapped[int | None]
The ID of the latest tool life record at the time of replacement.
This can be used to show the tool’s expected life fields at the time of replacement even if they have since changed.
- notes: Mapped[str]
Notes entered by the user when replacing the tool.
- parts: Mapped[Dict[str, int] | None]
The part count at the time the tool was replaced, broken down by program. The keys of this object will be program IDs and the values will be how many parts of that program this tool produced.
If
static_part_count
is greater than the sum of this object’s values, that means programs were unassigned from this tool between production and replacement, so we don’t know what programs they came from.
- process_id: Mapped[int | None]
The ID of the process this tool’s assembly belonged to at the time of replacement.
Will be NULL if the tool was not in an assembly or that assembly was not in use by a process at the time of replacement.
- reason: Mapped[int]
The reason for this tool replacement.
The following values are supported:
Value
Reason
Notes
0
Unspecified
condition
ornotes
may be used to provide more details.1
Broken
Tool is no longer usable.
2
Preemptive
Preemptive tool replacements are not considered when calculating average tool life.
3
Scheduled
Fixed schedule to reduce the effect of normal wear on part dimensions or finish.
- runtime: Mapped[timedelta]
The value of tool’s machining time counter at the time of replacement.
- static_part_count: Mapped[int]
The part count at the time the tool was replaced.
Does not change when parts/programs/etc are changed.
- substitute_id: Mapped[int | None]
The ID of the tool that replaced this one (for durable tools).
- testing: Mapped[bool]
Whether this tool replacement was a test of a new inventory item.
- testing_notes: Mapped[str | None]
Notes entered about what is being tested.
- timestamp: Mapped[datetime]
When the tool was replaced.
- tmac_job: Mapped[str | None]
The name of the TMAC job that was running when this tool was replaced.
- tool_id: Mapped[int]
The ID of the tool that was replaced.
- user_id: Mapped[int | None]
The ID of the user who replaced the tool.
Endpoints
- GET /api/tools/replacements/process/(int: process_id)
Get the data to chart the replacement history for all tools assigned to a process.
The output format is an object mapping tool ID to the Tool object, but with an added
replacements
field that is an object mapping tool replacement ID to ToolReplacement object.{ "17": { "id": 17, ..., "replacements": { "31895": { "id": 31895, "tool_id": 17, ... }, ... } }, ... }
It is strongly recommended to set
start
andend
as the returned data can get quite large and require several seconds to generate for large time spans.- Parameters:
process_id – the ID of the process to query
- Query Parameters:
start (int) – Optional, UNIX timestamp. Only replacements at or after this time will be returned
end (int) – Optional, UNIX timestamp. Only replacements at or before this time will be returned
- Returns:
an object mapping tool ID to replacement objects
- Status Codes:
404 Not Found – if the program doesn’t exist
- PATCH /api/tools/replacements/(int: repl_id)
Edit an existing tool replacement.
The request body should be a (partial) ToolReplacement object. Omitted fields will not be changed.
- Status Codes:
403 Forbidden – if the request is blocked from changing the replacement’s
testing
value404 Not Found – if the tool replacement does not exist
- DELETE /api/tools/replacements/(int: repl_id)
Delete a single tool replacement.
The current state of the tool will not be affected unless
undo
is set, in which case the replacement’s part count will be added to the tool’s part count and, if the tool was not indexed, one will be added back to the inventory point that was selected during replacement. This can only be used when deleting the most recent replacement of a given tool.- Query Parameters:
undo (int) – set to
1
to undo the replacement on the tool when deleting it
- Status Codes:
404 Not Found – if the replacement does not exist
409 Conflict – if
undo
was set but the tool has a more recent replacement202 Accepted – if
undo
was set but the tool for this replacement does not exist. This should be an impossible case as replacements are deleted with their tool.204 No Content – on success
- GET /api/tools/replacements/(int: obj_id)/image
Get the current image file of the ToolReplacement.
- Parameters:
obj_id – ID of the ToolReplacement to get the image for
- Status Codes:
200 OK – if the ToolReplacement exists and an image is set
404 Not Found – if the ToolReplacement does not exist
412 Precondition Failed – if the ToolReplacement exists but does not have an image
- Returns:
the image file, with the
Content-Type
header set to its MIME type
- POST /api/tools/replacements/(int: obj_id)/image
Upload a new image file for the ToolReplacement.
The request body should be an image file, and the
Content-Type
header should contain its MIME type.- Parameters:
obj_id – ID of the ToolReplacement to set the image for
- Status Codes:
200 OK – on success
404 Not Found – if the ToolReplacement does not exist
413 Request Entity Too Large – if the image file is larger than 5 MB
415 Unsupported Media Type – if the image file is invalid or of an unsupported type
- Returns:
the modified ToolReplacement
- DELETE /api/tools/replacements/(int: obj_id)/image
Remove the image from the ToolReplacement.
- Parameters:
obj_id – ID of the ToolReplacement to clear the image from
- Status Codes:
404 Not Found – if the ToolReplacement does not exist
200 OK – on success
- Returns:
the modified ToolReplacement