GitHub PullRequestReviewCommentEvent at 2014-07-03 09:16:27
Repository: odoo
Actor: tde-banana-odoo
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/14504054","id":14504054,"diff_hunk":"@@ -0,0 +1,321 @@\n+\n+from openerp.osv import osv\n+from openerp.osv import fields\n+from openerp.tools.translate import _\n+from openerp import SUPERUSER_ID\n+\n+class res_company(osv.osv):\n+    _inherit = 'res.company'\n+\n+    _columns = {\n+        'so_from_po': fields.boolean(\"Create Sale Orders when buying to this company\", help='Generate a Sale Order when a Purchase Order with this company as supplier is created.'),\n+        'po_from_so': fields.boolean(\"Create Purchase Orders when selling to this company\", help='Generate a Purchase Order when a Sale Order with this company as customer is created.'),\n+        'auto_generate_invoices': fields.boolean(\"Create Invoices/Refunds when encoding invoices/refunds made to this company\", help=\"Generate Customer/Supplier Invoices (and refunds) when encoding invoices (or refunds) made to this company.\\n e.g: Generate a Customer Invoice when a Supplier Invoice with this company as supplier is created.\"),\n+        'auto_validation': fields.boolean('Sale/Purchase Orders Auto Validation', help=\"When a Sale Order or a Purchase Order is created by a multi company rule for this company, it will automatically validate it\"),\n+        'intercompany_user_id': fields.many2one('res.users', 'Inter Company User', help=\"Responsible user for creation of documents triggered by intercompany rules.\"),\n+        'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse For Purchase Orders', help=\"Default value to set on Purchase Orders that will be created based on Sale Orders made to this company\")\n+    }\n+\n+    _defaults = {\n+        'intercompany_user_id': SUPERUSER_ID,\n+    }\n+\n+    def _find_company_from_partner(self, cr, uid, partner_id, context=None):\n+        \"\"\" @Return : company_id\"\"\"\n+        company_ids = self.search(cr, SUPERUSER_ID, [('partner_id', '=', partner_id)], context=context)\n+        if company_ids:\n+            return self.browse(cr, SUPERUSER_ID, company_ids[0], context=context)\n+\n+    def _check_intercompany_missmatch_selection(self, cr, uid, ids, context=None):\n+        for company in self.browse(cr, uid, ids, context=context):\n+            if (company.po_from_so or company.so_from_po) and company.auto_generate_invoices:\n+                raise osv.except_osv(_('Invalid Action!'), _(\"You cannot select to create invoices based on other invoices simultaneously with another option ('Create Sale Orders when buying to this company' or 'Create Purchase Orders when selling to this company')!\"))\n+        return True\n+\n+    _constraints = [\n+        (_check_intercompany_missmatch_selection, 'Invalid Action: Cannot Select group selection for intercompany', []),\n+    ]\n+\n+class sale_order(osv.osv):\n+    _inherit = \"sale.order\"\n+    _columns = {\n+        'auto_generated': fields.boolean('Auto Generated Sale Order'),\n+        'auto_po_id': fields.many2one('purchase.order', 'Source Purchase Order', readonly=True),\n+    }\n+\n+    def copy(self, cr, uid, id, default=None, context=None):\n+        if default is None:\n+            default = {}\n+        default.update({'auto_po_id': False, 'auto_generated': False})\n+        return super(sale_order, self).copy(cr, uid, id, default=default, context=context)\n+\n+    def action_button_confirm(self, cr, uid, ids, context=None):\n+        \"\"\" Overwrite method also generate intercompany purchase order base on conditions.\"\"\"\n+        company_obj = self.pool.get('res.company')\n+\n+        res = super(sale_order, self).action_button_confirm(cr, uid, ids, context=context)\n+\n+        for order in self.browse(cr, uid, ids, context=context):\n+            #If company_id not found, return to normal behavior\n+            if not order.company_id:\n+                continue\n+            #Total check for intersale relation.\n+            self._check_amount_total(cr, uid, order.id, context=context)\n+\n+            company_rec = company_obj._find_company_from_partner(cr, uid, order.partner_id.id, context=context)\n+            if company_rec and company_rec.po_from_so and (not order.auto_generated):\n+                self.action_create_po(cr, uid, ids, order.id, company_rec, context=context)\n+        return res\n+\n+    def _po_line_vals(self, cr, uid, line, company_partner, date_order, purchase_id, company, context=None):\n+        \"\"\" @ return : Purchase Line values dictionary \"\"\"\n+        line_obj = self.pool.get('purchase.order.line')\n+        tax_obj = self.pool.get('account.tax')\n+\n+        #price on PO line should be line - discount\n+        price = line.price_unit - (line.price_unit * (line.discount / 100))\n+\n+        #Computing Default taxes of lines. It may not affect because of parallel company relation\n+        taxes_ids = [x.id for x in line.tax_id]\n+        if line.product_id:\n+            onchange_lines = line_obj.onchange_product_id(cr, uid, [], False, line.product_id and line.product_id.id or False, line.product_uom_qty, line.product_id and line.product_id.uom_po_id.id or False, company_partner.id, context=context)\n+            if onchange_lines.get('value') and onchange_lines['value'].get('taxes_id'):\n+                taxes_ids = onchange_lines['value']['taxes_id']\n+        #Fetch taxes by company not by inter-company user\n+        cmpny_wise_taxes = []\n+        for tx_rec in tax_obj.browse(cr, SUPERUSER_ID, taxes_ids, context=context):\n+            if tx_rec.company_id.id == company.id:\n+                cmpny_wise_taxes.append(tx_rec.id)","path":"addons/inter_company_rules/models/inter_company_so_po.py","position":88,"original_position":88,"commit_id":"42838ac4257f9729244a43c84c60c896dc141f0f","original_commit_id":"42838ac4257f9729244a43c84c60c896dc141f0f","user":{"login":"tde-banana-odoo","id":7501424,"avatar_url":"https://avatars.githubusercontent.com/u/7501424?","gravatar_id":"3a07ea767372b5ecb3f50ec7c3a36dd6","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":"See below: can be simplified using list comprehension.","created_at":"2014-07-03T09:16:27Z","updated_at":"2014-07-03T09:16:27Z","html_url":"https://github.com/odoo/odoo/pull/808#discussion_r14504054","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/808","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/14504054"},"html":{"href":"https://github.com/odoo/odoo/pull/808#discussion_r14504054"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/808"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/808","id":17700358,"html_url":"https://github.com/odoo/odoo/pull/808","diff_url":"https://github.com/odoo/odoo/pull/808.diff","patch_url":"https://github.com/odoo/odoo/pull/808.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/808","number":808,"state":"open","title":"Master intercompany rules tpa","user":{"login":"rim-odoo","id":7300760,"avatar_url":"https://avatars.githubusercontent.com/u/7300760?","gravatar_id":"8976e9830d6a233676c8973ae5a1c981","url":"https://api.github.com/users/rim-odoo","html_url":"https://github.com/rim-odoo","followers_url":"https://api.github.com/users/rim-odoo/followers","following_url":"https://api.github.com/users/rim-odoo/following{/other_user}","gists_url":"https://api.github.com/users/rim-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/rim-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rim-odoo/subscriptions","organizations_url":"https://api.github.com/users/rim-odoo/orgs","repos_url":"https://api.github.com/users/rim-odoo/repos","events_url":"https://api.github.com/users/rim-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/rim-odoo/received_events","type":"User","site_admin":false},"body":"https://www.odoo.com/web#id=6962&view_type=form&model=project.task&action=333&active_id=131\r\nhttps://pad.odoo.com/p/r.IOcwt0uWZx1OKJiT","created_at":"2014-06-27T12:37:32Z","updated_at":"2014-07-03T09:16:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f1bed6cfaef17d9ba64c833249638cdad48e3a69","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/808/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/808/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments/{number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/808/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/42838ac4257f9729244a43c84c60c896dc141f0f","head":{"label":"odoo-dev:master-intercompany-rules-tpa","ref":"master-intercompany-rules-tpa","sha":"42838ac4257f9729244a43c84c60c896dc141f0f","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?","gravatar_id":null,"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?","gravatar_id":null,"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-06-25T14:26:37Z","pushed_at":"2014-07-03T09:04:46Z","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":824344,"stargazers_count":21,"watchers_count":21,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":21,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"8de012946b2651345b77be9ebc5b367c04a7d3ff","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?","gravatar_id":null,"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?","gravatar_id":null,"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 Business Apps.","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":"2014-07-03T08:58:36Z","pushed_at":"2014-07-03T07:37:00Z","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":765323,"stargazers_count":834,"watchers_count":834,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":498,"mirror_url":null,"open_issues_count":343,"forks":498,"open_issues":343,"watchers":834,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/808"},"html":{"href":"https://github.com/odoo/odoo/pull/808"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/808"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/808/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/808/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/808/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/42838ac4257f9729244a43c84c60c896dc141f0f"}}}}