# -*- coding: utf-8 -*- ############################################################################## # # Copyright (c) 2007 Ferran Pegueroles # Copyright (c) 2009 Albert Cervera i Areny # Copyright (C) 2011 Agile Business Group sagl () # Copyright (C) 2011 Domsense srl () # Copyright (C) 2013-2014 Camptocamp () # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## import logging from openerp import models, fields, api _logger = logging.getLogger('base_report_to_printer') class ReportXml(models.Model): """ Reports """ _inherit = 'ir.actions.report.xml' property_printing_action = fields.Many2one( comodel_name='printing.action', string='Action', company_dependent=True, ) printing_printer_id = fields.Many2one( comodel_name='printing.printer', string='Printer' ) printing_action_ids = fields.One2many( comodel_name='printing.report.xml.action', inverse_name='report_id', string='Actions', help='This field allows configuring action and printer on a per ' 'user basis' ) @api.multi def behaviour(self): result = {} 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 user = self.env.user if user.printing_action: default_action = user.printing_action if user.printing_printer_id: default_printer = user.printing_printer_id for report in self: action = default_action printer = default_printer # Retrieve report default values report_action = report.property_printing_action if report_action and report_action.type != 'user_default': action = report_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', '=', 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.id] = {'action': action, 'printer': printer, } return result