{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/40076903","id":40076903,"diff_hunk":"@@ -0,0 +1,64 @@\n+# -*- coding: utf-8 -*-\n+# Part of Odoo. See LICENSE file for full copyright and licensing details.\n+from datetime import datetime\n+import cPickle\n+\n+from openerp import models, fields, api\n+\n+class pos_cache(models.Model):\n+    _name = 'pos.cache'\n+\n+    cache = fields.Binary()\n+    cachetime = fields.Datetime()\n+    config_ids = fields.One2many('pos.config', 'cache_id', 'Config')\n+\n+    @api.model\n+    def refresh_all_caches(self):\n+        caches = self.search([('config_ids', '=', False)])\n+        if caches:\n+            caches.unlink()\n+        self.env['pos.config'].search([('state', '=', 'active')]).recomputeCache()\n+\n+    @api.one\n+    def refresh_cache(self):\n+        products = self.env['product.product'].search(self._get_domain())\n+        prod_ctx = products.with_context(pricelist=self.config_ids[0].pricelist_id.id, display_default_code=False)\n+        if self.config_ids[0].cachecomputeuser_id:\n+            prod_ctx = prod_ctx.sudo(self.config_ids[0].cachecomputeuser_id.id)\n+        res = prod_ctx.read(self._get_fields())\n+        datas = {\n+            'cache': cPickle.dumps(res, protocol=cPickle.HIGHEST_PROTOCOL),\n+            'cachetime': fields.Datetime.now(),\n+        }\n+\n+        self.write(datas)\n+\n+    def _get_domain(self):\n+        return [('sale_ok', '=', True), ('available_in_pos', '=', True)]\n+\n+    def _get_fields(self):\n+        return ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',\n+                'to_weight', 'uom_id', 'description_sale', 'description',\n+                'product_tmpl_id']\n+\n+\n+class pos_config(models.Model):\n+    _inherit = 'pos.config'\n+\n+    #Use a related model to avoid the load of the cache when the pos load his config\n+    cache_id = fields.Many2one('pos.cache', 'Cache')\n+    cachecomputeuser_id = fields.Many2one('res.users', 'Cache compute user', help=\"User used to compute the cache content and thus avoid the bad practice of using admin in multi-company\")\n+    cachetime = fields.Datetime(related='cache_id.cachetime', string='Last cache compute')\n+\n+    @api.multi\n+    def getProductsFromCache(self):","path":"addons/pos_cache/models/pos_cache.py","position":null,"original_position":54,"commit_id":"1dcdcbb37eccc4860bb7b30694a774ee222073c6","original_commit_id":"d0c46060f0e571958605f79246116ea9e3385646","user":{"login":"jorenvo","id":10252581,"avatar_url":"https://avatars.githubusercontent.com/u/10252581?v=3","gravatar_id":"","url":"https://api.github.com/users/jorenvo","html_url":"https://github.com/jorenvo","followers_url":"https://api.github.com/users/jorenvo/followers","following_url":"https://api.github.com/users/jorenvo/following{/other_user}","gists_url":"https://api.github.com/users/jorenvo/gists{/gist_id}","starred_url":"https://api.github.com/users/jorenvo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorenvo/subscriptions","organizations_url":"https://api.github.com/users/jorenvo/orgs","repos_url":"https://api.github.com/users/jorenvo/repos","events_url":"https://api.github.com/users/jorenvo/events{/privacy}","received_events_url":"https://api.github.com/users/jorenvo/received_events","type":"User","site_admin":false},"body":"Done\n\nOn 22/09/15 13:34, antonylesuisse wrote:\n>\n> In addons/pos_cache/models/pos_cache.py \n> <https://github.com/odoo/odoo/pull/8652#discussion_r40075748>:\n>\n> > +    def _get_fields(self):\n> > +        return ['display_name', 'list_price','price','pos_categ_id', 'taxes_id', 'barcode', 'default_code',\n> > +                'to_weight', 'uom_id', 'description_sale', 'description',\n> > +                'product_tmpl_id']\n> > +\n> > +\n> > +class pos_config(models.Model):\n> > +    _inherit = 'pos.config'\n> > +\n> > +    #Use a related model to avoid the load of the cache when the pos load his config\n> > +    cache_id = fields.Many2one('pos.cache', 'Cache')\n> > +    cachecomputeuser_id = fields.Many2one('res.users', 'Cache compute user', help=\"User used to compute the cache content and thus avoid the bad practice of using admin in multi-company\")\n> > +    cachetime = fields.Datetime(related='cache_id.cachetime', string='Last cache compute')\n> > +\n> > +    @api.multi\n> > +    def getProductsFromCache(self):\n>\n> use _ instead of camel convention for python methods\n>\n> —\n> Reply to this email directly or view it on GitHub \n> <https://github.com/odoo/odoo/pull/8652/files#r40075748>.\n>\n\n","created_at":"2015-09-22T11:50:43Z","updated_at":"2015-09-22T11:50:43Z","html_url":"https://github.com/odoo/odoo/pull/8652#discussion_r40076903","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/8652","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/40076903"},"html":{"href":"https://github.com/odoo/odoo/pull/8652#discussion_r40076903"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/8652"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/8652","id":45640854,"html_url":"https://github.com/odoo/odoo/pull/8652","diff_url":"https://github.com/odoo/odoo/pull/8652.diff","patch_url":"https://github.com/odoo/odoo/pull/8652.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/8652","number":8652,"state":"open","locked":false,"title":"[ADD] pos_cache","user":{"login":"jorenvo","id":10252581,"avatar_url":"https://avatars.githubusercontent.com/u/10252581?v=3","gravatar_id":"","url":"https://api.github.com/users/jorenvo","html_url":"https://github.com/jorenvo","followers_url":"https://api.github.com/users/jorenvo/followers","following_url":"https://api.github.com/users/jorenvo/following{/other_user}","gists_url":"https://api.github.com/users/jorenvo/gists{/gist_id}","starred_url":"https://api.github.com/users/jorenvo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorenvo/subscriptions","organizations_url":"https://api.github.com/users/jorenvo/orgs","repos_url":"https://api.github.com/users/jorenvo/repos","events_url":"https://api.github.com/users/jorenvo/events{/privacy}","received_events_url":"https://api.github.com/users/jorenvo/received_events","type":"User","site_admin":false},"body":"Add the pos_cache module from odoo-extra.","created_at":"2015-09-22T09:10:55Z","updated_at":"2015-09-22T11:50:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3d0250f2e250c1165026eaf2140219260553c6e","assignee":{"login":"antonylesuisse","id":641600,"avatar_url":"https://avatars.githubusercontent.com/u/641600?v=3","gravatar_id":"","url":"https://api.github.com/users/antonylesuisse","html_url":"https://github.com/antonylesuisse","followers_url":"https://api.github.com/users/antonylesuisse/followers","following_url":"https://api.github.com/users/antonylesuisse/following{/other_user}","gists_url":"https://api.github.com/users/antonylesuisse/gists{/gist_id}","starred_url":"https://api.github.com/users/antonylesuisse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonylesuisse/subscriptions","organizations_url":"https://api.github.com/users/antonylesuisse/orgs","repos_url":"https://api.github.com/users/antonylesuisse/repos","events_url":"https://api.github.com/users/antonylesuisse/events{/privacy}","received_events_url":"https://api.github.com/users/antonylesuisse/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/8652/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/8652/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/8652/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/1dcdcbb37eccc4860bb7b30694a774ee222073c6","head":{"label":"odoo-dev:9.0-pos-cache-jov","ref":"9.0-pos-cache-jov","sha":"1dcdcbb37eccc4860bb7b30694a774ee222073c6","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-09-09T08:41:10Z","pushed_at":"2015-09-22T11:45:17Z","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":1388355,"stargazers_count":60,"watchers_count":60,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":0,"forks":24,"open_issues":0,"watchers":60,"default_branch":"master"}},"base":{"label":"odoo:9.0","ref":"9.0","sha":"7a9c0097af22bf6547c06e44634784f5cdde0f67","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-09-22T08:54:55Z","pushed_at":"2015-09-22T11:45:32Z","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":1523774,"stargazers_count":3111,"watchers_count":3111,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2696,"mirror_url":null,"open_issues_count":2644,"forks":2696,"open_issues":2644,"watchers":3111,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/8652"},"html":{"href":"https://github.com/odoo/odoo/pull/8652"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/8652"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/8652/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/8652/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/8652/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/1dcdcbb37eccc4860bb7b30694a774ee222073c6"}}}}