{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/comments/23765252","id":23765252,"diff_hunk":"@@ -0,0 +1,126 @@\n+# -*- coding: utf-8 -*-\n+##############################################################################\n+#\n+#    Author: Guewen Baconnier\n+#    Copyright 2012 Camptocamp SA\n+#\n+#    This program is free software: you can redistribute it and/or modify\n+#    it under the terms of the GNU Affero General Public License as\n+#    published by the Free Software Foundation, either version 3 of the\n+#    License, or (at your option) any later version.\n+#\n+#    This program is distributed in the hope that it will be useful,\n+#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+#    GNU Affero General Public License for more details.\n+#\n+#    You should have received a copy of the GNU Affero General Public License\n+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+##############################################################################\n+\n+from openerp import models, fields, api\n+\n+\n+class stock_picking(models.Model):\n+    _inherit = \"stock.picking\"\n+\n+    @api.multi\n+    def generate_carrier_files(self, auto=True,\n+                               recreate=False):\n+        \"\"\"\n+        Generates all the files for a list of pickings according to\n+        their configuration carrier file.\n+        Does nothing on pickings without carrier or without\n+        carrier file configuration.\n+        Generate files only for outgoing pickings.\n+\n+        :param list ids: list of ids of pickings for which we need a file\n+        :param auto: specify if we call the method from an automatic action\n+                     (on process on picking as instance)\n+                     or called manually from the wizard. When auto is True,\n+                     only the carrier files set as \"auto_export\"\n+                     are exported\n+        :return: True if successful\n+        \"\"\"\n+        carrier_file_ids = {}\n+        for picking in self:\n+            if picking.picking_type_id.code != 'outgoing':\n+                continue\n+            if not recreate and picking.carrier_file_generated:\n+                continue\n+            carrier = picking.carrier_id\n+            if not carrier or not carrier.carrier_file_id:\n+                continue\n+            if auto and not carrier.carrier_file_id.auto_export:\n+                continue\n+            p_carrier_file_id = picking.carrier_id.carrier_file_id.id\n+            carrier_file_ids.setdefault(p_carrier_file_id, []).\\\n+                append(picking.id)\n+\n+        carrier_files = self.env[\"delivery.carrier.file\"].browse(\n+            carrier_file_ids.keys())\n+        for carrier_file in carrier_files:\n+            carrier_file.generate_files(carrier_file_ids[carrier_file.id])\n+        return True\n+\n+    @api.multi\n+    def action_done(self):\n+        result = super(stock_picking, self).action_done()\n+        self.generate_carrier_files(auto=True)\n+        return result\n+\n+    @api.multi\n+    def copy(self, default=None):\n+        if default is None:\n+            default = {}\n+        default.update({'carrier_file_generated': False})\n+        return super(stock_picking, self).copy(default=default)\n+\n+    @api.multi\n+    @api.depends(\"move_type\", \"move_lines.state\", \"move_lines.picking_id\",\n+                 \"move_lines.partially_available\")\n+    def _state_get(self):\n+        res = super(stock_picking, self)._state_get(None, None)\n+        pickings = self.browse(res.keys())\n+        done_pickings = self.browse([id for id, key in res.iteritems() if\n+                                     key == \"done\"])\n+        if done_pickings:\n+            done_pickings.generate_carrier_files()\n+        for picking in pickings:\n+            picking.state = res[picking.id]\n+\n+    @api.multi\n+    def _get_pickings(self):\n+        return super(stock_picking, self)._get_pickings(None, None)","path":"base_delivery_carrier_files/stock.py","position":95,"original_position":95,"commit_id":"a2825800a528ed6b591237d20946d4ee1eed7270","original_commit_id":"a2825800a528ed6b591237d20946d4ee1eed7270","user":{"login":"yvaucher","id":4158438,"avatar_url":"https://avatars.githubusercontent.com/u/4158438?v=3","gravatar_id":"","url":"https://api.github.com/users/yvaucher","html_url":"https://github.com/yvaucher","followers_url":"https://api.github.com/users/yvaucher/followers","following_url":"https://api.github.com/users/yvaucher/following{/other_user}","gists_url":"https://api.github.com/users/yvaucher/gists{/gist_id}","starred_url":"https://api.github.com/users/yvaucher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yvaucher/subscriptions","organizations_url":"https://api.github.com/users/yvaucher/orgs","repos_url":"https://api.github.com/users/yvaucher/repos","events_url":"https://api.github.com/users/yvaucher/events{/privacy}","received_events_url":"https://api.github.com/users/yvaucher/received_events","type":"User","site_admin":false},"body":"Is this really necessary? If yes, please provide a docstring explaining why.","created_at":"2015-01-29T12:55:31Z","updated_at":"2015-01-29T12:55:31Z","html_url":"https://github.com/OCA/carrier-delivery/pull/47#discussion_r23765252","pull_request_url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/comments/23765252"},"html":{"href":"https://github.com/OCA/carrier-delivery/pull/47#discussion_r23765252"},"pull_request":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47","id":26440715,"html_url":"https://github.com/OCA/carrier-delivery/pull/47","diff_url":"https://github.com/OCA/carrier-delivery/pull/47.diff","patch_url":"https://github.com/OCA/carrier-delivery/pull/47.patch","issue_url":"https://api.github.com/repos/OCA/carrier-delivery/issues/47","number":47,"state":"open","locked":false,"title":"base_delivery_carrier_files module migration to Odoo v8","user":{"login":"kkarolis","id":7696589,"avatar_url":"https://avatars.githubusercontent.com/u/7696589?v=3","gravatar_id":"","url":"https://api.github.com/users/kkarolis","html_url":"https://github.com/kkarolis","followers_url":"https://api.github.com/users/kkarolis/followers","following_url":"https://api.github.com/users/kkarolis/following{/other_user}","gists_url":"https://api.github.com/users/kkarolis/gists{/gist_id}","starred_url":"https://api.github.com/users/kkarolis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkarolis/subscriptions","organizations_url":"https://api.github.com/users/kkarolis/orgs","repos_url":"https://api.github.com/users/kkarolis/repos","events_url":"https://api.github.com/users/kkarolis/events{/privacy}","received_events_url":"https://api.github.com/users/kkarolis/received_events","type":"User","site_admin":false},"body":"","created_at":"2014-12-22T06:19:13Z","updated_at":"2015-01-29T12:55:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11daa0867119a1066f7570d52bb777ca714b176d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47/commits","review_comments_url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47/comments","review_comment_url":"https://api.github.com/repos/OCA/carrier-delivery/pulls/comments/{number}","comments_url":"https://api.github.com/repos/OCA/carrier-delivery/issues/47/comments","statuses_url":"https://api.github.com/repos/OCA/carrier-delivery/statuses/a2825800a528ed6b591237d20946d4ee1eed7270","head":{"label":"kkarolis:base_delivery_carrier_files_migration","ref":"base_delivery_carrier_files_migration","sha":"a2825800a528ed6b591237d20946d4ee1eed7270","user":{"login":"kkarolis","id":7696589,"avatar_url":"https://avatars.githubusercontent.com/u/7696589?v=3","gravatar_id":"","url":"https://api.github.com/users/kkarolis","html_url":"https://github.com/kkarolis","followers_url":"https://api.github.com/users/kkarolis/followers","following_url":"https://api.github.com/users/kkarolis/following{/other_user}","gists_url":"https://api.github.com/users/kkarolis/gists{/gist_id}","starred_url":"https://api.github.com/users/kkarolis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkarolis/subscriptions","organizations_url":"https://api.github.com/users/kkarolis/orgs","repos_url":"https://api.github.com/users/kkarolis/repos","events_url":"https://api.github.com/users/kkarolis/events{/privacy}","received_events_url":"https://api.github.com/users/kkarolis/received_events","type":"User","site_admin":false},"repo":{"id":28145930,"name":"carrier-delivery","full_name":"kkarolis/carrier-delivery","owner":{"login":"kkarolis","id":7696589,"avatar_url":"https://avatars.githubusercontent.com/u/7696589?v=3","gravatar_id":"","url":"https://api.github.com/users/kkarolis","html_url":"https://github.com/kkarolis","followers_url":"https://api.github.com/users/kkarolis/followers","following_url":"https://api.github.com/users/kkarolis/following{/other_user}","gists_url":"https://api.github.com/users/kkarolis/gists{/gist_id}","starred_url":"https://api.github.com/users/kkarolis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kkarolis/subscriptions","organizations_url":"https://api.github.com/users/kkarolis/orgs","repos_url":"https://api.github.com/users/kkarolis/repos","events_url":"https://api.github.com/users/kkarolis/events{/privacy}","received_events_url":"https://api.github.com/users/kkarolis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kkarolis/carrier-delivery","description":"Carriers And Deliveries Management","fork":true,"url":"https://api.github.com/repos/kkarolis/carrier-delivery","forks_url":"https://api.github.com/repos/kkarolis/carrier-delivery/forks","keys_url":"https://api.github.com/repos/kkarolis/carrier-delivery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kkarolis/carrier-delivery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kkarolis/carrier-delivery/teams","hooks_url":"https://api.github.com/repos/kkarolis/carrier-delivery/hooks","issue_events_url":"https://api.github.com/repos/kkarolis/carrier-delivery/issues/events{/number}","events_url":"https://api.github.com/repos/kkarolis/carrier-delivery/events","assignees_url":"https://api.github.com/repos/kkarolis/carrier-delivery/assignees{/user}","branches_url":"https://api.github.com/repos/kkarolis/carrier-delivery/branches{/branch}","tags_url":"https://api.github.com/repos/kkarolis/carrier-delivery/tags","blobs_url":"https://api.github.com/repos/kkarolis/carrier-delivery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kkarolis/carrier-delivery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kkarolis/carrier-delivery/git/refs{/sha}","trees_url":"https://api.github.com/repos/kkarolis/carrier-delivery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kkarolis/carrier-delivery/statuses/{sha}","languages_url":"https://api.github.com/repos/kkarolis/carrier-delivery/languages","stargazers_url":"https://api.github.com/repos/kkarolis/carrier-delivery/stargazers","contributors_url":"https://api.github.com/repos/kkarolis/carrier-delivery/contributors","subscribers_url":"https://api.github.com/repos/kkarolis/carrier-delivery/subscribers","subscription_url":"https://api.github.com/repos/kkarolis/carrier-delivery/subscription","commits_url":"https://api.github.com/repos/kkarolis/carrier-delivery/commits{/sha}","git_commits_url":"https://api.github.com/repos/kkarolis/carrier-delivery/git/commits{/sha}","comments_url":"https://api.github.com/repos/kkarolis/carrier-delivery/comments{/number}","issue_comment_url":"https://api.github.com/repos/kkarolis/carrier-delivery/issues/comments/{number}","contents_url":"https://api.github.com/repos/kkarolis/carrier-delivery/contents/{+path}","compare_url":"https://api.github.com/repos/kkarolis/carrier-delivery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kkarolis/carrier-delivery/merges","archive_url":"https://api.github.com/repos/kkarolis/carrier-delivery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kkarolis/carrier-delivery/downloads","issues_url":"https://api.github.com/repos/kkarolis/carrier-delivery/issues{/number}","pulls_url":"https://api.github.com/repos/kkarolis/carrier-delivery/pulls{/number}","milestones_url":"https://api.github.com/repos/kkarolis/carrier-delivery/milestones{/number}","notifications_url":"https://api.github.com/repos/kkarolis/carrier-delivery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kkarolis/carrier-delivery/labels{/name}","releases_url":"https://api.github.com/repos/kkarolis/carrier-delivery/releases{/id}","created_at":"2014-12-17T16:41:34Z","updated_at":"2014-12-22T18:07:07Z","pushed_at":"2015-01-29T10:56:39Z","git_url":"git://github.com/kkarolis/carrier-delivery.git","ssh_url":"git@github.com:kkarolis/carrier-delivery.git","clone_url":"https://github.com/kkarolis/carrier-delivery.git","svn_url":"https://github.com/kkarolis/carrier-delivery","homepage":"http://www.odoo-community.org/project/18","size":2733,"stargazers_count":1,"watchers_count":1,"language":"Python","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":1,"default_branch":"8.0"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"75a0207094cb62b7d681bfb647dd80dff8aa4a62","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":20890916,"name":"carrier-delivery","full_name":"OCA/carrier-delivery","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/carrier-delivery","description":"Carriers And Deliveries Management","fork":false,"url":"https://api.github.com/repos/OCA/carrier-delivery","forks_url":"https://api.github.com/repos/OCA/carrier-delivery/forks","keys_url":"https://api.github.com/repos/OCA/carrier-delivery/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/carrier-delivery/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/carrier-delivery/teams","hooks_url":"https://api.github.com/repos/OCA/carrier-delivery/hooks","issue_events_url":"https://api.github.com/repos/OCA/carrier-delivery/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/carrier-delivery/events","assignees_url":"https://api.github.com/repos/OCA/carrier-delivery/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/carrier-delivery/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/carrier-delivery/tags","blobs_url":"https://api.github.com/repos/OCA/carrier-delivery/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/carrier-delivery/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/carrier-delivery/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/carrier-delivery/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/carrier-delivery/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/carrier-delivery/languages","stargazers_url":"https://api.github.com/repos/OCA/carrier-delivery/stargazers","contributors_url":"https://api.github.com/repos/OCA/carrier-delivery/contributors","subscribers_url":"https://api.github.com/repos/OCA/carrier-delivery/subscribers","subscription_url":"https://api.github.com/repos/OCA/carrier-delivery/subscription","commits_url":"https://api.github.com/repos/OCA/carrier-delivery/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/carrier-delivery/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/carrier-delivery/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/carrier-delivery/issues/comments/{number}","contents_url":"https://api.github.com/repos/OCA/carrier-delivery/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/carrier-delivery/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/carrier-delivery/merges","archive_url":"https://api.github.com/repos/OCA/carrier-delivery/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/carrier-delivery/downloads","issues_url":"https://api.github.com/repos/OCA/carrier-delivery/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/carrier-delivery/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/carrier-delivery/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/carrier-delivery/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/carrier-delivery/labels{/name}","releases_url":"https://api.github.com/repos/OCA/carrier-delivery/releases{/id}","created_at":"2014-06-16T15:56:19Z","updated_at":"2014-12-21T03:31:12Z","pushed_at":"2015-01-19T12:46:14Z","git_url":"git://github.com/OCA/carrier-delivery.git","ssh_url":"git@github.com:OCA/carrier-delivery.git","clone_url":"https://github.com/OCA/carrier-delivery.git","svn_url":"https://github.com/OCA/carrier-delivery","homepage":"http://www.odoo-community.org/project/18","size":4871,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":6,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47"},"html":{"href":"https://github.com/OCA/carrier-delivery/pull/47"},"issue":{"href":"https://api.github.com/repos/OCA/carrier-delivery/issues/47"},"comments":{"href":"https://api.github.com/repos/OCA/carrier-delivery/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/OCA/carrier-delivery/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/carrier-delivery/statuses/a2825800a528ed6b591237d20946d4ee1eed7270"}}}}