<commit_before># -*- coding: utf-8 -*-
# © 2016 ONESTEiN BV (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api
from odoo.exceptions import Warning
from odoo.tools.translate import _


class HrHolidays(models.Model):
    _inherit = 'hr.holidays'

    public_holiday_id = fields.Many2one(
        'hr.holidays.public.line',
        string="Public Holiday")

    @api.model
    def get_employee_calendar(self, employee):
        calendar = None
        if employee.resource_id.calendar_id:
            calendar = employee.resource_id.calendar_id.id
        return calendar

    @api.multi
    def holidays_validate(self):
        for holiday in self:
            if not holiday.holiday_type == 'employee':
                return super(HrHolidays, self).holidays_validate()

            try:
                res_id = self.env['ir.model.data'].get_object(
                    'hr_public_holidays_leaves', 'hr_public_holiday').id
            except ValueError:
                raise Warning(
                    _("Leave Type for Public Holiday not found!"))

            if holiday.holiday_status_id.id != res_id:
                return super(HrHolidays, self).holidays_validate()

            calendar = self.get_employee_calendar(holiday.employee_id)

            self.env['resource.calendar.leaves'].create({
                'name': holiday.name,
                'date_from': holiday.date_from,
                'date_to': holiday.date_to,
                'resource_id': holiday.employee_id.resource_id.id,
                'calendar_id': calendar,
                'holiday_id': holiday.id
            })
            holiday.state = 'validate'<commit_msg>Method 'holidays_validate' renamed to the V10 function 'action_validate' in module 'hr_public_holidays_leaves'<commit_after># -*- coding: utf-8 -*-
# © 2016 ONESTEiN BV (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api
from odoo.exceptions import Warning
from odoo.tools.translate import _


class HrHolidays(models.Model):
    _inherit = 'hr.holidays'

    public_holiday_id = fields.Many2one(
        'hr.holidays.public.line',
        string="Public Holiday")

    @api.model
    def get_employee_calendar(self, employee):
        calendar = None
        if employee.resource_id.calendar_id:
            calendar = employee.resource_id.calendar_id.id
        return calendar

    @api.multi
    def action_validate(self):
        for holiday in self:
            if not holiday.holiday_type == 'employee':
                return super(HrHolidays, self).action_validate()

            try:
                res_id = self.env['ir.model.data'].get_object(
                    'hr_public_holidays_leaves', 'hr_public_holiday').id
            except ValueError:
                raise Warning(
                    _("Leave Type for Public Holiday not found!"))

            if holiday.holiday_status_id.id != res_id:
                return super(HrHolidays, self).action_validate()

            calendar = self.get_employee_calendar(holiday.employee_id)

            self.env['resource.calendar.leaves'].create({
                'name': holiday.name,
                'date_from': holiday.date_from,
                'date_to': holiday.date_to,
                'resource_id': holiday.employee_id.resource_id.id,
                'calendar_id': calendar,
                'holiday_id': holiday.id
            })
            holiday.state = 'validate'
{'fraction_non_alphanumeric': 0.10452374262433267, 'fraction_numerical': 0.005057600449564484, 'mean_word_length': 2.1310466138962183, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1554066', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1020, 'n_words': 209}