{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/22867240","id":22867240,"diff_hunk":"@@ -0,0 +1,300 @@\n+# -*- coding: utf-8 -*-\n+from datetime import datetime, timedelta\n+import logging\n+from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT\n+from openerp.exceptions import Warning\n+from openerp import models, fields, exceptions, SUPERUSER_ID, api\n+from openerp.tools.translate import _\n+import simplejson\n+\n+_logger = logging.getLogger(__name__)\n+\n+\n+class Experiment_version(models.Model):\n+\n+    _name = \"website_version.experiment_version\"\n+\n+    version_id = fields.Many2one('website_version.version', string=\"version_id\", required=True, ondelete='cascade')\n+    experiment_id = fields.Many2one('website_version.experiment', string=\"Experiment_id\", required=True, ondelete='cascade')\n+    frequency = fields.Selection([('10', 'Less'), ('50', 'Medium'), ('80', 'More')], string='Frequency', default='50')\n+    google_index = fields.Integer(string='Google index')\n+\n+\n+#This model allow to define the Google analytics goals in a experiment\n+\n+\n+class Goals(models.Model):\n+\n+    _name = \"website_version.goals\"\n+\n+    name = fields.Char(string=\"Name\", required=True)\n+    google_ref = fields.Char(string=\"Reference Google\", required=True)\n+\n+\n+class Experiment(models.Model):\n+\n+    _name = \"website_version.experiment\"\n+    _inherit = ['mail.thread']\n+    _order = 'sequence'\n+\n+    @api.multi\n+    def _check_view(self):\n+        #No overlap for running experiments\n+        for exp in self:\n+            if exp.state == 'running':\n+                for exp_ver in exp.experiment_version_ids:\n+                    if exp_ver.search([('version_id.view_ids.key', 'in', [v.key for v in exp_ver.version_id.view_ids]), ('experiment_id', '!=', exp_ver.experiment_id.id), ('experiment_id.website_id', '=', exp_ver.experiment_id.website_id.id), ('experiment_id.state', '=', 'running')]):\n+                        return False\n+        return True\n+\n+    @api.multi\n+    def _check_website(self):\n+        for exp in self:\n+            for exp_ver in exp.experiment_version_ids:\n+                if not exp_ver.version_id.website_id.id == exp.website_id.id:\n+                    return False\n+        return True\n+\n+    _constraints = [\n+        (_check_view, _('This experiment contains a view which is already used in another running experience'), ['state']),\n+        (_check_website, _('This experiment must have versions which are in the same website'), ['website_id', 'experiment_version_ids']),\n+    ]\n+\n+    _group_by_full = {\n+        'state': lambda *args, **kwargs: ([s[0] for s in [('running', 'Running'), ('paused', 'Paused'), ('ended', 'Ended')]], dict()),\n+    }\n+\n+    def _get_version_number(self):\n+        for exp in self:\n+            exp.version_number = len(exp.experiment_version_ids) + 1\n+\n+    name = fields.Char(string=\"Title\", required=True)\n+    experiment_version_ids = fields.One2many('website_version.experiment_version', 'experiment_id', string=\"experiment_version_ids\")\n+    website_id = fields.Many2one('website', string=\"Website\", required=True)\n+    state = fields.Selection([('running', 'Running'), ('paused', 'Paused'), ('ended', 'Ended')], 'Status', required=True, copy=False, track_visibility='onchange', default='running')\n+    goal_id = fields.Many2one('website_version.goals', string=\"Objective\", required=True)\n+    color = fields.Integer('Color Index')\n+    version_number = fields.Integer(compute=_get_version_number)","path":"addons/website_version/models/experiment.py","position":77,"original_position":77,"commit_id":"00c178a9c46694a1e647cef4c534d3140dd9369c","original_commit_id":"fb3aa04e0ba0540f726e16262af185f33fc5ebb9","user":{"login":"simongoffin","id":5430156,"avatar_url":"https://avatars.githubusercontent.com/u/5430156?v=3","gravatar_id":"","url":"https://api.github.com/users/simongoffin","html_url":"https://github.com/simongoffin","followers_url":"https://api.github.com/users/simongoffin/followers","following_url":"https://api.github.com/users/simongoffin/following{/other_user}","gists_url":"https://api.github.com/users/simongoffin/gists{/gist_id}","starred_url":"https://api.github.com/users/simongoffin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simongoffin/subscriptions","organizations_url":"https://api.github.com/users/simongoffin/orgs","repos_url":"https://api.github.com/users/simongoffin/repos","events_url":"https://api.github.com/users/simongoffin/events{/privacy}","received_events_url":"https://api.github.com/users/simongoffin/received_events","type":"User","site_admin":false},"body":"This field is not showed.","created_at":"2015-01-13T15:08:41Z","updated_at":"2015-01-13T15:08:41Z","html_url":"https://github.com/odoo/odoo/pull/4663#discussion_r22867240","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/4663","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/22867240"},"html":{"href":"https://github.com/odoo/odoo/pull/4663#discussion_r22867240"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/4663"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/4663","id":27261354,"html_url":"https://github.com/odoo/odoo/pull/4663","diff_url":"https://github.com/odoo/odoo/pull/4663.diff","patch_url":"https://github.com/odoo/odoo/pull/4663.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/4663","number":4663,"state":"open","locked":false,"title":"[ADD] View versioning module","user":{"login":"tde-banana-odoo","id":7501424,"avatar_url":"https://avatars.githubusercontent.com/u/7501424?v=3","gravatar_id":"","url":"https://api.github.com/users/tde-banana-odoo","html_url":"https://github.com/tde-banana-odoo","followers_url":"https://api.github.com/users/tde-banana-odoo/followers","following_url":"https://api.github.com/users/tde-banana-odoo/following{/other_user}","gists_url":"https://api.github.com/users/tde-banana-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/tde-banana-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tde-banana-odoo/subscriptions","organizations_url":"https://api.github.com/users/tde-banana-odoo/orgs","repos_url":"https://api.github.com/users/tde-banana-odoo/repos","events_url":"https://api.github.com/users/tde-banana-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/tde-banana-odoo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-13T10:34:26Z","updated_at":"2015-01-13T15:08:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"170830ecdc1c9d8ccca1b8784a19e5af5e139b8a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/4663/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/4663/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments/{number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/4663/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/00c178a9c46694a1e647cef4c534d3140dd9369c","head":{"label":"odoo-dev:master-version-new_api-sig","ref":"master-version-new_api-sig","sha":"00c178a9c46694a1e647cef4c534d3140dd9369c","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":"2014-12-16T17:15:21Z","pushed_at":"2015-01-13T15:07:11Z","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":1001331,"stargazers_count":37,"watchers_count":37,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":3,"forks":17,"open_issues":3,"watchers":37,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"34c15580bfdf37cf1041e0c2cfdd0aff3b0fdbda","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-01-13T14:51:49Z","pushed_at":"2015-01-13T14:59:46Z","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":1002224,"stargazers_count":1804,"watchers_count":1804,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1463,"mirror_url":null,"open_issues_count":1632,"forks":1463,"open_issues":1632,"watchers":1804,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/4663"},"html":{"href":"https://github.com/odoo/odoo/pull/4663"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/4663"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/4663/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/4663/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/4663/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/00c178a9c46694a1e647cef4c534d3140dd9369c"}}}}