2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-11-30 01:10:00 +00:00

[plugin] Add printing delay to sample machines (#10873)

* [plugin] Add printing delay to sample machines

- Useful for testing
- Default is zero

* Add backup_value to MachineSetting.get_setting

* Fix call to machine.get_setting

* Fix for printing logic

* Simplify code
This commit is contained in:
Oliver
2025-11-21 14:56:23 +11:00
committed by GitHub
parent d5ee647c6e
commit f50d568b23

View File

@@ -1,5 +1,7 @@
"""Sample plugin for registering custom machines."""
import time
from django.db import models
import structlog
@@ -26,7 +28,14 @@ class SamplePrinterDriver(LabelPrinterBaseDriver):
'name': 'Connection String',
'description': 'Custom string for connecting to the printer',
'default': '123-xx123:8000',
}
},
'DELAY': {
'name': 'Print Delay',
'description': 'Delay (in seconds) before printing',
'default': 0,
'units': 'seconds',
'validator': int,
},
}
def init_machine(self, machine: BaseMachineType) -> None:
@@ -44,7 +53,14 @@ class SamplePrinterDriver(LabelPrinterBaseDriver):
**kwargs,
) -> None:
"""Send the label to the printer."""
print_delay = machine.get_setting('DELAY', 'D')
print('MOCK LABEL PRINTING:')
if print_delay > 0:
print(f' - Delaying for {print_delay} seconds...')
time.sleep(print_delay)
print('- machine:', machine)
print('- label:', label)
print('- item:', item)