<commit_before># -*- coding: utf-8 -*-
# Copyright 2018-2019 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import datetime
from pytz import timezone
import pytz

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT


class HrAttendance(models.Model):
    _inherit = 'hr.attendance'

    update_manually = fields.Boolean(
        string='Updated Manually',
        default=False,
    )
    update_manually_reason = fields.Char(
        string='Updated Manually Reason',
    )
    state = fields.Selection(
        related='sheet_id.state',
        readonly=True,
    )

    @api.constrains('update_manually', 'update_manually_reason')
    def _check_update_manually(self):
        if not self.update_manually_reason:
            raise ValidationError(
                _('Please enter the reason of updating the attendance record.'))

    @api.onchange('employee_id', 'check_in', 'check_out')
    def _onchange_update_manually(self):
        self.update_manually = True

    @api.depends('employee_id', 'check_in', 'check_out',
                 'sheet_id_computed.date_to',
                 'sheet_id_computed.date_from',
                 'sheet_id_computed.employee_id')
    def _compute_sheet(self):
        """Links the attendance to the corresponding sheet
        """
        for attendance in self:
            att_tz_date_str = attendance._get_attendance_employee_tz(
                attendance.employee_id.id, attendance.check_in)
            corresponding_sheet = self.env[
                'hr_timesheet_sheet.sheet'].search(
                [('date_to', '>=', att_tz_date_str),
                 ('date_from', '<=', att_tz_date_str),
                 ('employee_id', '=', attendance.employee_id.id),
                 ('state', 'in', ['draft', 'new'])], limit=1)
            if corresponding_sheet:
                attendance.sheet_id_computed = corresponding_sheet[0]
                attendance.sheet_id = corresponding_sheet[0]

    def _search_sheet(self, operator, value):
        assert operator == 'in'
        ids = []
        for ts in self.env['hr_timesheet_sheet.sheet'].browse(value):<commit_msg>[FIX] Check update_manually in validation (#164)<commit_after># -*- coding: utf-8 -*-
# Copyright 2018-2019 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import datetime
from pytz import timezone
import pytz

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT


class HrAttendance(models.Model):
    _inherit = 'hr.attendance'

    update_manually = fields.Boolean(
        string='Updated Manually',
        default=False,
    )
    update_manually_reason = fields.Char(
        string='Updated Manually Reason',
    )
    state = fields.Selection(
        related='sheet_id.state',
        readonly=True,
    )

    @api.constrains('update_manually', 'update_manually_reason')
    def _check_update_manually(self):
        if self.update_manually and not self.update_manually_reason:
            raise ValidationError(
                _('Please enter the reason of updating the attendance record.'))

    @api.onchange('employee_id', 'check_in', 'check_out')
    def _onchange_update_manually(self):
        self.update_manually = True

    @api.depends('employee_id', 'check_in', 'check_out',
                 'sheet_id_computed.date_to',
                 'sheet_id_computed.date_from',
                 'sheet_id_computed.employee_id')
    def _compute_sheet(self):
        """Links the attendance to the corresponding sheet
        """
        for attendance in self:
            att_tz_date_str = attendance._get_attendance_employee_tz(
                attendance.employee_id.id, attendance.check_in)
            corresponding_sheet = self.env[
                'hr_timesheet_sheet.sheet'].search(
                [('date_to', '>=', att_tz_date_str),
                 ('date_from', '<=', att_tz_date_str),
                 ('employee_id', '=', attendance.employee_id.id),
                 ('state', 'in', ['draft', 'new'])], limit=1)
            if corresponding_sheet:
                attendance.sheet_id_computed = corresponding_sheet[0]
                attendance.sheet_id = corresponding_sheet[0]

    def _search_sheet(self, operator, value):
        assert operator == 'in'
        ids = []
        for ts in self.env['hr_timesheet_sheet.sheet'].browse(value):
{'fraction_non_alphanumeric': 0.10711188204683435, 'fraction_numerical': 0.0067215958369470944, 'mean_word_length': 2.6992782678428227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5277487', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1341, 'n_words': 276}