<commit_before># -*- coding: utf-8 -*-
# #############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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 time
from openerp import pooler
from datetime import date, datetime, timedelta
from openerp.osv import fields, osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
from pytz import timezone
import pytz
import logging
_logger = logging.getLogger(__name__)

#~ import logging
from dateutil import parser
from dateutil import rrule
from dateutil.relativedelta import relativedelta
import time
import re
import math

from openerp import SUPERUSER_ID, tools
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT

import sale
import doctor
import doctor_person
import doctor_appointment
import doctor_attentions
import doctor_invoice
import doctor_sales_order
import doctor_data
from openerp import netsvc


class doctor_schedule(osv.osv):
    """Schedule"""
    _name = 'doctor.schedule'
    _description = "Scheduling doctor office hours"
    _order = 'date_begin asc'
    _rec_name = 'professional_id'




    def _date_to_dateuser(self, cr, uid, ids, date_begin):
        date_begin_user = datetime.strptime(date_begin, "%Y-%m-%d %H:%M:%S")

        user = self.pool.get('res.users').browse(cr, uid, uid)
        tz = pytz.timezone(user.tz) if user.tz else pytz.utc
        date_begin_user = pytz.utc.localize(date_begin_user).astimezone(tz)

        date_begin_user = datetime.strftime(date_begin_user, "%d-%m-%Y %H:%M")
        return date_begin_user

    def _date_end_to_dateuser(self, cr, uid, ids, date_end):
        date_end_user = datetime.strptime(date_end, "%Y-%m-%d %H:%M:%S")

        user = self.pool.get('res.users').browse(cr, uid, uid)
        tz = pytz.timezone(user.tz) if user.tz else pytz.utc
        date_end_user = pytz.utc.localize(date_end_user).astimezone(tz)

        date_end_user = datetime.strftime(date_end_user, "%H:%M")
        return date_end_user

    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        res = []
        for record in self.browse(cr, uid, ids, context=context):
            date_begin = record.date_begin
            date_end = record.date_end
            display_name = record.professional_id['firtsname'] +' '+ record.professional_id['lastname'] + ' (' + self._date_to_dateuser(cr, uid, ids,
                                    date_begin) + ' - ' + self._date_end_to_dateuser( cr, uid, ids, date_end) + ')'
            res.append((record['id'], display_name))
        return res

    def _get_register(self, cr, uid, ids, fields, args, context=None):
        """Get Confirm or uncofirm register value.
        @param ids: List of Event registration type's id
        @param fields: List of function fields(register_current and register_prospect).
        @param context: A standard dictionary for contextual values
        @return: Dictionary of function fields value.
        """
        res = {}
        for schedule in self.browse(cr, uid, ids, context=context):
            res[schedule.id] = {}
            reg_open = 0
            for appointment in schedule.appointment_ids:
                if appointment.state != 'cancel':
                    reg_open += appointment.nb_register
            for field in fields:
                number = 0
                if field == 'patients_count':
                    number = reg_open
                res[schedule.id][field] = number
        return res

    _columns = {
        'professional_id': fields.many2one('doctor.professional', 'Doctor'),
        'date_begin': fields.datetime('Start date', required=True),
        'schedule_duration': fields.integer('Duration (in hours)', required=True),
        'date_end': fields.datetime('End date', required=True),
        'patients_count': fields.function(_get_register, string='Number of patients', multi='register_numbers'),
        'appointment_ids': fields.one2many('doctor.appointment', 'schedule_id', 'Appointments'),
    }

    def _check_schedule(self, cr, uid, ids):
        for record in self.browse(cr, uid, ids):
            schedule_ids = self.search(cr, uid,
                                       [('date_begin', '<', record.date_end), ('date_end', '>', record.date_begin),
                                        ('id', '<>', record.id)])
            if schedule_ids:
                return False
        return True

    def _check_date_begin(self, cr, uid, ids):
        for record in self.browse(cr, uid, ids):
            date_today = datetime.today()
            date_begin = record.date_begin
            date_begin = datetime.strptime(date_begin, "%Y-%m-%d %H:%M:%S")
            if date_begin < date_today:
                return False
        return True

    def _check_closing_time(self, cr, uid, ids, context=None):
        for record in self.browse(cr, uid, ids, context=context):
            if record.date_end < record.date_begin:
                return False
        return True<commit_msg>cambio creacion de agenda duracion en decimales ej: 2.5 horas -Capriatto<commit_after># -*- coding: utf-8 -*-
