{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/45175258","id":45175258,"diff_hunk":"@@ -0,0 +1,159 @@\n+# -*- coding: utf-8 -*-\n+# Part of Odoo. See LICENSE file for full copyright and licensing details.\n+\n+import calendar\n+\n+from dateutil.relativedelta import relativedelta\n+\n+from openerp import api, fields, models, _\n+from openerp.exceptions import UserError\n+\n+\n+class HrEmployee(models.Model):\n+    _inherit = \"hr.employee\"\n+\n+    remaining_leaves = fields.Float(string='Remaining Legal Leaves',\n+        compute='_compute_get_remaining_days', inverse='_inverse_set_remaining_days',\n+        help='Total number of legal leaves allocated to this employee, change '\n+             'this value to create allocation/leave request. Total based on '\n+             'all the leave types without overriding limit.')\n+    current_leave_state = fields.Selection([\n+        ('draft', 'New'),\n+        ('confirm', 'Waiting Approval'),\n+        ('refuse', 'Refused'),\n+        ('validate1', 'Waiting Second Approval'),\n+        ('validate', 'Approved'),\n+        ('cancel', 'Cancelled')\n+    ], compute='_compute_get_leave_status', string=\"Current Leave Status\")\n+    current_leave_id = fields.Many2one(compute='_compute_get_leave_status',\n+        comodel_name='hr.holidays.status', string=\"Current Leave Type\")\n+    leave_date_from = fields.Date(compute='_compute_get_leave_status', string='From Date')\n+    leave_date_to = fields.Date(compute='_compute_get_leave_status', string='To Date')\n+    leaves_count = fields.Integer(compute='_compute_leaves_count',\n+        string='Number of Leaves (current month)')\n+    approved_leaves_count = fields.Integer(compute='_compute_leaves_count',\n+        string='Approved Leaves not in Payslip',\n+        help='These leaves are approved but not taken into account for payslip')\n+    is_absent_today = fields.Boolean(compute='_compute_absent_employee',\n+        search='_search_absent_employee', string=\"Absent Today\", default=False)\n+\n+    @api.one\n+    def _compute_get_remaining_days(self):\n+        self.remaining_leaves = self.remaining_days_count()\n+\n+    @api.one\n+    def _inverse_set_remaining_days(self):\n+        if not self.remaining_leaves:\n+            return False\n+        Holidays = self.env['hr.holidays']\n+        HolidaysStatus = self.env['hr.holidays.status']\n+        status = HolidaysStatus.search([('limit', '=', False)])\n+        if len(status) != 1:\n+            raise UserError(_('The feature behind the field \\'Remaining '\n+                'Legal Leaves\\' can only be used when there is only one '\n+                'leave type with the option \\'Allow to Override Limit\\' '\n+                'unchecked. (%s Found). '\n+                'Otherwise, the update is ambiguous as we cannot decide '\n+                'on which leave type the update has to be done. \\n'\n+                'You may prefer to use the classic menus '\n+                '\\'Leave Requests\\' and \\'Allocation Requests\\' located '\n+                'in \\'Human Resources \\ Leaves\\' to manage the leave days '\n+                'of the employees if the configuration does not allow to '\n+                'use this field.') % (len(status)))\n+        status_id = status and status[0].id or False\n+        if not status_id:\n+            return False\n+\n+        before_remaining_leaves = self.remaining_days_count()\n+        diff = self.remaining_leaves - before_remaining_leaves\n+        if diff > 0:\n+            leave = Holidays.create({\n+                'name': _('Allocation for %s') % self.name,\n+                'employee_id': self.id,\n+                'holiday_status_id': status_id,\n+                'request_type': 'add',\n+                'holiday_type': 'employee',\n+                '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+\n+    @api.multi\n+    def _compute_get_leave_status(self):","path":"addons/hr_holidays/models/hr_employee.py","position":86,"original_position":86,"commit_id":"36b2c498cf2467d2519269464c83442943e7e275","original_commit_id":"36b2c498cf2467d2519269464c83442943e7e275","user":{"login":"mdi-odoo","id":7599791,"avatar_url":"https://avatars.githubusercontent.com/u/7599791?v=3","gravatar_id":"","url":"https://api.github.com/users/mdi-odoo","html_url":"https://github.com/mdi-odoo","followers_url":"https://api.github.com/users/mdi-odoo/followers","following_url":"https://api.github.com/users/mdi-odoo/following{/other_user}","gists_url":"https://api.github.com/users/mdi-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/mdi-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdi-odoo/subscriptions","organizations_url":"https://api.github.com/users/mdi-odoo/orgs","repos_url":"https://api.github.com/users/mdi-odoo/repos","events_url":"https://api.github.com/users/mdi-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/mdi-odoo/received_events","type":"User","site_admin":false},"body":"No need of decorator here .","created_at":"2015-11-18T09:15:01Z","updated_at":"2015-11-18T09:15:01Z","html_url":"https://github.com/odoo/odoo/pull/7260#discussion_r45175258","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/7260","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/45175258"},"html":{"href":"https://github.com/odoo/odoo/pull/7260#discussion_r45175258"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7260"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/7260","id":38436681,"html_url":"https://github.com/odoo/odoo/pull/7260","diff_url":"https://github.com/odoo/odoo/pull/7260.diff","patch_url":"https://github.com/odoo/odoo/pull/7260.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/7260","number":7260,"state":"open","locked":false,"title":"[MIG] hr_holidays: Migrated to new api.","user":{"login":"imjaypatel","id":7599891,"avatar_url":"https://avatars.githubusercontent.com/u/7599891?v=3","gravatar_id":"","url":"https://api.github.com/users/imjaypatel","html_url":"https://github.com/imjaypatel","followers_url":"https://api.github.com/users/imjaypatel/followers","following_url":"https://api.github.com/users/imjaypatel/following{/other_user}","gists_url":"https://api.github.com/users/imjaypatel/gists{/gist_id}","starred_url":"https://api.github.com/users/imjaypatel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imjaypatel/subscriptions","organizations_url":"https://api.github.com/users/imjaypatel/orgs","repos_url":"https://api.github.com/users/imjaypatel/repos","events_url":"https://api.github.com/users/imjaypatel/events{/privacy}","received_events_url":"https://api.github.com/users/imjaypatel/received_events","type":"User","site_admin":false},"body":"<b>Task</b>: https://www.odoo.com/web#id=12603&view_type=form&model=project.task&action=327\r\n<b>Pad</b>: https://pad.odoo.com/p/r.jR3WnMZPcwayX8wD","created_at":"2015-06-24T12:31:39Z","updated_at":"2015-11-18T09:15:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"da9e8ff7826beda971f09eaca0cdc0f6c0a74631","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/7260/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/7260/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/7260/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/36b2c498cf2467d2519269464c83442943e7e275","head":{"label":"odoo-dev:master-hr-holidays-newapi-jpa","ref":"master-hr-holidays-newapi-jpa","sha":"36b2c498cf2467d2519269464c83442943e7e275","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":"2015-10-13T05:17:28Z","pushed_at":"2015-11-18T09:13:39Z","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":1122118,"stargazers_count":62,"watchers_count":62,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":0,"forks":26,"open_issues":0,"watchers":62,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"e74ac7617a9a1ca1201bd2d4a1b1e50d53fc5194","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":"2015-11-18T08:27:35Z","pushed_at":"2015-11-18T09:11:14Z","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":1196901,"stargazers_count":3399,"watchers_count":3399,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3074,"mirror_url":null,"open_issues_count":2855,"forks":3074,"open_issues":2855,"watchers":3399,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7260"},"html":{"href":"https://github.com/odoo/odoo/pull/7260"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/7260"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/7260/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7260/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/7260/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/36b2c498cf2467d2519269464c83442943e7e275"}}}}