[PORT] Finalize move of printer_tray to base_report_to_printer,

fix tests as report param is not a string but recordset
This commit is contained in:
Graeme Gellatly
2017-10-06 01:33:53 +13:00
55 changed files with 169 additions and 2654 deletions

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from . import ir_actions_report
from . import printing_action

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
@@ -14,12 +13,12 @@ class IrActionsReport(models.Model):
property_printing_action_id = fields.Many2one(
comodel_name='printing.action',
string='Action',
string='Default Behaviour',
company_dependent=True,
)
printing_printer_id = fields.Many2one(
comodel_name='printing.printer',
string='Printer'
string='Default Printer'
)
printer_tray_id = fields.Many2one(
comodel_name='printing.tray',
@@ -48,7 +47,7 @@ class IrActionsReport(models.Model):
report = self._get_report_from_name(report_name)
if not report:
return {}
result = report.behaviour()[report]
result = report.behaviour()
serializable_result = {
'action': result['action'],
'printer_name': result['printer'].name,
@@ -57,49 +56,34 @@ class IrActionsReport(models.Model):
@api.multi
def behaviour(self):
result = {}
self.ensure_one()
printer_obj = self.env['printing.printer']
printing_act_obj = self.env['printing.report.xml.action']
# Set hardcoded default action
default_action = 'client'
# Retrieve system wide printer
default_printer = printer_obj.get_default()
# Retrieve user default values
# Retrieve user defaults or system defaults
user = self.env.user
if user.printing_action:
default_action = user.printing_action
if user.printing_printer_id:
default_printer = user.printing_printer_id
action = user.printing_action or 'client'
printer = user.printing_printer_id or printer_obj.get_default()
for report in self:
action = default_action
printer = default_printer
# Retrieve report default values
report_action = self.property_printing_action_id
if report_action and report_action.action_type != 'user_default':
action = report_action.action_type
if self.printing_printer_id:
printer = self.printing_printer_id
# Retrieve report default values
report_action = report.property_printing_action_id
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
# Retrieve report-user specific values
print_action = printing_act_obj.search([
('report_id', '=', self.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default'),
], limit=1)
if print_action:
user_action = print_action.behaviour()
action = user_action['action']
if user_action['printer']:
printer = user_action['printer']
# Retrieve report-user specific values
print_action = printing_act_obj.search([
('report_id', '=', report.id),
('user_id', '=', self.env.uid),
('action', '!=', 'user_default'),
], limit=1)
if print_action:
user_action = print_action.behaviour()
action = user_action['action']
if user_action['printer']:
printer = user_action['printer']
result[report] = {
'action': action,
'printer': printer,
}
return result
return {'action': action, 'printer': printer}
@api.multi
def print_document(self, record_ids, data=None):
@@ -107,7 +91,7 @@ class IrActionsReport(models.Model):
document = self.with_context(
must_skip_send_to_printer=True).render_qweb_pdf(
record_ids, data=data)
behaviour = self.behaviour()[self]
behaviour = self.behaviour()
printer = behaviour['printer']
if not printer:
raise exceptions.Warning(
@@ -138,7 +122,7 @@ class IrActionsReport(models.Model):
document, doc_format = super(IrActionsReport, self).render_qweb_pdf(
docids, data=data)
behaviour = self.behaviour()[self]
behaviour = self.behaviour()
printer = behaviour['printer']
can_print_report = self._can_print_report(behaviour, printer, document)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
@@ -63,9 +62,20 @@ class PrintingPrinter(models.Model):
@api.multi
def _prepare_update_from_cups(self, cups_connection, cups_printer):
vals = super(PrintingPrinter, self)._prepare_update_from_cups(
cups_connection, cups_printer)
mapping = {
3: 'available',
4: 'printing',
5: 'error'
}
vals = {
'name': cups_printer['printer-info'],
'model': cups_printer.get('printer-make-and-model', False),
'location': cups_printer.get('printer-location', False),
'uri': cups_printer.get('device-uri', False),
'status': mapping.get(cups_printer.get(
'printer-state'), 'unknown'),
'status_message': cups_printer.get('printer-state-message', ''),
}
printer_uri = cups_printer['printer-uri-supported']
printer_system_name = printer_uri[printer_uri.rfind('/') + 1:]
ppd_info = cups_connection.getPPD3(printer_system_name)
@@ -104,25 +114,6 @@ class PrintingPrinter(models.Model):
for tray in self.tray_ids.filtered(
lambda record: record.system_name not in cups_trays.keys())
])
return vals
@api.multi
def _prepare_update_from_cups(self, cups_connection, cups_printer):
mapping = {
3: 'available',
4: 'printing',
5: 'error'
}
vals = {
'name': cups_printer['printer-info'],
'model': cups_printer.get('printer-make-and-model', False),
'location': cups_printer.get('printer-location', False),
'uri': cups_printer.get('device-uri', False),
'status': mapping.get(cups_printer.get(
'printer-state'), 'unknown'),
'status_message': cups_printer.get('printer-state-message', ''),
}
return vals
@api.multi

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2007 Ferran Pegueroles <ferran@pegueroles.com>
# Copyright (c) 2009 Albert Cervera i Areny <albert@nan-tic.com>
# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
@@ -33,6 +32,17 @@ class ResUsers(models.Model):
domain="[('printer_id', '=', printing_printer_id)]",
)
@api.model
def _register_hook(self):
self.SELF_WRITEABLE_FIELDS.extend([
'printing_action',
'printing_printer_id',
])
self.SELF_READABLE_FIELDS.extend([
'printing_action',
'printing_printer_id',
])
@api.onchange('printing_printer_id')
def onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """