<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (c) 2007 <NAME> <<EMAIL>>
#    Copyright (c) 2009 <NAME> <<EMAIL>>
#    Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
#    Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
#    Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>)
#    All Rights Reserved
#
#    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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
import base64
from tempfile import mkstemp
import logging
import cups

from openerp.osv import orm, fields

#
# Reports
#

class report_xml(orm.Model):


    def set_print_options(self, cr, uid, report_id, format, context=None):
        """
        Hook to set print options
        """
        options = {}
        if format == 'raw':
            options['raw'] = True
        return options

    def print_direct(self, cr, uid, report_id, result, format, printer, context=None):
        user_obj = self.pool.get('res.users')
        fd, file_name = mkstemp()
        try:
            os.write(fd, base64.decodestring(result))
        finally:
            os.close(fd)
        printer_system_name = ''
        if printer:
            if isinstance(printer, (basestring)):
                printer_system_name = printer
            else:
                printer_system_name = printer.system_name
            connection = cups.Connection()

            options = self.set_print_options(cr, uid, report_id, format, context=context)

            connection.printFile(printer_system_name, file_name, file_name, options=options)
            logger = logging.getLogger('base_report_to_printer')
            logger.info("Printing job : '%s'" % file_name)
        return True

    _inherit = 'ir.actions.report.xml'
    _columns = {
        'property_printing_action': fields.property(
            #'ir.actions.report.xml',
            'printing.action',
            type='many2one',
            relation='printing.action',
            string='Action',
            view_load=True,
            method=True,
            ),
        'printing_printer_id': fields.many2one('printing.printer', 'Printer'),
        'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'),
        }

    def behaviour(self, cr, uid, ids, context=None):
        result = {}
        printer_obj = self.pool.get('printing.printer')
        printing_act_obj = self.pool.get('printing.report.xml.action')
        # Set hardcoded default action
        default_action = 'client'
        # Retrieve system wide printer
        default_printer = printer_obj.get_default(cr, uid, context=context)
        if default_printer:
            default_printer = printer_obj.browse(cr, uid, default_printer, context=context)


        # Retrieve user default values
        user = self.pool.get('res.users').browse(cr, uid, context)<commit_msg>[FIX] user browse was incorrect and never returned records. Fix based on the patch from <NAME> (etsinko)<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (c) 2007 <NAME> <<EMAIL>>
#    Copyright (c) 2009 <NAME> <<EMAIL>>
#    Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
#    Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
#    Copyright (C) 2013 Camptocamp (<http://www.camptocamp.com>)
#    All Rights Reserved
#
#    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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
import base64
from tempfile import mkstemp
import logging
import cups

from openerp.osv import orm, fields

#
# Reports
#

class report_xml(orm.Model):


    def set_print_options(self, cr, uid, report_id, format, context=None):
        """
        Hook to set print options
        """
        options = {}
        if format == 'raw':
            options['raw'] = True
        return options

    def print_direct(self, cr, uid, report_id, result, format, printer, context=None):
        fd, file_name = mkstemp()
        try:
            os.write(fd, base64.decodestring(result))
        finally:
            os.close(fd)
        printer_system_name = ''
        if printer:
            if isinstance(printer, (basestring)):
                printer_system_name = printer
            else:
                printer_system_name = printer.system_name
            connection = cups.Connection()

            options = self.set_print_options(cr, uid, report_id, format, context=context)

            connection.printFile(printer_system_name, file_name, file_name, options=options)
            logger = logging.getLogger('base_report_to_printer')
            logger.info("Printing job : '%s'" % file_name)
        return True

    _inherit = 'ir.actions.report.xml'
    _columns = {
        'property_printing_action': fields.property(
            #'ir.actions.report.xml',
            'printing.action',
            type='many2one',
            relation='printing.action',
            string='Action',
            view_load=True,
            method=True,
            ),
        'printing_printer_id': fields.many2one('printing.printer', 'Printer'),
        'printing_action_ids': fields.one2many('printing.report.xml.action', 'report_id', 'Actions', help='This field allows configuring action and printer on a per user basis'),
        }

    def behaviour(self, cr, uid, ids, context=None):
        result = {}
        printer_obj = self.pool.get('printing.printer')
        printing_act_obj = self.pool.get('printing.report.xml.action')
        # Set hardcoded default action
        default_action = 'client'
        # Retrieve system wide printer
        default_printer = printer_obj.get_default(cr, uid, context=context)
        if default_printer:
            default_printer = printer_obj.browse(cr, uid, default_printer, context=context)

        # Retrieve user default values
        user = self.pool.get('res.users').browse(
            cr, uid, [uid], context=context)[0]
{'fraction_non_alphanumeric': 0.1409145447273697, 'fraction_numerical': 0.007865617917610986, 'mean_word_length': 2.7679558011049723, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6066152', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2045, 'n_words': 609}