Skip to content

Commit

Permalink
[10.0][MIG] base_report_to_printer (OCA#68)
Browse files Browse the repository at this point in the history
* Set api.multi for action called as `object` on view

* Merge syleam printers module into base_report_to_printer (OCA#60)

* [IMP] Updated unit tests

* [FIX] Fixed renamed attributes

* [FIX] Remove deleted fields

* [IMP] Add printing.server and printing.job models

* [IMP] Allow to cancel all jobs, enable, and disable printers

* [IMP] Split the cups part of print_document into a new print_file method

* [IMP] Updated cron job to run the action_update_jobs method

* [ADD] Add a migration script to create a printing server from configuration

* [MIG] Migrate base_report_to_printer to v10.0

Removed deprecated methods on printing.printer (replaced by methods on
        printing.server)

* [IMP] Add wkhtmltopdf in travis configuration file

* [FIX] base_report_to_printer: Fix Update Job Cron
* Fix API issue with Update Job Cron
** Forward Port from 9.0

* [FIX] Fixed the res.users view

The string attribute should not be used as a selector, because it is
translatable.

* [FIX] Fixed the print_document method of report

The new API migration was made to @api.multi because of the "cr, uid,
ids" signature, but "ids" was the ids of the records to print here, not
the report's ids.
Also, the new API version of "get_pdf" get directly the ids of the
records to print in the standard module, not a recordset.

* [FIX] UI is now (un)blocked only when using qweb-pdf reports in standard addons
  • Loading branch information
Sylvain Garancher authored and john-herholz-dt committed Mar 8, 2024
1 parent fe2015b commit ed27efa
Show file tree
Hide file tree
Showing 32 changed files with 1,484 additions and 419 deletions.
1 change: 1 addition & 0 deletions base_report_to_printer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Contributors
* Lionel Sausin <ls@numerigraphe.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Dave Lasley <dave@laslabs.com>
* Sylvain Garancher <sylvain.garancher@syleam.fr>

Maintainer
----------
Expand Down
6 changes: 4 additions & 2 deletions base_report_to_printer/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{
'name': "Report to printer",
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Generic Modules/Base',
'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" LasLabs, Odoo Community Association (OCA)",
Expand All @@ -20,12 +20,14 @@
'security/security.xml',
'views/assets.xml',
'views/printing_printer_view.xml',
'views/printing_server.xml',
'views/printing_job.xml',
'views/printing_report_view.xml',
'views/res_users_view.xml',
'views/ir_actions_report_xml_view.xml',
'wizards/printing_printer_update_wizard_view.xml',
],
'installable': False,
'installable': True,
'application': True,
'external_dependencies': {
'python': ['cups'],
Expand Down
56 changes: 28 additions & 28 deletions base_report_to_printer/data/printing_data.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?xml version="1.0"?>
<odoo noupdate="1">

<!-- printing.action -->
<record model="printing.action" id="printing_action_1">
<field name="name">Send to Printer</field>
<field name="type">server</field>
</record>
<record model="printing.action" id="printing_action_2">
<field name="name">Send to Client</field>
<field name="type">client</field>
</record>
<!-- properties -->
<record forcecreate="True" id="property_printing_action_id" model="ir.property">
<field name="name">property_printing_action_id</field>
<field name="fields_id" search="[('model','=','ir.actions.report.xml'),('name','=','property_printing_action_id')]"/>
<field name="value" eval="'printing.action,'+str(printing_action_2)"/>
</record>

<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
<field name="name">Update Printers Status</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'printing.printer'" name="model"/>
<field eval="'update_printers_status'" name="function"/>
<field eval="'()'" name="args"/>
</record>
<!-- printing.action -->
<record model="printing.action" id="printing_action_1">
<field name="name">Send to Printer</field>
<field name="action_type">server</field>
</record>
<record model="printing.action" id="printing_action_2">
<field name="name">Send to Client</field>
<field name="action_type">client</field>
</record>
<!-- properties -->
<record forcecreate="True" id="property_printing_action_id" model="ir.property">
<field name="name">property_printing_action_id</field>
<field name="fields_id" search="[('model', '=', 'ir.actions.report.xml'), ('name', '=', 'property_printing_action_id')]"/>
<field name="value" eval="'printing.action,' + str(printing_action_2)"/>
</record>

<record forcecreate="True" id="ir_cron_update_printers" model="ir.cron">
<field name="name">Update Printers Jobs</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'printing.server'" name="model"/>
<field eval="'action_update_jobs'" name="function"/>
<field eval="'()'" name="args"/>
</record>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import SUPERUSER_ID, api
from openerp.tools.config import config

__name__ = 'Create a printing.server record from previous configuration'


def migrate(cr, v):
with api.Environment.manage():
uid = SUPERUSER_ID
env = api.Environment(cr, uid, {})
env['printing.server'].create({
'name': config.get('cups_host', 'localhost'),
'address': config.get('cups_host', 'localhost'),
'port': config.get('cups_port', 631),
})
2 changes: 2 additions & 0 deletions base_report_to_printer/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from . import ir_actions_report_xml
from . import printing_action
from . import printing_job
from . import printing_printer
from . import printing_server
from . import printing_report_xml_action
from . import report
from . import res_users
6 changes: 3 additions & 3 deletions base_report_to_printer/models/ir_actions_report_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api
from odoo import models, fields, api


class IrActionsReportXml(models.Model):
Expand Down Expand Up @@ -73,8 +73,8 @@ def behaviour(self):

# Retrieve report default values
report_action = report.property_printing_action_id
if report_action and report_action.type != 'user_default':
action = report_action.type
if report_action and report_action.action_type != 'user_default':
action = report_action.action_type
if report.printing_printer_id:
printer = report.printing_printer_id

Expand Down
24 changes: 13 additions & 11 deletions base_report_to_printer/models/printing_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api


@api.model
def _available_action_types(self):
return [('server', 'Send to Printer'),
('client', 'Send to Client'),
('user_default', "Use user's defaults"),
]
from odoo import models, fields, api


class PrintingAction(models.Model):
_name = 'printing.action'
_description = 'Print Job Action'

@api.model
def _available_action_types(self):
return [
('server', 'Send to Printer'),
('client', 'Send to Client'),
('user_default', "Use user's defaults"),
]

name = fields.Char(required=True)
type = fields.Selection(
lambda s: _available_action_types(s),
action_type = fields.Selection(
selection=_available_action_types,
string='Type',
required=True,
oldname='type'
)
107 changes: 107 additions & 0 deletions base_report_to_printer/models/printing_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
from odoo import models, fields, api

_logger = logging.getLogger(__name__)


class PrintingJob(models.Model):
_name = 'printing.job'
_description = 'Printing Job'
_order = 'job_id_cups DESC'

name = fields.Char(help='Job name.')
active = fields.Boolean(
default=True, help='Unchecked if the job is purged from cups.')
job_id_cups = fields.Integer(
string='Job ID', required=True,
help='CUPS id for this job.')
server_id = fields.Many2one(
comodel_name='printing.server', string='Server',
related='printer_id.server_id', store=True,
help='Server which hosts this job.')
printer_id = fields.Many2one(
comodel_name='printing.printer', string='Printer', required=True,
ondelete='cascade', help='Printer used for this job.')
job_media_progress = fields.Integer(
string='Media Progress', required=True,
help='Percentage of progress for this job.')
time_at_creation = fields.Datetime(
required=True, help='Date and time of creation for this job.')
time_at_processing = fields.Datetime(
help='Date and time of process for this job.')
time_at_completed = fields.Datetime(
help='Date and time of completion for this job.')
job_state = fields.Selection(selection=[
('pending', 'Pending'),
('pending held', 'Pending Held'),
('processing', 'Processing'),
('processing stopped', 'Processing Stopped'),
('canceled', 'Canceled'),
('aborted', 'Aborted'),
('completed', 'Completed'),
('unknown', 'Unknown'),
], string='State', help='Current state of the job.')
job_state_reason = fields.Selection(selection=[
('none', 'No reason'),
('aborted-by-system', 'Aborted by the system'),
('compression-error', 'Error in the compressed data'),
('document-access-error', 'The URI cannot be accessed'),
('document-format-error', 'Error in the document'),
('job-canceled-at-device', 'Cancelled at the device'),
('job-canceled-by-operator', 'Cancelled by the printer operator'),
('job-canceled-by-user', 'Cancelled by the user'),
('job-completed-successfully', 'Completed successfully'),
('job-completed-with-errors', 'Completed with some errors'),
('job-completed(with-warnings', 'Completed with some warnings'),
('job-data-insufficient', 'No data has been received'),
('job-hold-until-specified', 'Currently held'),
('job-incoming', 'Files are currently being received'),
('job-interpreting', 'Currently being interpreted'),
('job-outgoing', 'Currently being sent to the printer'),
('job-printing', 'Currently printing'),
('job-queued', 'Queued for printing'),
('job-queued-for-marker', 'Printer needs ink/marker/toner'),
('job-restartable', 'Can be restarted'),
('job-transforming', 'Being transformed into a different format'),
('printer-stopped', 'Printer is stopped'),
('printer-stopped-partly',
'Printer state reason set to \'stopped-partly\''),
('processing-to-stop-point',
'Cancelled, but printing already processed pages'),
('queued-in-device', 'Queued at the output device'),
('resources-are-not-ready',
'Resources not available to print the job'),
('service-off-line', 'Held because the printer is offline'),
('submission-interrupted', 'Files were not received in full'),
('unsupported-compression', 'Compressed using an unknown algorithm'),
('unsupported-document-format', 'Unsupported format'),
], string='State Reason', help='Reason for the current job state.')

_sql_constraints = [
('job_id_cups_unique', 'UNIQUE(job_id_cups, server_id)',
'The id of the job must be unique per server !'),
]

@api.multi
def action_cancel(self):
self.ensure_one()
return self.cancel()

@api.multi
def cancel(self, purge_job=False):
for job in self:
connection = job.server_id._open_connection()
if not connection:
continue

connection.cancelJob(job.job_id_cups, purge_job=purge_job)

# Update jobs' states info Odoo
self.mapped('server_id').update_jobs(
which='all', first_job_id=job.job_id_cups)

return True
Loading

0 comments on commit ed27efa

Please sign in to comment.