<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 <NAME>
#    (<http://www.savoirfairelinux.com>).
#
#    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 Affero 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 base64
from xlwt import Workbook, Formula, Font, XFStyle, Alignment, Borders, Pattern
from StringIO import StringIO

from openerp.osv import fields, orm
from openerp.tools.translate import _


class Cell(object):

    def __init__(self, text, font, alignment, border, pattern,
                 number_format_str='General', width=0x0E00, ):
        self.text = text
        self.font = font
        self.alignment = alignment
        self.border = border
        self.pattern = pattern
        self.style = XFStyle()
        self.style.font = self.font
        self.style.alignment = self.alignment
        self.style.borders = self.border
        self.style.pattern = self.pattern
        self.style.num_format_str = number_format_str
        self.width = width


class Column(Cell):
    title_fnt = Font()
    title_fnt.name = 'Calibri'
    title_fnt.bold = True
    title_fnt.height = 12 * 20  # font size 12

    obj_fnt = Font()
    obj_fnt.name = 'Calibri'
    obj_fnt.height = 12 * 20  # font size 12

    title_aln = Alignment()
    title_aln.horz = Alignment.HORZ_CENTER
    title_aln.vert = Alignment.VERT_CENTER
    title_aln.wrap = Alignment.WRAP_AT_RIGHT

    title_ptn = Pattern()
    title_ptn.pattern = Pattern.SOLID_PATTERN
    title_ptn.pattern_fore_colour = 0x2C

    def __init__(self, text, left_border=False, right_border=False,
                 use_pattern=False, width=0x0E00, func=lambda obj: ""):
        super(Column, self).__init__(
            text, self.title_fnt, self.title_aln, Borders(),
            self.title_ptn, width=width
        )
        self.obj_style = XFStyle()
        self.obj_style.alignment = self.title_aln

        self.obj_style.borders = Borders()
        self.obj_style.borders.left = Borders.HAIR
        self.obj_style.borders.right = Borders.HAIR
        self.obj_style.borders.top = Borders.HAIR
        self.obj_style.borders.bottom = Borders.HAIR
        self.border.left = Borders.HAIR
        self.border.right = Borders.HAIR
        self.border.top = Borders.THICK
        self.border.bottom = Borders.THICK

        if left_border:
            self.obj_style.borders.left = Borders.THICK
            self.border.left = Borders.THICK
        if right_border:
            self.obj_style.borders.right = Borders.THICK
            self.border.right = Borders.THICK

        self.obj_style.font = self.obj_fnt

        if use_pattern:
            self.obj_style.pattern = self.pattern

        self.func = func


class travel_summary(orm.TransientModel):
    _name = "travel.summary"
    _description = "Travel Journey Summary"
    _columns = {
        'travel_id': fields.many2one(
            'travel.travel', string="Travel", required=True),
        'excel_file': fields.binary('Report', readonly=True),
        'export_filename': fields.char('Export Filename', size=128),
    }
    _defaults = {
        'export_filename': lambda self, *a: self._get_filename(*a),
    }

    def _get_filename(self, cr, uid, ids, context=None):
        return _('travel_summary.xls')

    def get_excel_columns(self, context=None):
        return [
            Column(_('#'), left_border=True, width=0x0400),
            Column(_('NAME'), width=0x1000,
                   func=lambda obj: obj.passenger_id.partner_id.name),
            Column(_('CO.'), left_border=True, width=0x0700,
                   func=lambda obj: obj.company_get()),
            Column(_('Departure City'), left_border=True, width=0x1400,
                   func=lambda obj: obj.origin_get().name_get()[0][1]),
            Column(_('Departure Date'),
                   func=lambda obj: obj.departure_date_get()),
            Column(_('Departure Time'),
                   func=lambda obj: obj.departure_time_get()),
            Column(_('Arrival City'), width=0x1400,
                   func=lambda obj: obj.destination_get().name_get()[0][1]),
            Column(_('Arrival Date'),
                   func=lambda obj: obj.arrival_date_get()),
            Column(_('Arrival Time'),
                   func=lambda obj: obj.arrival_time_get()),
            Column(_('TICKET RATE'), left_border=True, use_pattern=True),
            Column(_('COSTS'), use_pattern=True),
            Column(_('TOTAL'), right_border=True, use_pattern=True),
        ]

    def export_excel(self, cr, uid, ids, context=None):
        """Export a journey summary an excel file

        This reopens the current wizard with a download link to the gathered
        data, instead of populating the tree view.
        """
        travel_smry_id = ids[0] if type(ids) is list else ids
        travel_smry_pool = self.pool.get('travel.summary')
        travel_smry = travel_smry_pool.browse(
            cr, uid, travel_smry_id, context=context)
        travel = travel_smry.travel_id
        output = StringIO()
        try:
            workbook = self.produce_summary(cr, uid, travel, context=context)
            workbook.save(output)
            self.write(cr, uid, ids, {
                'excel_file': base64.encodestring(output.getvalue()),
            }, context=context)
        finally:
            output.close()
<commit_msg>[FIX] origin_get() return a list and name_search doesn't exist anymore on v8 in the better.zip model<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 <NAME>
#    (<http://www.savoirfairelinux.com>).
#
#    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 Affero 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 base64
from xlwt import Workbook, Formula, Font, XFStyle, Alignment, Borders, Pattern
from StringIO import StringIO

