<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/>.
#
##############################################################################

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


class travel_passenger(orm.Model):
    """Passenger on travel"""
    _description = _(__doc__)
    _name = 'travel.passenger'
    _inherit = ['mail.thread']
    _rec_name = 'partner_id'
    _columns = {
        'partner_id': fields.many2one(
            'res.partner', 'Partner', required=True, ondelete='cascade',
            help="Name of Passenger."),
        'travel_id': fields.many2one(
            'travel.travel', 'Travel',
            help='Travel for which the passenger is participating.'),
        'travel_name': fields.related(
            'travel_id', 'name', type='char', string='Travel'),
        'travel_state': fields.related(
            'travel_id', 'state', type='selection', string='State'),
    }

    def name_get(self, cr, uid, ids, context=None):
        if type(ids) is not list:
            ids = [ids]
        return [(i.id, i.partner_id.name_get()[0][1])
                for i in self.browse(cr, uid, ids, context=context)]

    def action_passenger_form_view(self, cr, uid, ids, context=None):
        """Call action, if there is a travel, put it in the name."""
        if type(ids) is not list:
            ids = [ids]
        travels = self.browse(cr, uid, ids, context=context)
        travel_name = ('%s / %s ' % (travels[0].travel_id.name,
                                     travels[0].name_get()[0][1])
                       if len(travels) == 1 else False)
        name = travel_name or _('Passenger')
        return {
            'name': name,
            'res_model': 'travel.passenger',
            'view_mode': 'form',
            'type': 'ir.actions.act_window',
            'target': 'new',
            'res_id': ids[0],
            'context': context,
        }

    def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
        """Placeholder function to be inherited"""
        res = {}
        return res<commit_msg>Set up context to send travel dates into passengers form<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2010 - 2014 Savoir-faire Linux
#    (<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/>.
#
##############################################################################

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


class travel_passenger(orm.Model):
    """Passenger on travel"""
    _description = _(__doc__)
    _name = 'travel.passenger'
    _inherit = ['mail.thread']
    _rec_name = 'partner_id'
    _columns = {
        'partner_id': fields.many2one(
            'res.partner', 'Partner', required=True, ondelete='cascade',
            help="Name of Passenger."),
        'travel_id': fields.many2one(
            'travel.travel', 'Travel',
            help='Travel for which the passenger is participating.'),
        'travel_name': fields.related(
            'travel_id', 'name', type='char', string='Travel'),
        'travel_state': fields.related(
            'travel_id', 'state', type='selection', string='State'),
    }

    def name_get(self, cr, uid, ids, context=None):
        if type(ids) is not list:
            ids = [ids]
        return [(i.id, i.partner_id.name_get()[0][1])
                for i in self.browse(cr, uid, ids, context=context)]

    def action_passenger_form_view(self, cr, uid, ids, context=None):
        """Call action, if there is a travel, put it in the name."""
        if not ids:
            return {}
        if type(ids) is not list:
            ids = [ids]
        passenger = self.browse(cr, uid, ids, context=context)[0]
        travel = passenger.travel_id
        travel_name = ('%s / %s ' % (travel.name, passenger.name_get()[0][1]))
        name = travel_name or _('Passenger')
        context['default_date_start'] = travel.date_start
        context['default_date_stop'] = travel.date_stop
        return {
            'name': name,
            'res_model': 'travel.passenger',
            'view_mode': 'form',
            'type': 'ir.actions.act_window',
            'target': 'new',
            'res_id': ids[0],
            'context': context,
        }

    def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
        """Placeholder function to be inherited"""
        res = {}
        return res
{'fraction_non_alphanumeric': 0.1649804177545692, 'fraction_numerical': 0.006201044386422976, 'mean_word_length': 2.66566985645933, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2237248', 'n_tokens_mistral': 1779, 'n_tokens_neox': 1693, 'n_words': 552}