<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2013 <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 datetime import datetime
from openerp import fields, models, api, _
from openerp.tools.misc import (
    DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DEFAULT_SERVER_TIME_FORMAT,
)

import logging
_logger = logging.getLogger(__name__)


class TravelJourney(models.Model):

    """Journey of travel"""
    _name = 'travel.journey'
    _description = _(__doc__)
    _journey_type_classes = {}
    _rec_name = 'destination'

    @staticmethod
    def _check_dep_arr_dates(departure, arrival):
        return not departure or not arrival or departure <= arrival
    
    @api.one
    def _estimate_datetime(self, field_name):
        """If there is no start date from journey, get it from travel"""
        res = {}
        date = False

        if self.journey_type:
            try:
                journey_class = self._journey_type_classes[self.journey_type]
                date = journey_class._estimate_typed_date(
                    self, self, field_name)
            except KeyError:
                _logger.error(
                    _('Transportation type "%s" has not registered its '
                      'class in _journey_types, skipping its dates')
                    % self.journey_type)
            except AttributeError:
                _logger.error(
                    _('Transportation type "%s" has not registered a '
                      '_estimate_typed_date() function, skipping its '
                      'dates')
                    % self.journey_type)
        if field_name == 'date_start':
            date = (date or self.departure or
                    self.passenger_id.travel_id.date_start)
        elif field_name == 'date_stop':
            date = (date or self.arrival or
                    self.passenger_id.travel_id.date_stop)
        # Make sure every date is in datetime format and not simply date
        try:
            date = datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
        except ValueError:
            date = datetime.strptime(date, DEFAULT_SERVER_DATETIME_FORMAT)
        res[self.id] = date
        
        return res

    @api.one
    def _estimate_date(self, field_name):
        datetimes = self._estimate_datetime(field_name)
        return {
            i: datetimes[i].strftime(DEFAULT_SERVER_DATE_FORMAT)
            for i in datetimes
        }

    @api.one
    def _estimate_time(self, field_name):
        datetimes = self._estimate_datetime(field_name)
        return {
            i: datetimes[i].strftime(DEFAULT_SERVER_TIME_FORMAT)
            for i in datetimes
        }

    def _inv_estimate_date(self, cr, uid, ids, field_name, val, arg,
                           context=None):
        """If there is no start date in journey, set it in travel"""
        if type(ids) in (int, long):
            ids = [ids]
        for journey in self.browse(cr, uid, ids, context=context):
            if journey.journey_type:
                try:
                    journey_class = self._journey_type_classes[journey.journey_type]
                    if (journey_class._inv_estimate_typed_date(
                            self, journey, field_name, val)):
                        continue
                except KeyError:
                    _logger.error(
                        _('Transportation type "%s" has not registered its '
                          'class in _journey_types, skipping its dates')
                        % journey.journey_type)
                except AttributeError:
                    _logger.error(
                        _('Transportation type "%s" has not registered a '
                          '_inv_estimate_typed_date() function, skipping its '
                          'dates') % journey.journey_type)
            if field_name == 'date_start':
                if journey.departure:
                    journey.write({'departure': val})
                elif journey.passenger_id.travel_id.date_start:
                    journey.passenger_id.travel_id.write({'date_start': val})
            elif field_name == 'date_stop':
                if journey.arrival:
                    journey.write({'arrival': val})
                elif journey.passenger_id.travel_id.date_stop:
                    journey.passenger_id.travel_id.write({'date_stop': val})

    @api.one
    def _default_class(self):
        return self.env['ir.model.data'].get_object_reference(
                'travel_journey', 'travel_journey_class_directive')[1]
    
    @api.one
    def _get_journey_type(self):
#         if type(ids) is dict and context is None:
#             context = ids
        res = self.env['travel.journey.type'].search(cr, uid, [])
        #res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
        return [(r.code, r.name) for r in res]
    
    @api.v7
    def create(self, cr, uid, vals, context=None):<commit_msg>[REFACT] remove commented code<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    This module copyright (C) 2013 <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 datetime import datetime
