Skip to content

[FR] Support multiple Label printers within the same label plugin #4789

Closed

Description

@wolflu05

Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find a similar feature request

Problem statement

The current label printing system is not very scalable in larger environments with multiple printers of the same brand because each plugin only has the ability to expose one printer.

Suggested solution

The current system has a huge downside. Every plugin can only provide one printer. I thought very long about how we can fix that system without the downsides listed in alternatives I've already considered. This is my final concept:

💡 The idea

  1. We add a new PrintingDriverMixin which lets the developer define needed settings for each (physical) printer. That should work somehow the same way as the current SettingsMixin, but is scoped to a specific (physical) printer
  2. InvenTree settings get a new Tab Printers to manage printers. We should think about a printing plugin more like a provided printing driver than just a function. In that tab we can manage printers. A printer has the following attributes:
    • name
    • driver (select field - plugin that provides that driver)
    • defined config for that specific printer (specified in 1)
    • (scopes)
    • ...
  3. We add printers by giving it a name, selecting a driver and fill out the driver specific settings
  4. When printing we can choose between all created printers. The printing plugin then gets called with the pdf that needs to be printed and the Printer model which contains the printer specific settings.

This changes the way printing plugins work, so we need some migration period to allow the migrating of the old LabelPrintingMixin plugins.

🚀 Future ideas

