{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/commission/pulls/comments/23372804","id":23372804,"diff_hunk":"@@ -0,0 +1,653 @@\n+# -*- coding: utf-8 -*-\n+##############################################################################\n+#\n+#    OpenERP, Open Source Management Solution\n+#    Copyright (C) 2011 Pexego Sistemas Informáticos (<http://www.pexego.es>).\n+#    All Rights Reserved\n+#    $Id$\n+#\n+#    This program is free software: you can redistribute it and/or modify\n+#    it under the terms of the GNU General Public License as published by\n+#    the Free Software Foundation, either version 3 of the License, or\n+#    (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 General Public License for more details.\n+#\n+#    You should have received a copy of the GNU General Public License\n+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+#\n+##############################################################################\n+\"\"\"Objetos sobre las liquidación\"\"\"\n+\n+from openerp import models, fields, _\n+from openerp import tools\n+from openerp import exceptions\n+\n+\n+class settlement(models.Model):\n+    \"\"\"Settlement model\"\"\"\n+\n+    _name = \"settlement\"\n+\n+    name = fields.Char(\n+        string=\"Settlement period\",\n+        required=True,\n+        readonly=True\n+    )\n+\n+    total = fields.Float(string=\"Total\", readonly=True)\n+\n+    date_from = fields.Date(string=\"From\")\n+\n+    date_to = fields.Date(string=\"To\")\n+\n+    settlement_agent_id = fields.One2many(\n+        \"settlement.agent\",\n+        \"settlement_id\",\n+        string=\"Settlement agents\",\n+        readonly=True)\n+\n+    date = fields.Datetime(\n+        string=\"Created Date\",\n+        required=True,\n+        default=fields.Datetime.now()\n+    )\n+\n+    # TODO: Workflow is necessary to manage 'cancel' state/transition\n+    state = fields.Selection(\n+        [\n+            (\"invoiced\", \"Invoiced\"),\n+            (\"settled\", \"Settled\"),\n+            (\"cancel\", \"Cancel\")\n+        ],\n+        string=\"State\",\n+        readonly=True,\n+        default=\"settled\"\n+    )\n+\n+    def action_invoice_create(self, cursor, user, ids,\n+                              journal_id, product_id, context=None):\n+        if context is None:\n+            context = {}\n+        agents_pool = self.pool.get('settlement.agent')\n+        res = {}\n+        for settlement in self.browse(cursor, user, ids, context=context):\n+            settlement_agent_ids = map(\n+                lambda x: x.id, settlement.settlement_agent_id\n+            )\n+            invoices_agent = agents_pool.action_invoice_create(\n+                cursor, user,\n+                settlement_agent_ids,\n+                journal_id,\n+                product_id,\n+                context=context\n+            )\n+            res[settlement.id] = invoices_agent.values()\n+        return res\n+\n+    def calculate(self, cr, uid, ids, agent_ids,\n+                  date_from, date_to, context=None):\n+        \"\"\"genera una entrada de liquidación por agente\"\"\"\n+        # Busca todas las líneas de liquidación facturadas en un período\n+        if context is None:\n+            context = {}\n+        sale_agent_pool = self.pool.get('sale.agent')\n+        settlement_agent_pool = self.pool.get('settlement.agent')\n+        agents = sale_agent_pool.browse(cr, uid, agent_ids, context=context)\n+        total = 0\n+        for agent in agents:\n+            # genera una entrada de liquidación por agente\n+            liq_agent_id = settlement_agent_pool.create(\n+                cr, uid,\n+                {'agent_id': agent.id, 'settlement_id': ids},\n+                context=context\n+            )\n+            settlement_agent_pool.calculate(\n+                cr, uid,\n+                liq_agent_id,\n+                date_from,\n+                date_to,\n+                context=context\n+            )\n+            liq_agent = settlement_agent_pool.browse(\n+                cr, uid,\n+                liq_agent_id,\n+                context=context\n+            )\n+            total = total + liq_agent.total\n+        return self.write(cr, uid, ids, {'total': total}, context=context)\n+\n+    def action_cancel(self, cr, uid, ids, context=None):\n+        \"\"\"Cancel the liquidation\"\"\"\n+        if context is None:\n+            context = {}","path":"sale_commission/model/settled.py","position":126,"original_position":126,"commit_id":"79c2b8b1554c0bbb23807cd7fd80c60c4cda25f7","original_commit_id":"79c2b8b1554c0bbb23807cd7fd80c60c4cda25f7","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":"Remove context check","created_at":"2015-01-22T12:50:40Z","updated_at":"2015-01-22T12:50:40Z","html_url":"https://github.com/OCA/commission/pull/7#discussion_r23372804","pull_request_url":"https://api.github.com/repos/OCA/commission/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/OCA/commission/pulls/comments/23372804"},"html":{"href":"https://github.com/OCA/commission/pull/7#discussion_r23372804"},"pull_request":{"href":"https://api.github.com/repos/OCA/commission/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/commission/pulls/7","id":24139969,"html_url":"https://github.com/OCA/commission/pull/7","diff_url":"https://github.com/OCA/commission/pull/7.diff","patch_url":"https://github.com/OCA/commission/pull/7.patch","issue_url":"https://api.github.com/repos/OCA/commission/issues/7","number":7,"state":"open","locked":false,"title":"Migrated sale_commission to Odoo v8.0","user":{"login":"gborelli","id":301738,"avatar_url":"https://avatars.githubusercontent.com/u/301738?v=3","gravatar_id":"","url":"https://api.github.com/users/gborelli","html_url":"https://github.com/gborelli","followers_url":"https://api.github.com/users/gborelli/followers","following_url":"https://api.github.com/users/gborelli/following{/other_user}","gists_url":"https://api.github.com/users/gborelli/gists{/gist_id}","starred_url":"https://api.github.com/users/gborelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gborelli/subscriptions","organizations_url":"https://api.github.com/users/gborelli/orgs","repos_url":"https://api.github.com/users/gborelli/repos","events_url":"https://api.github.com/users/gborelli/events{/privacy}","received_events_url":"https://api.github.com/users/gborelli/received_events","type":"User","site_admin":false},"body":"I've migrate old module by maintaining the same functionalities.","created_at":"2014-11-10T11:10:18Z","updated_at":"2015-01-22T12:50:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"87b36cf985b447f07db2a1113b8f88648079ed50","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OCA/commission/pulls/7/commits","review_comments_url":"https://api.github.com/repos/OCA/commission/pulls/7/comments","review_comment_url":"https://api.github.com/repos/OCA/commission/pulls/comments/{number}","comments_url":"https://api.github.com/repos/OCA/commission/issues/7/comments","statuses_url":"https://api.github.com/repos/OCA/commission/statuses/79c2b8b1554c0bbb23807cd7fd80c60c4cda25f7","head":{"label":"abstract-open-solutions:8.0-gborelli","ref":"8.0-gborelli","sha":"79c2b8b1554c0bbb23807cd7fd80c60c4cda25f7","user":{"login":"abstract-open-solutions","id":1053378,"avatar_url":"https://avatars.githubusercontent.com/u/1053378?v=3","gravatar_id":"","url":"https://api.github.com/users/abstract-open-solutions","html_url":"https://github.com/abstract-open-solutions","followers_url":"https://api.github.com/users/abstract-open-solutions/followers","following_url":"https://api.github.com/users/abstract-open-solutions/following{/other_user}","gists_url":"https://api.github.com/users/abstract-open-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/abstract-open-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abstract-open-solutions/subscriptions","organizations_url":"https://api.github.com/users/abstract-open-solutions/orgs","repos_url":"https://api.github.com/users/abstract-open-solutions/repos","events_url":"https://api.github.com/users/abstract-open-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/abstract-open-solutions/received_events","type":"Organization","site_admin":false},"repo":{"id":26230368,"name":"commission","full_name":"abstract-open-solutions/commission","owner":{"login":"abstract-open-solutions","id":1053378,"avatar_url":"https://avatars.githubusercontent.com/u/1053378?v=3","gravatar_id":"","url":"https://api.github.com/users/abstract-open-solutions","html_url":"https://github.com/abstract-open-solutions","followers_url":"https://api.github.com/users/abstract-open-solutions/followers","following_url":"https://api.github.com/users/abstract-open-solutions/following{/other_user}","gists_url":"https://api.github.com/users/abstract-open-solutions/gists{/gist_id}","starred_url":"https://api.github.com/users/abstract-open-solutions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abstract-open-solutions/subscriptions","organizations_url":"https://api.github.com/users/abstract-open-solutions/orgs","repos_url":"https://api.github.com/users/abstract-open-solutions/repos","events_url":"https://api.github.com/users/abstract-open-solutions/events{/privacy}","received_events_url":"https://api.github.com/users/abstract-open-solutions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/abstract-open-solutions/commission","description":"","fork":true,"url":"https://api.github.com/repos/abstract-open-solutions/commission","forks_url":"https://api.github.com/repos/abstract-open-solutions/commission/forks","keys_url":"https://api.github.com/repos/abstract-open-solutions/commission/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abstract-open-solutions/commission/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abstract-open-solutions/commission/teams","hooks_url":"https://api.github.com/repos/abstract-open-solutions/commission/hooks","issue_events_url":"https://api.github.com/repos/abstract-open-solutions/commission/issues/events{/number}","events_url":"https://api.github.com/repos/abstract-open-solutions/commission/events","assignees_url":"https://api.github.com/repos/abstract-open-solutions/commission/assignees{/user}","branches_url":"https://api.github.com/repos/abstract-open-solutions/commission/branches{/branch}","tags_url":"https://api.github.com/repos/abstract-open-solutions/commission/tags","blobs_url":"https://api.github.com/repos/abstract-open-solutions/commission/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abstract-open-solutions/commission/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abstract-open-solutions/commission/git/refs{/sha}","trees_url":"https://api.github.com/repos/abstract-open-solutions/commission/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abstract-open-solutions/commission/statuses/{sha}","languages_url":"https://api.github.com/repos/abstract-open-solutions/commission/languages","stargazers_url":"https://api.github.com/repos/abstract-open-solutions/commission/stargazers","contributors_url":"https://api.github.com/repos/abstract-open-solutions/commission/contributors","subscribers_url":"https://api.github.com/repos/abstract-open-solutions/commission/subscribers","subscription_url":"https://api.github.com/repos/abstract-open-solutions/commission/subscription","commits_url":"https://api.github.com/repos/abstract-open-solutions/commission/commits{/sha}","git_commits_url":"https://api.github.com/repos/abstract-open-solutions/commission/git/commits{/sha}","comments_url":"https://api.github.com/repos/abstract-open-solutions/commission/comments{/number}","issue_comment_url":"https://api.github.com/repos/abstract-open-solutions/commission/issues/comments/{number}","contents_url":"https://api.github.com/repos/abstract-open-solutions/commission/contents/{+path}","compare_url":"https://api.github.com/repos/abstract-open-solutions/commission/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abstract-open-solutions/commission/merges","archive_url":"https://api.github.com/repos/abstract-open-solutions/commission/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abstract-open-solutions/commission/downloads","issues_url":"https://api.github.com/repos/abstract-open-solutions/commission/issues{/number}","pulls_url":"https://api.github.com/repos/abstract-open-solutions/commission/pulls{/number}","milestones_url":"https://api.github.com/repos/abstract-open-solutions/commission/milestones{/number}","notifications_url":"https://api.github.com/repos/abstract-open-solutions/commission/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abstract-open-solutions/commission/labels{/name}","releases_url":"https://api.github.com/repos/abstract-open-solutions/commission/releases{/id}","created_at":"2014-11-05T17:12:21Z","updated_at":"2014-09-30T16:30:21Z","pushed_at":"2014-11-20T13:07:12Z","git_url":"git://github.com/abstract-open-solutions/commission.git","ssh_url":"git@github.com:abstract-open-solutions/commission.git","clone_url":"https://github.com/abstract-open-solutions/commission.git","svn_url":"https://github.com/abstract-open-solutions/commission","homepage":null,"size":388,"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:8.0","ref":"8.0","sha":"fb54b77870b2c5e74ce19098419a10e76195e26e","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":20922238,"name":"commission","full_name":"OCA/commission","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/commission","description":"","fork":false,"url":"https://api.github.com/repos/OCA/commission","forks_url":"https://api.github.com/repos/OCA/commission/forks","keys_url":"https://api.github.com/repos/OCA/commission/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/commission/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/commission/teams","hooks_url":"https://api.github.com/repos/OCA/commission/hooks","issue_events_url":"https://api.github.com/repos/OCA/commission/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/commission/events","assignees_url":"https://api.github.com/repos/OCA/commission/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/commission/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/commission/tags","blobs_url":"https://api.github.com/repos/OCA/commission/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/commission/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/commission/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/commission/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/commission/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/commission/languages","stargazers_url":"https://api.github.com/repos/OCA/commission/stargazers","contributors_url":"https://api.github.com/repos/OCA/commission/contributors","subscribers_url":"https://api.github.com/repos/OCA/commission/subscribers","subscription_url":"https://api.github.com/repos/OCA/commission/subscription","commits_url":"https://api.github.com/repos/OCA/commission/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/commission/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/commission/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/commission/issues/comments/{number}","contents_url":"https://api.github.com/repos/OCA/commission/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/commission/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/commission/merges","archive_url":"https://api.github.com/repos/OCA/commission/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/commission/downloads","issues_url":"https://api.github.com/repos/OCA/commission/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/commission/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/commission/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/commission/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/commission/labels{/name}","releases_url":"https://api.github.com/repos/OCA/commission/releases{/id}","created_at":"2014-06-17T12:22:39Z","updated_at":"2014-12-18T06:35:59Z","pushed_at":"2014-12-18T06:35:59Z","git_url":"git://github.com/OCA/commission.git","ssh_url":"git@github.com:OCA/commission.git","clone_url":"https://github.com/OCA/commission.git","svn_url":"https://github.com/OCA/commission","homepage":null,"size":482,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":3,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/commission/pulls/7"},"html":{"href":"https://github.com/OCA/commission/pull/7"},"issue":{"href":"https://api.github.com/repos/OCA/commission/issues/7"},"comments":{"href":"https://api.github.com/repos/OCA/commission/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/commission/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/commission/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/OCA/commission/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/commission/statuses/79c2b8b1554c0bbb23807cd7fd80c60c4cda25f7"}}}}