{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/partner-contact/pulls/comments/86494477","pull_request_review_id":7150951,"id":86494477,"diff_hunk":"@@ -0,0 +1,43 @@\n+# -*- coding: utf-8 -*-\n+# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>\n+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).\n+\n+from openerp import api, fields, models\n+from lxml import etree\n+\n+\n+class SaleOrder(models.Model):\n+    _inherit = 'sale.order'\n+\n+    default_sale_discount = fields.Float(\n+        related=\"partner_id.commercial_partner_id.default_sale_discount\",\n+        string=\"Default sales discount (%)\",\n+    )\n+\n+    @api.model\n+    def fields_view_get(self, view_id=None, view_type='form', toolbar=False,\n+                        submenu=False):\n+        \"\"\"Inject the default in the context of the line this way for\n+        making it inheritable.\n+        \"\"\"\n+        res = super(SaleOrder, self).fields_view_get(\n+            view_id=view_id, view_type=view_type, toolbar=toolbar,\n+            submenu=submenu\n+        )\n+        if view_type != 'form':  # pragma: no cover\n+            return res\n+        eview = etree.fromstring(res['arch'])\n+        xml_order_line = eview.xpath(\"//field[@name='order_line']\")\n+        xml_discount = eview.xpath(\"//field[@name='default_sale_discount']\")\n+        if xml_order_line and xml_discount:\n+            # This should be handled in \"string\" mode\n+            context = xml_order_line[0].get('context', '{}')\n+            index = context.find('{')\n+            context = (\n+                context[:index + 1] +\n+                \"'default_discount': default_sale_discount, \" +\n+                context[index + 1:]\n+            )\n+            xml_order_line[0].set('context', context)","path":"partner_default_sale_discount/models/sale_order.py","position":41,"original_position":41,"commit_id":"d56800327f4a8a1859f2c41bb332f1fdc643ec45","original_commit_id":"d56800327f4a8a1859f2c41bb332f1fdc643ec45","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"body":"Good idea, @Yajo, changing it...","created_at":"2016-11-04T06:32:09Z","updated_at":"2016-11-04T06:32:09Z","html_url":"https://github.com/OCA/partner-contact/pull/322#discussion_r86494477","pull_request_url":"https://api.github.com/repos/OCA/partner-contact/pulls/322","_links":{"self":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/comments/86494477"},"html":{"href":"https://github.com/OCA/partner-contact/pull/322#discussion_r86494477"},"pull_request":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/322"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/partner-contact/pulls/322","id":91804043,"html_url":"https://github.com/OCA/partner-contact/pull/322","diff_url":"https://github.com/OCA/partner-contact/pull/322.diff","patch_url":"https://github.com/OCA/partner-contact/pull/322.patch","issue_url":"https://api.github.com/repos/OCA/partner-contact/issues/322","number":322,"state":"open","locked":false,"title":"[ADD] partner_default_sale_discount","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars.githubusercontent.com/u/7165771?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrobaeza","html_url":"https://github.com/pedrobaeza","followers_url":"https://api.github.com/users/pedrobaeza/followers","following_url":"https://api.github.com/users/pedrobaeza/following{/other_user}","gists_url":"https://api.github.com/users/pedrobaeza/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrobaeza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrobaeza/subscriptions","organizations_url":"https://api.github.com/users/pedrobaeza/orgs","repos_url":"https://api.github.com/users/pedrobaeza/repos","events_url":"https://api.github.com/users/pedrobaeza/events{/privacy}","received_events_url":"https://api.github.com/users/pedrobaeza/received_events","type":"User","site_admin":false},"body":"Default sales discount per partner\r\n==================================\r\n\r\nThis module allows to define at partner level a default discount to be applied\r\non sales orders as the default one. As the field is a company dependent one,\r\nyou can configure a different value for the partner for each of your companies.\r\n\r\nConfiguration\r\n=============\r\n\r\nEnabling the use of discounts in Odoo:\r\n\r\n* Go to *Sales > Configuration > Settings*\r\n* On the group \"Quotations & Sales\", select the option \"Allow discounts on\r\n  sales order lines\" for the \"Discount\" section.\r\n\r\nSetting a default sales discount:\r\n\r\n* Then, go to *Sales > Customers*.\r\n* Create or modify a customer.\r\n* Go to \"Sales & Purchases\" page.\r\n* In the \"Sale\" section, there's a field called \"Default sales discount (%)\"\r\n  where you can fill the default discount percentage.\r\n* This value can only be filled at company partners, not for contacts.\r\n\r\nUsage\r\n=====\r\n\r\nTo use this module, you need to:\r\n\r\n* Go to *Sales > Quotations*.\r\n* Create a new quotation.\r\n* Select a partner with a default discount applied.\r\n* Create an order line, and you will see this discount as default in the line.\r\n\r\nKnown issues / Roadmap\r\n======================\r\n\r\n* This module doesn't work with *product_visible_discount*, as it overwrites\r\n  the discount field with its own value.","created_at":"2016-11-01T15:27:46Z","updated_at":"2016-11-04T06:32:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5a2b6a3c7bf064735a3c509a7ea88aa6e06c00d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/OCA/partner-contact/pulls/322/commits","review_comments_url":"https://api.github.com/repos/OCA/partner-contact/pulls/322/comments","review_comment_url":"https://api.github.com/repos/OCA/partner-contact/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/partner-contact/issues/322/comments","statuses_url":"https://api.github.com/repos/OCA/partner-contact/statuses/d56800327f4a8a1859f2c41bb332f1fdc643ec45","head":{"label":"Tecnativa:9.0-partner_default_sale_discount","ref":"9.0-partner_default_sale_discount","sha":"d56800327f4a8a1859f2c41bb332f1fdc643ec45","user":{"login":"Tecnativa","id":18120193,"avatar_url":"https://avatars.githubusercontent.com/u/18120193?v=3","gravatar_id":"","url":"https://api.github.com/users/Tecnativa","html_url":"https://github.com/Tecnativa","followers_url":"https://api.github.com/users/Tecnativa/followers","following_url":"https://api.github.com/users/Tecnativa/following{/other_user}","gists_url":"https://api.github.com/users/Tecnativa/gists{/gist_id}","starred_url":"https://api.github.com/users/Tecnativa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tecnativa/subscriptions","organizations_url":"https://api.github.com/users/Tecnativa/orgs","repos_url":"https://api.github.com/users/Tecnativa/repos","events_url":"https://api.github.com/users/Tecnativa/events{/privacy}","received_events_url":"https://api.github.com/users/Tecnativa/received_events","type":"Organization","site_admin":false},"repo":{"id":62309164,"name":"partner-contact","full_name":"Tecnativa/partner-contact","owner":{"login":"Tecnativa","id":18120193,"avatar_url":"https://avatars.githubusercontent.com/u/18120193?v=3","gravatar_id":"","url":"https://api.github.com/users/Tecnativa","html_url":"https://github.com/Tecnativa","followers_url":"https://api.github.com/users/Tecnativa/followers","following_url":"https://api.github.com/users/Tecnativa/following{/other_user}","gists_url":"https://api.github.com/users/Tecnativa/gists{/gist_id}","starred_url":"https://api.github.com/users/Tecnativa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tecnativa/subscriptions","organizations_url":"https://api.github.com/users/Tecnativa/orgs","repos_url":"https://api.github.com/users/Tecnativa/repos","events_url":"https://api.github.com/users/Tecnativa/events{/privacy}","received_events_url":"https://api.github.com/users/Tecnativa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Tecnativa/partner-contact","description":"Odoo Partner and Contact related addons","fork":true,"url":"https://api.github.com/repos/Tecnativa/partner-contact","forks_url":"https://api.github.com/repos/Tecnativa/partner-contact/forks","keys_url":"https://api.github.com/repos/Tecnativa/partner-contact/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tecnativa/partner-contact/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tecnativa/partner-contact/teams","hooks_url":"https://api.github.com/repos/Tecnativa/partner-contact/hooks","issue_events_url":"https://api.github.com/repos/Tecnativa/partner-contact/issues/events{/number}","events_url":"https://api.github.com/repos/Tecnativa/partner-contact/events","assignees_url":"https://api.github.com/repos/Tecnativa/partner-contact/assignees{/user}","branches_url":"https://api.github.com/repos/Tecnativa/partner-contact/branches{/branch}","tags_url":"https://api.github.com/repos/Tecnativa/partner-contact/tags","blobs_url":"https://api.github.com/repos/Tecnativa/partner-contact/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tecnativa/partner-contact/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tecnativa/partner-contact/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tecnativa/partner-contact/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tecnativa/partner-contact/statuses/{sha}","languages_url":"https://api.github.com/repos/Tecnativa/partner-contact/languages","stargazers_url":"https://api.github.com/repos/Tecnativa/partner-contact/stargazers","contributors_url":"https://api.github.com/repos/Tecnativa/partner-contact/contributors","subscribers_url":"https://api.github.com/repos/Tecnativa/partner-contact/subscribers","subscription_url":"https://api.github.com/repos/Tecnativa/partner-contact/subscription","commits_url":"https://api.github.com/repos/Tecnativa/partner-contact/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tecnativa/partner-contact/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tecnativa/partner-contact/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tecnativa/partner-contact/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tecnativa/partner-contact/contents/{+path}","compare_url":"https://api.github.com/repos/Tecnativa/partner-contact/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tecnativa/partner-contact/merges","archive_url":"https://api.github.com/repos/Tecnativa/partner-contact/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tecnativa/partner-contact/downloads","issues_url":"https://api.github.com/repos/Tecnativa/partner-contact/issues{/number}","pulls_url":"https://api.github.com/repos/Tecnativa/partner-contact/pulls{/number}","milestones_url":"https://api.github.com/repos/Tecnativa/partner-contact/milestones{/number}","notifications_url":"https://api.github.com/repos/Tecnativa/partner-contact/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tecnativa/partner-contact/labels{/name}","releases_url":"https://api.github.com/repos/Tecnativa/partner-contact/releases{/id}","deployments_url":"https://api.github.com/repos/Tecnativa/partner-contact/deployments","created_at":"2016-06-30T12:33:35Z","updated_at":"2016-06-30T12:33:37Z","pushed_at":"2016-11-01T16:14:08Z","git_url":"git://github.com/Tecnativa/partner-contact.git","ssh_url":"git@github.com:Tecnativa/partner-contact.git","clone_url":"https://github.com/Tecnativa/partner-contact.git","svn_url":"https://github.com/Tecnativa/partner-contact","homepage":"","size":2986,"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":"9.0"}},"base":{"label":"OCA:9.0","ref":"9.0","sha":"15c42ffba37846e2b50f86774f019648264aa56f","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":20922147,"name":"partner-contact","full_name":"OCA/partner-contact","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/partner-contact","description":"Odoo Partner and Contact related addons","fork":false,"url":"https://api.github.com/repos/OCA/partner-contact","forks_url":"https://api.github.com/repos/OCA/partner-contact/forks","keys_url":"https://api.github.com/repos/OCA/partner-contact/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/partner-contact/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/partner-contact/teams","hooks_url":"https://api.github.com/repos/OCA/partner-contact/hooks","issue_events_url":"https://api.github.com/repos/OCA/partner-contact/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/partner-contact/events","assignees_url":"https://api.github.com/repos/OCA/partner-contact/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/partner-contact/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/partner-contact/tags","blobs_url":"https://api.github.com/repos/OCA/partner-contact/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/partner-contact/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/partner-contact/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/partner-contact/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/partner-contact/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/partner-contact/languages","stargazers_url":"https://api.github.com/repos/OCA/partner-contact/stargazers","contributors_url":"https://api.github.com/repos/OCA/partner-contact/contributors","subscribers_url":"https://api.github.com/repos/OCA/partner-contact/subscribers","subscription_url":"https://api.github.com/repos/OCA/partner-contact/subscription","commits_url":"https://api.github.com/repos/OCA/partner-contact/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/partner-contact/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/partner-contact/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/partner-contact/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/partner-contact/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/partner-contact/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/partner-contact/merges","archive_url":"https://api.github.com/repos/OCA/partner-contact/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/partner-contact/downloads","issues_url":"https://api.github.com/repos/OCA/partner-contact/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/partner-contact/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/partner-contact/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/partner-contact/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/partner-contact/labels{/name}","releases_url":"https://api.github.com/repos/OCA/partner-contact/releases{/id}","deployments_url":"https://api.github.com/repos/OCA/partner-contact/deployments","created_at":"2014-06-17T12:19:26Z","updated_at":"2016-10-24T11:02:10Z","pushed_at":"2016-11-03T03:33:51Z","git_url":"git://github.com/OCA/partner-contact.git","ssh_url":"git@github.com:OCA/partner-contact.git","clone_url":"https://github.com/OCA/partner-contact.git","svn_url":"https://github.com/OCA/partner-contact","homepage":"","size":5801,"stargazers_count":42,"watchers_count":42,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":180,"mirror_url":null,"open_issues_count":56,"forks":180,"open_issues":56,"watchers":42,"default_branch":"10.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/322"},"html":{"href":"https://github.com/OCA/partner-contact/pull/322"},"issue":{"href":"https://api.github.com/repos/OCA/partner-contact/issues/322"},"comments":{"href":"https://api.github.com/repos/OCA/partner-contact/issues/322/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/322/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/partner-contact/pulls/322/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/partner-contact/statuses/d56800327f4a8a1859f2c41bb332f1fdc643ec45"}}}}
{"actor":{"display_login":"pedrobaeza"}}