Skip to content

Machine Mixin

MachineDriverMixin

The MachineDriverMixin class is used to implement custom machine drivers (or machine types) in InvenTree.

InvenTree supports integration with external machines, through the use of plugin-supplied device drivers.

get_machine_drivers

To register custom machine driver(s), the get_machine_drivers method must be implemented. This method should return a list of machine driver classes that the plugin supports.

Register custom machine drivers.

Source code in src/backend/InvenTree/plugin/base/integration/MachineMixin.py
39
40
41
def get_machine_drivers(self) -> list[BaseDriver]:
    """Register custom machine drivers."""
    return []

The default implementation returns an empty list, meaning no custom machine drivers are registered.

get_machine_types

To register custom machine type(s), the get_machine_types method must be implemented. This method should return a list of machine type classes that the plugin supports.

Register custom machine types.

Source code in src/backend/InvenTree/plugin/base/integration/MachineMixin.py
35
36
37
def get_machine_types(self) -> list[BaseMachineType]:
    """Register custom machine types."""
    return []

The default implementation returns an empty list, meaning no custom machine types are registered.

Sample Plugin

A sample plugin is provided which implements a simple label printing machine driver:

A very simple example of a 'printer' machine plugin.

This plugin class simply prints a message to the logger.

Source code in src/backend/InvenTree/plugin/samples/machines/sample_printer.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class SamplePrinterMachine(MachineDriverMixin, SettingsMixin, InvenTreePlugin):
    """A very simple example of a 'printer' machine plugin.

    This plugin class simply prints a message to the logger.
    """

    NAME = 'SamplePrinterMachine'
    SLUG = 'sample-printer-machine-plugin'
    TITLE = 'Sample dummy plugin for printing labels'

    VERSION = '0.1'

    def get_machine_drivers(self) -> list[BaseDriver]:
        """Return a list of drivers registered by this plugin."""
        return [SamplePrinterDriver]