This enables us much more possibilities in the future:

  • printers can be sorted based on priority for a specific label that need to be printed (e.g. that paper box labels are printed with a different printer than labels for magazine boxes)
  • printers can be scoped to locations, categories, ... (you're most like not using a printer that is in Fab1 while you are in Fab2)

👍 Advantages

  • ✅ Easily scaleable for large environments
  • ✅ Not every developer has to think about handling multiple printers on themself

Describe alternatives you've considered

  1. Allow plugins to be instantiated multiple times with different settings (Ref: [FR] Create multiple instances of a plugin #3568)
    • ❌ not very durable and can cause many bugs
  2. Allow plugins to expose multiple printers
    • ❌ every printer plugin dev needs to handle multiple printers support on their own

Examples of other systems

No response

Do you want to develop this?

  • I want to develop this.

Activity

  1. added
    enhancement
    triage:not-checked
    plugin
    on May 7, 2023
  2. removed
    triage:not-checked
    on May 7, 2023
  3. SchrodingersGat commented on May 8, 2023

    @SchrodingersGat
    Member

    On the face of it, this approach seems a bit "heavy handed". For discussion, I'd like to propose a simpler alternative.

    Each LabelPrintingMixin plugin exposes a method get_printers() which returns a list of names of available printers. These can be enumerated in whatever way the individual plugin wants. By default, the get_printers() plugin returns a single printer, as the current implementation, so existing printer plugins are not impacted.

    So a plugin may decide it wants to expose multiple printers, and can also decide how to name them for the user to select. Then the printers are exposed to the user in the current fashion.

    This does not provide advanced functionality like print queues / scopes / advanced generic configuration. But it would be much simpler to implement.

    I'm not sure how much effort to put into advanced printing functionality - how widely is this being used?

  4. wolflu05 commented on May 8, 2023

    @wolflu05
    MemberAuthor

    I also considered this approach (Alternative 2), but the big downside is that every plugin dev has to deal with the same problem. Every developer has to somehow save the available printers in the database create an own user interface for managing printers which can be different from plugin to plugin. Also scopes and filtering will be much more difficult to implement. I like the centralized idea so I would like to try work on implementing my suggested solution if you think this is just not prio for you but also like the idea. But I'm curious what matmair thinks. Because I think printing is one of the key functionalities of inventree.

  5. matmair commented on May 8, 2023

    @matmair
    Member

    I would like to have proper machine (in this case printers) management and would like to work on this if @wolflu05 is not taking dips. A first implementation could be pretty simple. I am imagining something like the notification method registry. That works pretty great IMO. Something like this but for machines, with plugins providing drivers for the different machines. The new printing plugin would then implement a base LabelPrintingDriver - who's core function is the same printing function as current. The internal APIs from other parts of InvenTree need to change very little to support this.

    The steps for implementing this would be:

    • Add a registry for Drivers
    • Add a model for holding machine configs (just like InvenTreePlugins and PluginConfigs work)
    • Add a BaseDriver
    • Add a BaseLabelPrintingDriver
    • Add management APIs and an API driven ui for machines (of all types)

    @SchrodingersGat what do you think?

  6. matmair commented on May 8, 2023

    @matmair
    Member

    Suggested name change by @wolflu05 is 'Driver' - which I find more fitting than Macine. The function remains the same. I edited my suggestion acordingly.

  7. wolflu05 commented on May 8, 2023

    @wolflu05
    MemberAuthor
    1. Can you maybe point out the differences to my approach a bit more?

    No real difference, just a bit larger target market

    1. So do I get this right, your machines are a second, different type of „plugins“ that can’t be used together. E.g. use the current settings mixin, app mixin with a machine?

    Not really, it would be physical devices on a network/bus controlled via InvenTree. Using m2m protocols like MQTT for example

    1. And regarding implementation, I‘d got a bit more comfortable with Django and thought this could be my first try for a bigger feature, but if you say you want to develop that now, go ahead, you know the codebase better than I. I don’t think I can get your approach with that new type of plugin registry to work clean.

    I do not have any hurry. How about you implement something and I build on it? Or would you be up to pair/co-coding it? I have so much open issues, I am fine not doing this

    1. Can you maybe also explain more how you imagine your PnP machine to integrate with this new machine registry, maybe this explains your general thoughts more.

    The 'Machine' in InvenTree would be a virtual representation of the real thing that saves state and can issue commands. So for the PnP example: The machine would be instructed to send state updates via some way - probably a MQTT adapter. InvenTree would receive those and for example, register newly build boards or set a test result on a stock item etc. When a board is build the PnP could wait for a command to start the next job, move the conveyor etc. InvenTree would issue that command via MQTT after it has checked that more boards are needed

    1. are individual settings for each machine defined at the machine type also included in your idea? And how do you imagine the userinteface, we click on a button add machine, then Chose machine type (pnp, printer, …) and then select an available driver? (Btw I kind of like that name to call them „driver“) and then enter the driver required settings like ip address, username, …

    That sums it up well. The Machine would probably support a subset of plugin mixins. Driver sounds fine

    (quoted sentences are answers from @matmair )

  8. wolflu05 commented on May 8, 2023

    @wolflu05
    MemberAuthor
    1. I meant from the python implementation side
    2. That sounds like a good plan. I'll start and may ask you if I have a specific question. Maybe good for beginning would be to create a basic interactive draft with something like figma.
    3. I'm not sure if we should call it a driver registry. I actually liked the name machine registry that stores machine configs, but I think the thing that creates the bridge between the machine API and inventree should be called driver. I'm not sure how good that is in term of naming conventions and consistency.

    new question

    6.Where do you want that implementation to live? Distributed via pypi? What are the advantages, that would complicate things more I guess. Shouldn't that be its own Django app in core?

  9. matmair commented on May 8, 2023

    @matmair
    Member
    1. The machine/driver could probably use some methods like settings as pointed out in 5. I do not think every mixin makes sense
    2. The backend is probably a lot simpler than the UI, I imagine it being similar to MethodStorageClass and NotificationMethod. The only thing I know about figma is that they belong to Adobe - If it can help why not
    3. We can also call it a machine registry. I am not too hawkish on any name rn. The nomenclature should probably be Machine => 1 instance (in database) of a thing that needs a Driver that facilitates communication between the Inventree Machine and real-world Machine ie thing

    New Question

    1. There was no positive feedback from the maintainer. I think we should wait at least a few days for feedback on the points brought up. I would like to see it in core. It could live in a plugin too. There is no real downside to that (except maybe for some install hurtles)
  10. SchrodingersGat commented on May 9, 2023

    @SchrodingersGat
    Member

    As discussed over on discord, @wolflu05 if you want to take the lead on this I'd be happy to review and assist :)

  11. wolflu05 commented on May 9, 2023

    @wolflu05
    MemberAuthor

    I'd made a first interactive (click on the add printer button) draft with penpot of how the userinterface could look like. What approach do you think would be the best (V1,V2 or V3)? (Versions can be selected in the top bar)

    I also thought a bit more about the plugin system implementation and think that the current mixins doesn't make sense to be used with a machine, which would enable use to only discover drivers and there is no need to activate them like a plugin inoder to see them appearing in the machine driver selection. So the InvenTreePlugin class is not needed for a machine. I image the API like the following. What do you think?

    from zebra import ZebraPrinter # dummy zebra library
    
    # InvenTree driver libs
    from machines import BaseDriver
    from machines.mixins import PrintingDriverMixin
    
    class ZebraPrinterDriver(PrintingDriverMixin, BaseDriver):
        """Zebra label printing machine driver"""
    
        NAME = "Zebra printing driver"
        VERSION = "1.0"
        AUTHOR = "wolflu05"
    
        def print_page(self, machine, pdf_data):
            """Send the label to the printer"""
            zebra_printer = ZebraPrinter(ip=machine.settings.ip, user=machine.settings.ip)
            zebra_printer.print(pdf_data)
  12. matmair commented on May 9, 2023

    @matmair
    Member

    @wolflu05 nice tool. I think V1 is the cleanes / easiest to work with.
    As for the python code: I think the notification methods are pretty much how it could work. So a plugin would hold 1+ Drivers, discovered via inheritance. Maybe take a look at this. I think Drivers could work this way. That would enable global settings for a driver (via plugin settings) and per-machine settings.

  13. wolflu05 commented on May 10, 2023

    @wolflu05
    MemberAuthor

    This is much better. Thank you I'll take a look at that part - haven't looked into notifications yet.

  14. 6 remaining items

  15. removed
    inactive
    on Jul 10, 2023
  16. github-actions commented on Sep 9, 2023

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  17. added
    inactive
    on Sep 9, 2023
  18. wolflu05 commented on Sep 9, 2023

    @wolflu05
    MemberAuthor

    In development at #4824, currently waiting on PUI and a few missing methods in the form framework.

  19. removed
    inactive
    on Sep 10, 2023
  20. github-actions commented on Nov 9, 2023

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  21. added
    inactive
    on Nov 9, 2023
  22. wolflu05 commented on Nov 9, 2023

    @wolflu05
    MemberAuthor

    Currently in development and making some progress with the Machine admin in PUI. (#4824)

  23. removed
    inactive
    on Nov 10, 2023
  24. github-actions commented on Jan 9, 2024

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  25. added
    inactive
    on Jan 9, 2024
  26. self-assigned this
    on Jan 9, 2024
  27. wolflu05 commented on Jan 9, 2024

    @wolflu05
    MemberAuthor

    Still wip in #4824, I now self assigned me this.

  28. removed
    inactive
    on Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementplugin

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions