{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/50231705","id":50231705,"diff_hunk":"@@ -0,0 +1,107 @@\n+# -*- coding: utf-8 -*-\n+# Part of Odoo. See LICENSE file for full copyright and licensing details.\n+\n+# Copyright (c) 2005-2006 Axelor SARL. (http://www.axelor.com)\n+\n+from dateutil.relativedelta import relativedelta\n+\n+from odoo import api, fields, models, _\n+from odoo.exceptions import UserError\n+\n+\n+class HrEmployee(models.Model):\n+    _inherit = \"hr.employee\"\n+\n+    remaining_leaves = fields.Float(compute='_compute_remaining_days', string='Remaining Legal Leaves', inverse='_inverse_remaining_days', help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave request. Total based on all the leave types without overriding limit.')\n+    current_leave_state = fields.Selection([('draft', 'New'), ('confirm', 'Waiting Approval'),\n+        ('refuse', 'Refused'), ('validate1', 'Waiting Second Approval'),\n+        ('validate', 'Approved'), ('cancel', 'Cancelled')],\n+        compute='_compute_leave_status', string=\"Current Leave Status\")\n+    current_leave_id = fields.Many2one('hr.holidays.status', compute='_compute_leave_status', string=\"Current Leave Type\")\n+    leave_date_from = fields.Date(compute='_compute_leave_status', string='From Date')\n+    leave_date_to = fields.Date(compute='_compute_leave_status', string='To Date')\n+    leaves_count = fields.Integer(compute='_compute_leaves_count', string='Number of Leaves')\n+    show_leaves = fields.Boolean(compute='_compute_show_leaves', string=\"Able to see Remaining Leaves\")\n+    is_absent_totay = fields.Boolean(compute='_compute_absent_employee', search='_search_absent_employee', string=\"Absent Today\")\n+\n+    def _remaining_leaves_count(self):\n+        leaves = self.env['hr.holidays'].read_group([('state', '=', 'validate'),\n+            ('holiday_status_id.limit', '=', False), ('employee_id', 'in', self.ids)],\n+            ['number_of_days', 'employee_id'], ['employee_id'])\n+        leaves = dict([(leave['employee_id'][0], leave['number_of_days']) for leave in leaves])\n+        return dict([(employee.id, leaves.get(employee.id, 0)) for employee in self])\n+\n+    def _inverse_remaining_days(self):\n+        if self.remaining_leaves:\n+            diff = self.remaining_leaves - self._remaining_leaves_count().get(self.id)\n+            # Find for holidays status\n+            status = self.env['hr.holidays.status'].search([('limit', '=', False)])\n+            if len(status) != 1:\n+                raise UserError(_(\"The feature behind the field 'Remaining Legal Leaves' can only be used when there is only one leave type with the option 'Allow to Override Limit' unchecked. (%s Found). Otherwise, the update is ambiguous as we cannot decide on which leave type the update has to be done. \\nYou may prefer to use the classic menus 'Leave Requests' and 'Allocation Requests' located in 'Human Resources \\ Leaves' to manage the leave days of the employees if the configuration does not allow to use this field.\") % (len(status)))\n+            if diff > 0:\n+                leave = self.env['hr.holidays'].create({'name': _('Allocation for %s') % self.name, 'employee_id': self.id, 'holiday_status_id': status.id, 'type': 'add', 'holiday_type': 'employee', 'number_of_days_temp': diff})\n+            elif diff < 0:\n+                raise UserError(_('You cannot reduce validated allocation requests'))\n+            else:\n+                return False\n+            for sig in ('confirm', 'validate', 'second_validate'):\n+                leave.signal_workflow(sig)\n+            return True\n+        return False\n+\n+    def _compute_remaining_days(self):\n+        remaining_leaves = self._remaining_leaves_count()\n+        for employee in self:\n+            employee.remaining_leaves = remaining_leaves[employee.id]\n+\n+    @api.depends('current_leave_id', 'leave_date_from', 'leave_date_to')\n+    def _compute_leave_status(self):\n+        today_date = fields.Date.from_string(fields.Date.today())\n+        today_end = fields.Datetime.to_string(today_date + relativedelta(hours=23, minutes=59, seconds=59))\n+        holidays = self.env['hr.holidays'].search([\n+            ('date_from', '<=', fields.Datetime.now()),\n+            ('date_to', '>=', today_end), ('type', '=', 'remove'),","path":"addons/hr_holidays/models/hr_employee.py","position":63,"original_position":63,"commit_id":"707571563d8c6ccd2d780869ab3365596e570cbe","original_commit_id":"707571563d8c6ccd2d780869ab3365596e570cbe","user":{"login":"xmo-odoo","id":7571158,"avatar_url":"https://avatars.githubusercontent.com/u/7571158?v=3","gravatar_id":"","url":"https://api.github.com/users/xmo-odoo","html_url":"https://github.com/xmo-odoo","followers_url":"https://api.github.com/users/xmo-odoo/followers","following_url":"https://api.github.com/users/xmo-odoo/following{/other_user}","gists_url":"https://api.github.com/users/xmo-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/xmo-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xmo-odoo/subscriptions","organizations_url":"https://api.github.com/users/xmo-odoo/orgs","repos_url":"https://api.github.com/users/xmo-odoo/repos","events_url":"https://api.github.com/users/xmo-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/xmo-odoo/received_events","type":"User","site_admin":false},"body":"Why >= with {today}T23:59:59?","created_at":"2016-01-20T09:34:24Z","updated_at":"2016-01-20T09:34:24Z","html_url":"https://github.com/odoo/odoo/pull/10182#discussion_r50231705","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/10182","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/50231705"},"html":{"href":"https://github.com/odoo/odoo/pull/10182#discussion_r50231705"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10182"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/10182","id":54442293,"html_url":"https://github.com/odoo/odoo/pull/10182","diff_url":"https://github.com/odoo/odoo/pull/10182.diff","patch_url":"https://github.com/odoo/odoo/pull/10182.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/10182","number":10182,"state":"open","locked":false,"title":"[MIG] hr_holidays: Migrated to new api.","user":{"login":"dut-odoo","id":12252239,"avatar_url":"https://avatars.githubusercontent.com/u/12252239?v=3","gravatar_id":"","url":"https://api.github.com/users/dut-odoo","html_url":"https://github.com/dut-odoo","followers_url":"https://api.github.com/users/dut-odoo/followers","following_url":"https://api.github.com/users/dut-odoo/following{/other_user}","gists_url":"https://api.github.com/users/dut-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/dut-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dut-odoo/subscriptions","organizations_url":"https://api.github.com/users/dut-odoo/orgs","repos_url":"https://api.github.com/users/dut-odoo/repos","events_url":"https://api.github.com/users/dut-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/dut-odoo/received_events","type":"User","site_admin":false},"body":"Task: https://www.odoo.com/web#id=12603&view_type=form&model=project.task&action=327\r\nPad: https://pad.odoo.com/p/r.jR3WnMZPcwayX8wD","created_at":"2015-12-23T06:00:40Z","updated_at":"2016-01-20T09:34:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b84580a2150dc7f182198395e96be09747e23da4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/10182/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/10182/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/10182/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/707571563d8c6ccd2d780869ab3365596e570cbe","head":{"label":"odoo-dev:master-hr-holidays-new-api-dut","ref":"master-hr-holidays-new-api-dut","sha":"707571563d8c6ccd2d780869ab3365596e570cbe","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":19853934,"name":"odoo","full_name":"odoo-dev/odoo","owner":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo-dev/odoo","description":"RD Dev Repository","fork":true,"url":"https://api.github.com/repos/odoo-dev/odoo","forks_url":"https://api.github.com/repos/odoo-dev/odoo/forks","keys_url":"https://api.github.com/repos/odoo-dev/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo-dev/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo-dev/odoo/teams","hooks_url":"https://api.github.com/repos/odoo-dev/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo-dev/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo-dev/odoo/events","assignees_url":"https://api.github.com/repos/odoo-dev/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo-dev/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo-dev/odoo/tags","blobs_url":"https://api.github.com/repos/odoo-dev/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo-dev/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo-dev/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo-dev/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo-dev/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo-dev/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo-dev/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo-dev/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo-dev/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo-dev/odoo/subscription","commits_url":"https://api.github.com/repos/odoo-dev/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo-dev/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo-dev/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo-dev/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo-dev/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo-dev/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo-dev/odoo/merges","archive_url":"https://api.github.com/repos/odoo-dev/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo-dev/odoo/downloads","issues_url":"https://api.github.com/repos/odoo-dev/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo-dev/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo-dev/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo-dev/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo-dev/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo-dev/odoo/releases{/id}","created_at":"2014-05-16T11:16:19Z","updated_at":"2016-01-08T09:23:25Z","pushed_at":"2016-01-20T09:27:26Z","git_url":"git://github.com/odoo-dev/odoo.git","ssh_url":"git@github.com:odoo-dev/odoo.git","clone_url":"https://github.com/odoo-dev/odoo.git","svn_url":"https://github.com/odoo-dev/odoo","homepage":"https://www.odoo.com","size":1218214,"stargazers_count":65,"watchers_count":65,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":0,"forks":27,"open_issues":0,"watchers":65,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"a8e811a08cf3b559d263ca3869cc71a6fc5c010b","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"repo":{"id":19745004,"name":"odoo","full_name":"odoo/odoo","owner":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo/odoo","description":"Odoo (formerly OpenERP). Open Source Apps To Grow Your Business.","fork":false,"url":"https://api.github.com/repos/odoo/odoo","forks_url":"https://api.github.com/repos/odoo/odoo/forks","keys_url":"https://api.github.com/repos/odoo/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo/odoo/teams","hooks_url":"https://api.github.com/repos/odoo/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo/odoo/events","assignees_url":"https://api.github.com/repos/odoo/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo/odoo/tags","blobs_url":"https://api.github.com/repos/odoo/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo/odoo/subscription","commits_url":"https://api.github.com/repos/odoo/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo/odoo/merges","archive_url":"https://api.github.com/repos/odoo/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo/odoo/downloads","issues_url":"https://api.github.com/repos/odoo/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo/odoo/releases{/id}","created_at":"2014-05-13T15:38:58Z","updated_at":"2016-01-20T09:24:44Z","pushed_at":"2016-01-20T09:27:28Z","git_url":"git://github.com/odoo/odoo.git","ssh_url":"git@github.com:odoo/odoo.git","clone_url":"https://github.com/odoo/odoo.git","svn_url":"https://github.com/odoo/odoo","homepage":"https://www.odoo.com","size":1298914,"stargazers_count":3659,"watchers_count":3659,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3398,"mirror_url":null,"open_issues_count":3023,"forks":3398,"open_issues":3023,"watchers":3659,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10182"},"html":{"href":"https://github.com/odoo/odoo/pull/10182"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/10182"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/10182/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10182/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/10182/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/707571563d8c6ccd2d780869ab3365596e570cbe"}}}}