{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/project/pulls/comments/58318387","id":58318387,"diff_hunk":"@@ -0,0 +1,71 @@\n+# -*- coding: utf-8 -*-\n+# © 2016 Antonio Espinosa\n+# © 2016 Pedro M. Baeza\n+# © 2016 Sergio Teruel\n+# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html\n+\n+from openerp import models, fields, api\n+from datetime import datetime\n+\n+\n+class AccountAnalyticLine(models.Model):\n+    _inherit = 'account.analytic.line'\n+\n+    date_time = fields.Datetime(default=fields.Datetime.now, string='Date')\n+    folded = fields.Boolean(related='task_id.stage_id.fold')\n+\n+    @api.onchange('account_id')\n+    def onchange_account_id(self):\n+        if self.task_id.project_id.analytic_account_id != self.account_id:\n+            self.task_id = False\n+        domain = {'task_id': []}\n+        if self.account_id:\n+            project = self.env['project.project'].search(\n+                [('analytic_account_id', '=', self.account_id.id)], limit=1)\n+            domain = {'task_id': [('project_id', '=', project.id),\n+                                  ('stage_id.fold', '=', False)]}\n+        return {'domain': domain}\n+\n+    @api.onchange('task_id')\n+    def onchange_task_id(self):\n+        if self.task_id:\n+            self.account_id = self.task_id.project_id.analytic_account_id.id\n+\n+    def eval_date(self, vals):\n+        if 'date_time' in vals and 'date' not in vals:\n+            vals['date'] = fields.Date.from_string(vals['date_time'])\n+        return vals\n+\n+    @api.model\n+    def create(self, vals):\n+        return super(AccountAnalyticLine, self).create(self.eval_date(vals))\n+\n+    @api.multi\n+    def write(self, vals):\n+        return super(AccountAnalyticLine, self).write(self.eval_date(vals))\n+\n+    @api.multi\n+    def button_end_work(self):\n+        end_date = datetime.now()\n+        for line in self:\n+            date = fields.Datetime.from_string(line.date_time)\n+            line.unit_amount = (end_date - date).total_seconds() / 3600\n+        return True\n+\n+    @api.multi\n+    def button_open_task(self):\n+        for line in self.filtered('task_id'):\n+            if line.task_id.project_id:\n+                stage = self.env['project.task.type'].search(\n+                    [('project_ids', '=', line.task_id.project_id.id),\n+                     ('fold', '=', False)], limit=1)\n+                line.task_id.write({'stage_id': stage.id})\n+\n+    @api.multi\n+    def button_close_task(self):\n+        for line in self.filtered('task_id'):\n+            if line.task_id.project_id:\n+                stage = self.env['project.task.type'].search(\n+                    [('project_ids', '=', line.task_id.project_id.id),\n+                     ('fold', '=', True)], limit=1)","path":"project_timesheet_time_control/models/account_analytic_line.py","position":70,"original_position":70,"commit_id":"846fd14737c2557b8198f2bde8826c7293705ac7","original_commit_id":"846fd14737c2557b8198f2bde8826c7293705ac7","user":{"login":"danimaribeiro","id":854781,"avatar_url":"https://avatars.githubusercontent.com/u/854781?v=3","gravatar_id":"","url":"https://api.github.com/users/danimaribeiro","html_url":"https://github.com/danimaribeiro","followers_url":"https://api.github.com/users/danimaribeiro/followers","following_url":"https://api.github.com/users/danimaribeiro/following{/other_user}","gists_url":"https://api.github.com/users/danimaribeiro/gists{/gist_id}","starred_url":"https://api.github.com/users/danimaribeiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danimaribeiro/subscriptions","organizations_url":"https://api.github.com/users/danimaribeiro/orgs","repos_url":"https://api.github.com/users/danimaribeiro/repos","events_url":"https://api.github.com/users/danimaribeiro/events{/privacy}","received_events_url":"https://api.github.com/users/danimaribeiro/received_events","type":"User","site_admin":false},"body":"What about raise an UserError when there is no fold stage? I did one test and the task goes 'undefined' \r\n![undefined](https://cloud.githubusercontent.com/assets/854781/14235232/339e75fe-f9ce-11e5-88f2-f3306bbe46e2.png)\r\n","created_at":"2016-04-03T22:00:02Z","updated_at":"2016-04-03T22:00:02Z","html_url":"https://github.com/OCA/project/pull/163#discussion_r58318387","pull_request_url":"https://api.github.com/repos/OCA/project/pulls/163","_links":{"self":{"href":"https://api.github.com/repos/OCA/project/pulls/comments/58318387"},"html":{"href":"https://github.com/OCA/project/pull/163#discussion_r58318387"},"pull_request":{"href":"https://api.github.com/repos/OCA/project/pulls/163"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/project/pulls/163","id":63932516,"html_url":"https://github.com/OCA/project/pull/163","diff_url":"https://github.com/OCA/project/pull/163.diff","patch_url":"https://github.com/OCA/project/pull/163.patch","issue_url":"https://api.github.com/repos/OCA/project/issues/163","number":163,"state":"open","locked":false,"title":"[9.0] [ADD] project_timesheet_time_control","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"body":"==============================\r\nProject Timesheet Time Control\r\n==============================\r\n\r\nThis module adds a button at account analytic line level to compute minutes\r\nlasted from start date to the current moment.\r\n\r\nIt adds a datetime field that replaces ``date`` field in tree view, and write\r\ndate field with datetime field value.\r\n\r\nIt also adds a filter by user and some groups by task and by user.\r\n\r\nFinally, it allows to open and close tasks from account analytic lines.","created_at":"2016-03-23T18:41:11Z","updated_at":"2016-04-03T22:00:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fd33c5ed6d1e00d8b9a5b3c8d0ba496f46fe417a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/project/pulls/163/commits","review_comments_url":"https://api.github.com/repos/OCA/project/pulls/163/comments","review_comment_url":"https://api.github.com/repos/OCA/project/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/project/issues/163/comments","statuses_url":"https://api.github.com/repos/OCA/project/statuses/846fd14737c2557b8198f2bde8826c7293705ac7","head":{"label":"pedrobaeza:9.0-project_timesheet_time_control","ref":"9.0-project_timesheet_time_control","sha":"846fd14737c2557b8198f2bde8826c7293705ac7","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"repo":{"id":23324226,"name":"project","full_name":"pedrobaeza/project","owner":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pedrobaeza/project","description":"","fork":true,"url":"https://api.github.com/repos/pedrobaeza/project","forks_url":"https://api.github.com/repos/pedrobaeza/project/forks","keys_url":"https://api.github.com/repos/pedrobaeza/project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pedrobaeza/project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pedrobaeza/project/teams","hooks_url":"https://api.github.com/repos/pedrobaeza/project/hooks","issue_events_url":"https://api.github.com/repos/pedrobaeza/project/issues/events{/number}","events_url":"https://api.github.com/repos/pedrobaeza/project/events","assignees_url":"https://api.github.com/repos/pedrobaeza/project/assignees{/user}","branches_url":"https://api.github.com/repos/pedrobaeza/project/branches{/branch}","tags_url":"https://api.github.com/repos/pedrobaeza/project/tags","blobs_url":"https://api.github.com/repos/pedrobaeza/project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pedrobaeza/project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pedrobaeza/project/git/refs{/sha}","trees_url":"https://api.github.com/repos/pedrobaeza/project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pedrobaeza/project/statuses/{sha}","languages_url":"https://api.github.com/repos/pedrobaeza/project/languages","stargazers_url":"https://api.github.com/repos/pedrobaeza/project/stargazers","contributors_url":"https://api.github.com/repos/pedrobaeza/project/contributors","subscribers_url":"https://api.github.com/repos/pedrobaeza/project/subscribers","subscription_url":"https://api.github.com/repos/pedrobaeza/project/subscription","commits_url":"https://api.github.com/repos/pedrobaeza/project/commits{/sha}","git_commits_url":"https://api.github.com/repos/pedrobaeza/project/git/commits{/sha}","comments_url":"https://api.github.com/repos/pedrobaeza/project/comments{/number}","issue_comment_url":"https://api.github.com/repos/pedrobaeza/project/issues/comments{/number}","contents_url":"https://api.github.com/repos/pedrobaeza/project/contents/{+path}","compare_url":"https://api.github.com/repos/pedrobaeza/project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pedrobaeza/project/merges","archive_url":"https://api.github.com/repos/pedrobaeza/project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pedrobaeza/project/downloads","issues_url":"https://api.github.com/repos/pedrobaeza/project/issues{/number}","pulls_url":"https://api.github.com/repos/pedrobaeza/project/pulls{/number}","milestones_url":"https://api.github.com/repos/pedrobaeza/project/milestones{/number}","notifications_url":"https://api.github.com/repos/pedrobaeza/project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pedrobaeza/project/labels{/name}","releases_url":"https://api.github.com/repos/pedrobaeza/project/releases{/id}","deployments_url":"https://api.github.com/repos/pedrobaeza/project/deployments","created_at":"2014-08-25T18:32:27Z","updated_at":"2016-03-23T18:39:50Z","pushed_at":"2016-03-24T02:39:53Z","git_url":"git://github.com/pedrobaeza/project.git","ssh_url":"git@github.com:pedrobaeza/project.git","clone_url":"https://github.com/pedrobaeza/project.git","svn_url":"https://github.com/pedrobaeza/project","homepage":null,"size":1439,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"8.0"}},"base":{"label":"OCA:9.0","ref":"9.0","sha":"588ee1922d717811fe915e531d225626ebb7f233","user":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"repo":{"id":20896145,"name":"project","full_name":"OCA/project","owner":{"login":"OCA","id":7600578,"avatar_url":"https://avatars.githubusercontent.com/u/7600578?v=3","gravatar_id":"","url":"https://api.github.com/users/OCA","html_url":"https://github.com/OCA","followers_url":"https://api.github.com/users/OCA/followers","following_url":"https://api.github.com/users/OCA/following{/other_user}","gists_url":"https://api.github.com/users/OCA/gists{/gist_id}","starred_url":"https://api.github.com/users/OCA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OCA/subscriptions","organizations_url":"https://api.github.com/users/OCA/orgs","repos_url":"https://api.github.com/users/OCA/repos","events_url":"https://api.github.com/users/OCA/events{/privacy}","received_events_url":"https://api.github.com/users/OCA/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OCA/project","description":"Odoo Project Management and Services Company Addons","fork":false,"url":"https://api.github.com/repos/OCA/project","forks_url":"https://api.github.com/repos/OCA/project/forks","keys_url":"https://api.github.com/repos/OCA/project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/project/teams","hooks_url":"https://api.github.com/repos/OCA/project/hooks","issue_events_url":"https://api.github.com/repos/OCA/project/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/project/events","assignees_url":"https://api.github.com/repos/OCA/project/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/project/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/project/tags","blobs_url":"https://api.github.com/repos/OCA/project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/project/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/project/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/project/languages","stargazers_url":"https://api.github.com/repos/OCA/project/stargazers","contributors_url":"https://api.github.com/repos/OCA/project/contributors","subscribers_url":"https://api.github.com/repos/OCA/project/subscribers","subscription_url":"https://api.github.com/repos/OCA/project/subscription","commits_url":"https://api.github.com/repos/OCA/project/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/project/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/project/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/project/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/project/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/project/merges","archive_url":"https://api.github.com/repos/OCA/project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/project/downloads","issues_url":"https://api.github.com/repos/OCA/project/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/project/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/project/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/project/labels{/name}","releases_url":"https://api.github.com/repos/OCA/project/releases{/id}","deployments_url":"https://api.github.com/repos/OCA/project/deployments","created_at":"2014-06-16T18:40:45Z","updated_at":"2016-03-28T23:11:26Z","pushed_at":"2016-03-29T07:16:16Z","git_url":"git://github.com/OCA/project.git","ssh_url":"git@github.com:OCA/project.git","clone_url":"https://github.com/OCA/project.git","svn_url":"https://github.com/OCA/project","homepage":"","size":3660,"stargazers_count":33,"watchers_count":33,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":103,"mirror_url":null,"open_issues_count":36,"forks":103,"open_issues":36,"watchers":33,"default_branch":"9.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/project/pulls/163"},"html":{"href":"https://github.com/OCA/project/pull/163"},"issue":{"href":"https://api.github.com/repos/OCA/project/issues/163"},"comments":{"href":"https://api.github.com/repos/OCA/project/issues/163/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/project/pulls/163/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/project/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/project/pulls/163/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/project/statuses/846fd14737c2557b8198f2bde8826c7293705ac7"}}}}