from openerp.osv import fields, orm
from openerp.tools.translate import _


class Cell(object):

    def __init__(self, text, font, alignment, border, pattern,
                 number_format_str='General', width=0x0E00, ):
        self.text = text
        self.font = font
        self.alignment = alignment
        self.border = border
        self.pattern = pattern
        self.style = XFStyle()
        self.style.font = self.font
        self.style.alignment = self.alignment
        self.style.borders = self.border
        self.style.pattern = self.pattern
        self.style.num_format_str = number_format_str
        self.width = width


class Column(Cell):
    title_fnt = Font()
    title_fnt.name = 'Calibri'
    title_fnt.bold = True
    title_fnt.height = 12 * 20  # font size 12

    obj_fnt = Font()
    obj_fnt.name = 'Calibri'
    obj_fnt.height = 12 * 20  # font size 12

    title_aln = Alignment()
    title_aln.horz = Alignment.HORZ_CENTER
    title_aln.vert = Alignment.VERT_CENTER
    title_aln.wrap = Alignment.WRAP_AT_RIGHT

    title_ptn = Pattern()
    title_ptn.pattern = Pattern.SOLID_PATTERN
    title_ptn.pattern_fore_colour = 0x2C

    def __init__(self, text, left_border=False, right_border=False,
                 use_pattern=False, width=0x0E00, func=lambda obj: ""):
        super(Column, self).__init__(
            text, self.title_fnt, self.title_aln, Borders(),
            self.title_ptn, width=width
        )
        self.obj_style = XFStyle()
        self.obj_style.alignment = self.title_aln

        self.obj_style.borders = Borders()
        self.obj_style.borders.left = Borders.HAIR
        self.obj_style.borders.right = Borders.HAIR
        self.obj_style.borders.top = Borders.HAIR
        self.obj_style.borders.bottom = Borders.HAIR
        self.border.left = Borders.HAIR
        self.border.right = Borders.HAIR
        self.border.top = Borders.THICK
        self.border.bottom = Borders.THICK

        if left_border:
            self.obj_style.borders.left = Borders.THICK
            self.border.left = Borders.THICK
        if right_border:
            self.obj_style.borders.right = Borders.THICK
            self.border.right = Borders.THICK

        self.obj_style.font = self.obj_fnt

        if use_pattern:
            self.obj_style.pattern = self.pattern

        self.func = func


class travel_summary(orm.TransientModel):
    _name = "travel.summary"
    _description = "Travel Journey Summary"
    _columns = {
        'travel_id': fields.many2one(
            'travel.travel', string="Travel", required=True),
        'excel_file': fields.binary('Report', readonly=True),
        'export_filename': fields.char('Export Filename', size=128),
    }
    _defaults = {
        'export_filename': lambda self, *a: self._get_filename(*a),
    }

    def _get_filename(self, cr, uid, ids, context=None):
        return _('travel_summary.xls')

    def get_excel_columns(self, context=None):
        return [
            Column(_('#'), left_border=True, width=0x0400),
            Column(_('NAME'), width=0x1000,
                   func=lambda obj: obj.passenger_id.partner_id.name),
            Column(_('CO.'), left_border=True, width=0x0700,
                   func=lambda obj: obj.company_get()),
            Column(_('Departure City'), left_border=True, width=0x1400,
                   func=lambda obj: obj.origin_get()[0].display_name),
            Column(_('Departure Date'),
                   func=lambda obj: obj.departure_date_get()),
            Column(_('Departure Time'),
                   func=lambda obj: obj.departure_time_get()),
            Column(_('Arrival City'), width=0x1400,
                   func=lambda obj: obj.destination_get()[0].display_name),
            Column(_('Arrival Date'),
                   func=lambda obj: obj.arrival_date_get()),
            Column(_('Arrival Time'),
                   func=lambda obj: obj.arrival_time_get()),
            Column(_('TICKET RATE'), left_border=True, use_pattern=True),
            Column(_('COSTS'), use_pattern=True),
            Column(_('TOTAL'), right_border=True, use_pattern=True),
        ]

    def export_excel(self, cr, uid, ids, context=None):
        """Export a journey summary an excel file

        This reopens the current wizard with a download link to the gathered
        data, instead of populating the tree view.
        """
        travel_smry_id = ids[0] if type(ids) is list else ids
        travel_smry_pool = self.pool.get('travel.summary')
        travel_smry = travel_smry_pool.browse(
            cr, uid, travel_smry_id, context=context)
        travel = travel_smry.travel_id
        output = StringIO()
        try:
            workbook = self.produce_summary(cr, uid, travel, context=context)
            workbook.save(output)
            self.write(cr, uid, ids, {
                'excel_file': base64.encodestring(output.getvalue()),
            }, context=context)
        finally:
            output.close()

{'fraction_non_alphanumeric': 0.12670266784879503, 'fraction_numerical': 0.011203352945917627, 'mean_word_length': 2.5360501567398117, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3386115', 'n_tokens_mistral': 3826, 'n_tokens_neox': 3619, 'n_words': 887}