Print from linux server

Hi,

I’d like to be able to print automatically some documents when Shipment state changes.
The server is on linux. I’d like to call a command line to print the generated reports from the server. Could you please point me to an example or to the way to achieve this?

I would suggest to use the email notification using the email of the printer (now most of the printer has such service).

There are many examples on internet about commandline printing in Linux. The best way I think is to create a temporary PDF and use that to send to the printer using the commandline. When you use a trigger for the state change, it stays outside your workflow so when printing fails no problem.

You can use Python to execute the commandline command, so when a state changes, the trigger is called. That trigger will create the report and stores it somewhere in your filesystem. Then the trigger executes a commandline command to send the report to the printer.

So first thing I would do is search the internet. Then take a PDF file and try to send it to the printer. Next thing is integrating it with the trigger system in Tryton.

Yes, that’s for this part I was looking an example.
I think I’ll use something like

to send the report to local cups server, and something like ir/email_.py to generate the Report.

Sry, it won’t fit for me, because the printer is not on the same network, I can reach it only with cups/ipp, and I don’t see in its admin how to receive email. I must say I trust more ipp thant email to respond quickly.

I was more thinking about the convert function in trytond: a43357c36db9 trytond/report/report.py

What I’m thinking of:

  1. You have to create the template / report in the ‘normal’ way and make sure to have either Postscript or PDF as output extension.
  2. Create a function (Python code) which can be executed by the trigger.
  3. The function gets the template and knows the record(s) so it can generate the report.
  4. The rendered output is stored on disk.
  5. A Python subprocess executes the print command.

To generate the report you can use something like

        pool = Pool()
        Report = pool.get('ir.action.report')
        reports = Report.search([
                ('report_name', '=', 'account.invoice'),
                ])

        with Transaction().set_context(language=language):
            ext, content, _, title = Report.execute(
                [record.id], {
                    'action_id': report[0].id,
                    })

You get the contents back and using BytesIO you can store the report on disk. Then do something like in the convert function of trytond: a43357c36db9 trytond/report/report.py specific the cmd variable. Just play with it.

Here is an example how to add your function to the trigger. modules/notification_email: 32880f8ede99 ir.py
And your function can look like modules/notification_email: 32880f8ede99 notification.py

Maybe you can extend the ir.trigger with a Many2One which holds the report template.