from openerp import fields, models, api, _
from openerp.tools.misc import (
    DEFAULT_SERVER_DATE_FORMAT,
    DEFAULT_SERVER_DATETIME_FORMAT,
    DEFAULT_SERVER_TIME_FORMAT,
)

import logging
_logger = logging.getLogger(__name__)


class TravelJourney(models.Model):

    """Journey of travel"""
    _name = 'travel.journey'
    _description = _(__doc__)
    _journey_type_classes = {}
    _rec_name = 'destination'

    @staticmethod
    def _check_dep_arr_dates(departure, arrival):
        return not departure or not arrival or departure <= arrival
    
    @api.one
    def _estimate_datetime(self, field_name):
        """If there is no start date from journey, get it from travel"""
        res = {}
        date = False

        if self.journey_type:
            try:
                journey_class = self._journey_type_classes[self.journey_type]
                date = journey_class._estimate_typed_date(
                    self, self, field_name)
            except KeyError:
                _logger.error(
                    _('Transportation type "%s" has not registered its '
                      'class in _journey_types, skipping its dates')
                    % self.journey_type)
            except AttributeError:
                _logger.error(
                    _('Transportation type "%s" has not registered a '
                      '_estimate_typed_date() function, skipping its '
                      'dates')
                    % self.journey_type)
        if field_name == 'date_start':
            date = (date or self.departure or
                    self.passenger_id.travel_id.date_start)
        elif field_name == 'date_stop':
            date = (date or self.arrival or
                    self.passenger_id.travel_id.date_stop)
        # Make sure every date is in datetime format and not simply date
        try:
            date = datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
        except ValueError:
            date = datetime.strptime(date, DEFAULT_SERVER_DATETIME_FORMAT)
        res[self.id] = date
        
        return res

    @api.one
    def _estimate_date(self, field_name):
        datetimes = self._estimate_datetime(field_name)
        return {
            i: datetimes[i].strftime(DEFAULT_SERVER_DATE_FORMAT)
            for i in datetimes
        }

    @api.one
    def _estimate_time(self, field_name):
        datetimes = self._estimate_datetime(field_name)
        return {
            i: datetimes[i].strftime(DEFAULT_SERVER_TIME_FORMAT)
            for i in datetimes
        }

    def _inv_estimate_date(self, cr, uid, ids, field_name, val, arg,
                           context=None):
        """If there is no start date in journey, set it in travel"""
        if type(ids) in (int, long):
            ids = [ids]
        for journey in self.browse(cr, uid, ids, context=context):
            if journey.journey_type:
                try:
                    journey_class = self._journey_type_classes[journey.journey_type]
                    if (journey_class._inv_estimate_typed_date(
                            self, journey, field_name, val)):
                        continue
                except KeyError:
                    _logger.error(
                        _('Transportation type "%s" has not registered its '
                          'class in _journey_types, skipping its dates')
                        % journey.journey_type)
                except AttributeError:
                    _logger.error(
                        _('Transportation type "%s" has not registered a '
                          '_inv_estimate_typed_date() function, skipping its '
                          'dates') % journey.journey_type)
            if field_name == 'date_start':
                if journey.departure:
                    journey.write({'departure': val})
                elif journey.passenger_id.travel_id.date_start:
                    journey.passenger_id.travel_id.write({'date_start': val})
            elif field_name == 'date_stop':
                if journey.arrival:
                    journey.write({'arrival': val})
                elif journey.passenger_id.travel_id.date_stop:
                    journey.passenger_id.travel_id.write({'date_stop': val})

    @api.one
    def _default_class(self):
        return self.env['ir.model.data'].get_object_reference(
                'travel_journey', 'travel_journey_class_directive')[1]
    
    @api.one
    def _get_journey_type(self):
        res = self.env['travel.journey.type'].search(cr, uid, [])
        #res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
        return [(r.code, r.name) for r in res]
    
    @api.v7
    def create(self, cr, uid, vals, context=None):
{'fraction_non_alphanumeric': 0.10863818538415622, 'fraction_numerical': 0.0013643728148716636, 'mean_word_length': 2.020345093999485, 'pattern_counts': {'":': 0, '<': 11, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2352380', 'n_tokens_mistral': 3279, 'n_tokens_neox': 3119, 'n_words': 870}