forked from OCA/report-print-send
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.0][MIG] base_report_to_printer (OCA#68)
* 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
1 parent
0b4572f
commit 776f481
Showing
32 changed files
with
1,484 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
19 changes: 19 additions & 0 deletions
19
base_report_to_printer/migrations/9.0.2.0.0/post-10-create_server_record.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.