# #############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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 time
from openerp import pooler
from datetime import date, datetime, timedelta
from openerp.osv import fields, osv
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp
from pytz import timezone
import pytz
import logging
_logger = logging.getLogger(__name__)

#~ import logging
from dateutil import parser
from dateutil import rrule
from dateutil.relativedelta import relativedelta
import time
import re
import math

from openerp import SUPERUSER_ID, tools
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT

import sale
import doctor
import doctor_person
import doctor_appointment
import doctor_attentions
import doctor_invoice
import doctor_sales_order
import doctor_data
from openerp import netsvc


class doctor_schedule(osv.osv):
    """Schedule"""
    _name = 'doctor.schedule'
    _description = "Scheduling doctor office hours"
    _order = 'date_begin asc'
    _rec_name = 'professional_id'




    def _date_to_dateuser(self, cr, uid, ids, date_begin):
        date_begin_user = datetime.strptime(date_begin, "%Y-%m-%d %H:%M:%S")

        user = self.pool.get('res.users').browse(cr, uid, uid)
        tz = pytz.timezone(user.tz) if user.tz else pytz.utc
        date_begin_user = pytz.utc.localize(date_begin_user).astimezone(tz)

        date_begin_user = datetime.strftime(date_begin_user, "%d-%m-%Y %H:%M")
        return date_begin_user

    def _date_end_to_dateuser(self, cr, uid, ids, date_end):
        date_end_user = datetime.strptime(date_end, "%Y-%m-%d %H:%M:%S")

        user = self.pool.get('res.users').browse(cr, uid, uid)
        tz = pytz.timezone(user.tz) if user.tz else pytz.utc
        date_end_user = pytz.utc.localize(date_end_user).astimezone(tz)

        date_end_user = datetime.strftime(date_end_user, "%H:%M")
        return date_end_user

    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        res = []
        for record in self.browse(cr, uid, ids, context=context):
            date_begin = record.date_begin
            date_end = record.date_end
            display_name = record.professional_id['firtsname'] +' '+ record.professional_id['lastname'] + ' (' + self._date_to_dateuser(cr, uid, ids,
                                    date_begin) + ' - ' + self._date_end_to_dateuser( cr, uid, ids, date_end) + ')'
            res.append((record['id'], display_name))
        return res

    def _get_register(self, cr, uid, ids, fields, args, context=None):
        """Get Confirm or uncofirm register value.
        @param ids: List of Event registration type's id
        @param fields: List of function fields(register_current and register_prospect).
        @param context: A standard dictionary for contextual values
        @return: Dictionary of function fields value.
        """
        res = {}
        for schedule in self.browse(cr, uid, ids, context=context):
            res[schedule.id] = {}
            reg_open = 0
            for appointment in schedule.appointment_ids:
                if appointment.state != 'cancel':
                    reg_open += appointment.nb_register
            for field in fields:
                number = 0
                if field == 'patients_count':
                    number = reg_open
                res[schedule.id][field] = number
        return res

    _columns = {
        'professional_id': fields.many2one('doctor.professional', 'Doctor'),
        'date_begin': fields.datetime('Start date', required=True),
        'schedule_duration': fields.float('Duration (in hours)', required=True),
        'date_end': fields.datetime('End date', required=True),
        'patients_count': fields.function(_get_register, string='Number of patients', multi='register_numbers'),
        'appointment_ids': fields.one2many('doctor.appointment', 'schedule_id', 'Appointments'),
    }

    def _check_schedule(self, cr, uid, ids):
        for record in self.browse(cr, uid, ids):
            schedule_ids = self.search(cr, uid,
                                       [('date_begin', '<', record.date_end), ('date_end', '>', record.date_begin),
                                        ('id', '<>', record.id)])
            if schedule_ids:
                return False
        return True

    def _check_date_begin(self, cr, uid, ids):
        for record in self.browse(cr, uid, ids):
            date_today = datetime.today()
            date_begin = record.date_begin
            date_begin = datetime.strptime(date_begin, "%Y-%m-%d %H:%M:%S")
            if date_begin < date_today:
                return False
        return True

    def _check_closing_time(self, cr, uid, ids, context=None):
        for record in self.browse(cr, uid, ids, context=context):
            if record.date_end < record.date_begin:
                return False
        return True
{'fraction_non_alphanumeric': 0.12473855935748347, 'fraction_numerical': 0.0025098301681586214, 'mean_word_length': 2.798538290435335, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5763294', 'n_tokens_mistral': 3547, 'n_tokens_neox': 3362, 'n_words': 993}