20% OFF UNTIL THE END OF THE YEAR Use Code: OFF20 for 20% Off!
We have a custom developed module where we want to enable automatic printing also. Can you support our development team so they will be able to implement this?

We have a custom developed module where we want to enable automatic printing also. Can you support our development team so they will be able to implement this?

If we do not have yet such a print scenario that you need, then for your developers it is rather simple to do by following steps below. We made our module to be very easy to adapt to your customizations.

In place inside your module where you want to print a document do the following:

  1. First insert below code to get current users printer and printer tray bin. It is needed to proceed with the printing. If the user has no printer defined – then there is not possible to print:

user = self.env.user
printer_id, printer_bin = user.get_report_printer(report.id)
  • report – object of type ir.actions.report. Corresponds to the printed report you are going to print

  1. After this just call printing like below. And you are all set!

options = {'bin': printer_bin} if printer_bin else {}
printer_id.printnode_print(
    report,
    objects,
    copies=1,
    options=options,
)
  • objects – is a list of any objects (browse records) for which you want to print a specified report. For example, a list of invoices / sales orders etc

  • report – object of type ir.actions.report. Corresponds to the printed report you are going to print

  • copies – this parameter allows you to specify number of copies to print

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *