{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/comments/22516006","id":22516006,"diff_hunk":"@@ -130,127 +116,57 @@ def _generate_lines_from_agreements(self, cr, uid, container, line,\n         if they are cheaper in other currences. Then it will choose remaining\n         agreements ordered by price converted in company currency\n \n-        :param container: list of agreements browse\n-        :param qty: quantity to be sourced\n-        :param line: origin requisition line\n+        :param self: origin requisition line\n+        :param agreements: list of agreement which can be used\n+        :param currency: prefered currency for agreement sorting\n \n         :returns: remaining quantity to source\n \n         \"\"\"\n-        agreements = agreements if agreements is not None else []\n-        agreements = self._sort_agreements(cr, uid, agreements, qty,\n-                                           currency=currency)\n+        qty = self.requested_qty\n         if not agreements:\n             return qty\n-        current_agr = agreements.pop(0)\n-        avail = current_agr.available_quantity\n-        if not avail:\n-            return qty\n-        avail_sold = avail - qty\n-        to_consume = qty if avail_sold >= 0 else avail\n-\n-        source_id = self.make_source_line(cr, uid, line, force_qty=to_consume,\n-                                          agreement=current_agr,\n-                                          context=context)\n-        container.append(source_id)\n-        difference = qty - to_consume\n-        if difference:\n-            return self._generate_lines_from_agreements(cr, uid, container,\n-                                                        line, agreements,\n-                                                        difference,\n-                                                        context=context)\n-        else:\n-            return 0\n-\n-    def _source_lines_for_agreements(self, cr, uid, line, agreements,\n-                                     currency=None, context=None):\n-        \"\"\"Generate 1/n source line(s) for one requisition line\n-\n-        This is done using available agreements.\n-        We first look for cheapeast agreement.\n-        Then if no more quantity are available and there is still remaining\n-        needs we look for next cheapest agreement or we create a tender source\n-        line\n-\n-        :param line: requisition line browse record\n-        :returns: (generated line ids, remaining qty not covered by agreement)\n-\n-        \"\"\"\n-        Sourced = namedtuple('Sourced', ['generated', 'remaining'])\n-        qty = line.requested_qty\n-        generated = []\n-        remaining_qty = self._generate_lines_from_agreements(cr, uid,\n-                                                             generated, line,\n-                                                             agreements, qty,\n-                                                             currency=currency,\n-                                                             context=context)\n-        return Sourced(generated, remaining_qty)\n-\n-    def make_source_line(self, cr, uid, line, force_qty=None, agreement=None,\n-                         context=None):\n-        \"\"\"Generate a source line from a requisition line, see\n-        _prepare_line_source for details.\n-\n-        :param line: browse record of origin logistic.request\n-        :param force_qty: if set this quantity will be used instead\n-        of requested quantity\n-        :returns: id of generated source line\n-\n-        \"\"\"\n-        qty = force_qty if force_qty else line.requested_qty\n-        src_obj = self.pool['logistic.requisition.source']\n-        vals = self._prepare_line_source(cr, uid, line,\n-                                         qty=qty,\n-                                         agreement=agreement,\n-                                         context=None)\n-        return src_obj.create(cr, uid, vals, context=context)\n-\n-    def _generate_source_line(self, cr, uid, line, context=None):\n+        agreements = self._sort_agreements(agreements, qty,\n+                                           currency=currency)\n+        src_model = self.env['logistic.requisition.source']\n+        remaining_qty = qty\n+        while remaining_qty and agreements:\n+            current_agr = agreements.pop(0)\n+            avail = current_agr.available_quantity\n+            if not avail:\n+                continue\n+            avail_sold = avail - remaining_qty\n+            to_consume = remaining_qty if avail_sold >= 0 else avail\n+            remaining_qty -= to_consume\n+\n+            values = self._prepare_agreement_source(current_agr,\n+                                                    qty=to_consume)\n+            src_model.create(values)\n+\n+        return remaining_qty\n+\n+    @api.multi\n+    def _generate_sources(self):\n         \"\"\"Generate one or n source line(s) per requisition line.\n \n         Depending on the available resources. If there is framework\n         agreement(s) running we generate one or n source line using agreements\n         otherwise we generate one source line using tender process\n \n-        :param line: browse record of origin logistic.request\n-\n-        :returns: list of generated source line ids\n+        :param self: origin requisition line","path":"framework_agreement_sourcing/model/logistic_requisition.py","position":203,"original_position":203,"commit_id":"bb62a9f323510aaded6d47bef730035aa14e6d29","original_commit_id":"bb62a9f323510aaded6d47bef730035aa14e6d29","user":{"login":"lepistone","id":1314778,"avatar_url":"https://avatars.githubusercontent.com/u/1314778?v=3","gravatar_id":"","url":"https://api.github.com/users/lepistone","html_url":"https://github.com/lepistone","followers_url":"https://api.github.com/users/lepistone/followers","following_url":"https://api.github.com/users/lepistone/following{/other_user}","gists_url":"https://api.github.com/users/lepistone/gists{/gist_id}","starred_url":"https://api.github.com/users/lepistone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lepistone/subscriptions","organizations_url":"https://api.github.com/users/lepistone/orgs","repos_url":"https://api.github.com/users/lepistone/repos","events_url":"https://api.github.com/users/lepistone/events{/privacy}","received_events_url":"https://api.github.com/users/lepistone/received_events","type":"User","site_admin":false},"body":"The return value is probably more important (is it a list? a recordset?)","created_at":"2015-01-06T09:58:43Z","updated_at":"2015-01-06T09:58:43Z","html_url":"https://github.com/OCA/vertical-ngo/pull/97#discussion_r22516006","pull_request_url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97","_links":{"self":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/comments/22516006"},"html":{"href":"https://github.com/OCA/vertical-ngo/pull/97#discussion_r22516006"},"pull_request":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97","id":25903515,"html_url":"https://github.com/OCA/vertical-ngo/pull/97","diff_url":"https://github.com/OCA/vertical-ngo/pull/97.diff","patch_url":"https://github.com/OCA/vertical-ngo/pull/97.patch","issue_url":"https://api.github.com/repos/OCA/vertical-ngo/issues/97","number":97,"state":"open","locked":false,"title":"Add module logistics_requisition_donation","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":"This one is based on (includes other PR commits) \r\n\r\n- [ ] #92 ","created_at":"2014-12-11T14:34:57Z","updated_at":"2015-01-06T09:58:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5df063151b324cbfec694c1625eca5e0b4d2c043","assignee":{"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},"milestone":null,"commits_url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97/commits","review_comments_url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97/comments","review_comment_url":"https://api.github.com/repos/OCA/vertical-ngo/pulls/comments/{number}","comments_url":"https://api.github.com/repos/OCA/vertical-ngo/issues/97/comments","statuses_url":"https://api.github.com/repos/OCA/vertical-ngo/statuses/bb62a9f323510aaded6d47bef730035aa14e6d29","head":{"label":"yvaucher:8.0-add-logistics_requisition_donation","ref":"8.0-add-logistics_requisition_donation","sha":"bb62a9f323510aaded6d47bef730035aa14e6d29","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},"repo":{"id":23216855,"name":"vertical-ngo","full_name":"yvaucher/vertical-ngo","owner":{"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},"private":false,"html_url":"https://github.com/yvaucher/vertical-ngo","description":"","fork":true,"url":"https://api.github.com/repos/yvaucher/vertical-ngo","forks_url":"https://api.github.com/repos/yvaucher/vertical-ngo/forks","keys_url":"https://api.github.com/repos/yvaucher/vertical-ngo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yvaucher/vertical-ngo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yvaucher/vertical-ngo/teams","hooks_url":"https://api.github.com/repos/yvaucher/vertical-ngo/hooks","issue_events_url":"https://api.github.com/repos/yvaucher/vertical-ngo/issues/events{/number}","events_url":"https://api.github.com/repos/yvaucher/vertical-ngo/events","assignees_url":"https://api.github.com/repos/yvaucher/vertical-ngo/assignees{/user}","branches_url":"https://api.github.com/repos/yvaucher/vertical-ngo/branches{/branch}","tags_url":"https://api.github.com/repos/yvaucher/vertical-ngo/tags","blobs_url":"https://api.github.com/repos/yvaucher/vertical-ngo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yvaucher/vertical-ngo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yvaucher/vertical-ngo/git/refs{/sha}","trees_url":"https://api.github.com/repos/yvaucher/vertical-ngo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yvaucher/vertical-ngo/statuses/{sha}","languages_url":"https://api.github.com/repos/yvaucher/vertical-ngo/languages","stargazers_url":"https://api.github.com/repos/yvaucher/vertical-ngo/stargazers","contributors_url":"https://api.github.com/repos/yvaucher/vertical-ngo/contributors","subscribers_url":"https://api.github.com/repos/yvaucher/vertical-ngo/subscribers","subscription_url":"https://api.github.com/repos/yvaucher/vertical-ngo/subscription","commits_url":"https://api.github.com/repos/yvaucher/vertical-ngo/commits{/sha}","git_commits_url":"https://api.github.com/repos/yvaucher/vertical-ngo/git/commits{/sha}","comments_url":"https://api.github.com/repos/yvaucher/vertical-ngo/comments{/number}","issue_comment_url":"https://api.github.com/repos/yvaucher/vertical-ngo/issues/comments/{number}","contents_url":"https://api.github.com/repos/yvaucher/vertical-ngo/contents/{+path}","compare_url":"https://api.github.com/repos/yvaucher/vertical-ngo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yvaucher/vertical-ngo/merges","archive_url":"https://api.github.com/repos/yvaucher/vertical-ngo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yvaucher/vertical-ngo/downloads","issues_url":"https://api.github.com/repos/yvaucher/vertical-ngo/issues{/number}","pulls_url":"https://api.github.com/repos/yvaucher/vertical-ngo/pulls{/number}","milestones_url":"https://api.github.com/repos/yvaucher/vertical-ngo/milestones{/number}","notifications_url":"https://api.github.com/repos/yvaucher/vertical-ngo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yvaucher/vertical-ngo/labels{/name}","releases_url":"https://api.github.com/repos/yvaucher/vertical-ngo/releases{/id}","created_at":"2014-08-22T07:27:59Z","updated_at":"2014-12-11T10:31:33Z","pushed_at":"2015-01-06T09:56:32Z","git_url":"git://github.com/yvaucher/vertical-ngo.git","ssh_url":"git@github.com:yvaucher/vertical-ngo.git","clone_url":"https://github.com/yvaucher/vertical-ngo.git","svn_url":"https://github.com/yvaucher/vertical-ngo","homepage":null,"size":4573,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"8.0"}},"base":{"label":"OCA:8.0","ref":"8.0","sha":"b94523f0bef590e1fa806088dfd025e65182d684","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":20897575,"name":"vertical-ngo","full_name":"OCA/vertical-ngo","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/vertical-ngo","description":"","fork":false,"url":"https://api.github.com/repos/OCA/vertical-ngo","forks_url":"https://api.github.com/repos/OCA/vertical-ngo/forks","keys_url":"https://api.github.com/repos/OCA/vertical-ngo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/vertical-ngo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/vertical-ngo/teams","hooks_url":"https://api.github.com/repos/OCA/vertical-ngo/hooks","issue_events_url":"https://api.github.com/repos/OCA/vertical-ngo/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/vertical-ngo/events","assignees_url":"https://api.github.com/repos/OCA/vertical-ngo/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/vertical-ngo/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/vertical-ngo/tags","blobs_url":"https://api.github.com/repos/OCA/vertical-ngo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/vertical-ngo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/vertical-ngo/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/vertical-ngo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/vertical-ngo/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/vertical-ngo/languages","stargazers_url":"https://api.github.com/repos/OCA/vertical-ngo/stargazers","contributors_url":"https://api.github.com/repos/OCA/vertical-ngo/contributors","subscribers_url":"https://api.github.com/repos/OCA/vertical-ngo/subscribers","subscription_url":"https://api.github.com/repos/OCA/vertical-ngo/subscription","commits_url":"https://api.github.com/repos/OCA/vertical-ngo/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/vertical-ngo/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/vertical-ngo/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/vertical-ngo/issues/comments/{number}","contents_url":"https://api.github.com/repos/OCA/vertical-ngo/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/vertical-ngo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/vertical-ngo/merges","archive_url":"https://api.github.com/repos/OCA/vertical-ngo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/vertical-ngo/downloads","issues_url":"https://api.github.com/repos/OCA/vertical-ngo/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/vertical-ngo/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/vertical-ngo/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/vertical-ngo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/vertical-ngo/labels{/name}","releases_url":"https://api.github.com/repos/OCA/vertical-ngo/releases{/id}","created_at":"2014-06-16T19:24:02Z","updated_at":"2014-12-23T13:15:38Z","pushed_at":"2014-12-23T13:15:38Z","git_url":"git://github.com/OCA/vertical-ngo.git","ssh_url":"git@github.com:OCA/vertical-ngo.git","clone_url":"https://github.com/OCA/vertical-ngo.git","svn_url":"https://github.com/OCA/vertical-ngo","homepage":null,"size":5032,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":13,"forks":12,"open_issues":13,"watchers":1,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97"},"html":{"href":"https://github.com/OCA/vertical-ngo/pull/97"},"issue":{"href":"https://api.github.com/repos/OCA/vertical-ngo/issues/97"},"comments":{"href":"https://api.github.com/repos/OCA/vertical-ngo/issues/97/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/OCA/vertical-ngo/pulls/97/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/vertical-ngo/statuses/bb62a9f323510aaded6d47bef730035aa14e6d29"}}}}