{"action":"created","comment":{"url":"https://api.github.com/repos/OCA/maintenance/pulls/comments/122848230","pull_request_review_id":44998885,"id":122848230,"diff_hunk":"@@ -0,0 +1,68 @@\n+# -*- coding: utf-8 -*-\n+# Copyright 2017 Tecnativa - Pedro M. Baeza\n+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).\n+\n+from odoo import api, fields, models\n+import math\n+\n+\n+class AccountInvoice(models.Model):\n+    _inherit = 'account.invoice'\n+\n+    equipment_ids = fields.Many2many(\n+        comodel_name=\"maintenance.equipment\", compute=\"_compute_equipment_ids\",\n+        string=\"Equipments\",\n+    )\n+\n+    @api.multi\n+    @api.depends('invoice_line_ids', 'invoice_line_ids.equipment_ids')\n+    def _compute_equipment_ids(self):\n+        for invoice in self:\n+            invoice.equipment_ids = [\n+                (6, 0, invoice.mapped('invoice_line_ids.equipment_ids').ids),\n+            ]\n+\n+    @api.multi\n+    def action_invoice_cancel(self):\n+        res = super(AccountInvoice, self).action_invoice_cancel()\n+        self.mapped('equipment_ids').unlink()\n+        return res\n+\n+\n+class AccountInvoiceLine(models.Model):\n+    _inherit = 'account.invoice.line'\n+\n+    equipment_ids = fields.One2many(\n+        comodel_name=\"maintenance.equipment\", inverse_name=\"invoice_line_id\",\n+        string=\"Equipments\",\n+    )\n+\n+    def _prepare_equipment_vals_list(self, invoice_line):\n+        vals_list = []\n+        num = int(math.ceil(invoice_line.quantity))\n+        for i in range(num):\n+            vals_list.append({\n+                'name': \"{} [{}/{}]\".format(invoice_line.name, i + 1, num),\n+                'category_id': (\n+                    invoice_line.asset_category_id.equipment_category_id.id\n+                ),\n+                'invoice_line_id': invoice_line.id,\n+                'cost': invoice_line.price_subtotal / invoice_line.quantity,\n+                'partner_id': invoice_line.invoice_id.partner_id.id,\n+            })\n+        return vals_list\n+\n+    @api.multi\n+    def asset_create(self):\n+        for line in self.filtered('asset_category_id.equipment_category_id'):\n+            # Create equipments\n+            equipments = self.env['maintenance.equipment']\n+            for vals in self._prepare_equipment_vals_list(line):\n+                equipments += equipments.create(vals)","path":"account_asset_maintenance/models/account_invoice.py","position":61,"original_position":61,"commit_id":"aac05d747a93ddbb3212155653eb9971df3fb56e","original_commit_id":"aac05d747a93ddbb3212155653eb9971df3fb56e","user":{"login":"rigo1985","id":10016548,"avatar_url":"https://avatars0.githubusercontent.com/u/10016548?v=3","gravatar_id":"","url":"https://api.github.com/users/rigo1985","html_url":"https://github.com/rigo1985","followers_url":"https://api.github.com/users/rigo1985/followers","following_url":"https://api.github.com/users/rigo1985/following{/other_user}","gists_url":"https://api.github.com/users/rigo1985/gists{/gist_id}","starred_url":"https://api.github.com/users/rigo1985/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rigo1985/subscriptions","organizations_url":"https://api.github.com/users/rigo1985/orgs","repos_url":"https://api.github.com/users/rigo1985/repos","events_url":"https://api.github.com/users/rigo1985/events{/privacy}","received_events_url":"https://api.github.com/users/rigo1985/received_events","type":"User","site_admin":false},"body":"Hi Pedro I consider that part (if not all) the points that are raised is resolved with the inheritance by the delegation of the Asset in the Equipment.","created_at":"2017-06-19T23:20:51Z","updated_at":"2017-06-19T23:20:51Z","html_url":"https://github.com/OCA/maintenance/pull/1#discussion_r122848230","pull_request_url":"https://api.github.com/repos/OCA/maintenance/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/comments/122848230"},"html":{"href":"https://github.com/OCA/maintenance/pull/1#discussion_r122848230"},"pull_request":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/OCA/maintenance/pulls/1","id":124162125,"html_url":"https://github.com/OCA/maintenance/pull/1","diff_url":"https://github.com/OCA/maintenance/pull/1.diff","patch_url":"https://github.com/OCA/maintenance/pull/1.patch","issue_url":"https://api.github.com/repos/OCA/maintenance/issues/1","number":1,"state":"open","locked":false,"title":"[ADD] account_asset_maintenance","user":{"login":"pedrobaeza","id":7165771,"avatar_url":"https://avatars1.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":"Link between assets and equipments\r\n==================================\r\n\r\nThis module links assets with equipments, allowing to create automatically\r\nan equipment from the supplier invoice if an equipment category is assigned\r\nin the asset category.\r\n\r\nConfiguration\r\n=============\r\n\r\nTo configure this module, you need to:\r\n\r\n* Go to *Accounting > Configuration > Management > Asset Types*.\r\n* Select one asset type.\r\n* Fill the field \"Equipment category\" with the equipment category we want to\r\n  assign to the auto-created equipments.\r\n\r\nUsage\r\n=====\r\n\r\nTo use this module, you need to:\r\n\r\n* Go to *Accounting > Purchases > Vendor Bills*.\r\n* Create a new bill.\r\n* Create one invoice line.\r\n* Select an asset category with an equipment category filled.\r\n* Validate the invoice.\r\n* A new page called \"Equipments\" will appear with the auto-created equipments.\r\n* An equipment will created per each quantity indicated in the invoice line.\r\n* If the quantity is not integer (for example: 3.5), the upper integer number\r\n  will be used (4 for the example).\r\n* If you cancel the bill, the created equipments will be removed.\r\n\r\nYou can access equipments for the created asset:\r\n\r\n* Go to *Accounting > Adviser > Assets*.\r\n* Open the created asset\r\n* You will see an smart-button with the string \"Equipments\" that links to the\r\n  created asset.","created_at":"2017-06-06T10:53:47Z","updated_at":"2017-06-19T23:20:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"628f72fb3fde932f25d017aaa306c7e03529fb70","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/OCA/maintenance/pulls/1/commits","review_comments_url":"https://api.github.com/repos/OCA/maintenance/pulls/1/comments","review_comment_url":"https://api.github.com/repos/OCA/maintenance/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OCA/maintenance/issues/1/comments","statuses_url":"https://api.github.com/repos/OCA/maintenance/statuses/aac05d747a93ddbb3212155653eb9971df3fb56e","head":{"label":"Tecnativa:10.0-account_asset_maintenance","ref":"10.0-account_asset_maintenance","sha":"aac05d747a93ddbb3212155653eb9971df3fb56e","user":{"login":"Tecnativa","id":18120193,"avatar_url":"https://avatars1.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":93508033,"name":"maintenance","full_name":"Tecnativa/maintenance","owner":{"login":"Tecnativa","id":18120193,"avatar_url":"https://avatars1.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/maintenance","description":"Odoo modules for businesses that implies maintenance tasks","fork":true,"url":"https://api.github.com/repos/Tecnativa/maintenance","forks_url":"https://api.github.com/repos/Tecnativa/maintenance/forks","keys_url":"https://api.github.com/repos/Tecnativa/maintenance/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tecnativa/maintenance/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tecnativa/maintenance/teams","hooks_url":"https://api.github.com/repos/Tecnativa/maintenance/hooks","issue_events_url":"https://api.github.com/repos/Tecnativa/maintenance/issues/events{/number}","events_url":"https://api.github.com/repos/Tecnativa/maintenance/events","assignees_url":"https://api.github.com/repos/Tecnativa/maintenance/assignees{/user}","branches_url":"https://api.github.com/repos/Tecnativa/maintenance/branches{/branch}","tags_url":"https://api.github.com/repos/Tecnativa/maintenance/tags","blobs_url":"https://api.github.com/repos/Tecnativa/maintenance/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tecnativa/maintenance/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tecnativa/maintenance/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tecnativa/maintenance/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tecnativa/maintenance/statuses/{sha}","languages_url":"https://api.github.com/repos/Tecnativa/maintenance/languages","stargazers_url":"https://api.github.com/repos/Tecnativa/maintenance/stargazers","contributors_url":"https://api.github.com/repos/Tecnativa/maintenance/contributors","subscribers_url":"https://api.github.com/repos/Tecnativa/maintenance/subscribers","subscription_url":"https://api.github.com/repos/Tecnativa/maintenance/subscription","commits_url":"https://api.github.com/repos/Tecnativa/maintenance/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tecnativa/maintenance/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tecnativa/maintenance/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tecnativa/maintenance/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tecnativa/maintenance/contents/{+path}","compare_url":"https://api.github.com/repos/Tecnativa/maintenance/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tecnativa/maintenance/merges","archive_url":"https://api.github.com/repos/Tecnativa/maintenance/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tecnativa/maintenance/downloads","issues_url":"https://api.github.com/repos/Tecnativa/maintenance/issues{/number}","pulls_url":"https://api.github.com/repos/Tecnativa/maintenance/pulls{/number}","milestones_url":"https://api.github.com/repos/Tecnativa/maintenance/milestones{/number}","notifications_url":"https://api.github.com/repos/Tecnativa/maintenance/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tecnativa/maintenance/labels{/name}","releases_url":"https://api.github.com/repos/Tecnativa/maintenance/releases{/id}","deployments_url":"https://api.github.com/repos/Tecnativa/maintenance/deployments","created_at":"2017-06-06T10:53:15Z","updated_at":"2017-06-06T10:11:53Z","pushed_at":"2017-06-06T10:53:36Z","git_url":"git://github.com/Tecnativa/maintenance.git","ssh_url":"git@github.com:Tecnativa/maintenance.git","clone_url":"https://github.com/Tecnativa/maintenance.git","svn_url":"https://github.com/Tecnativa/maintenance","homepage":null,"size":21,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"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":"10.0"}},"base":{"label":"OCA:10.0","ref":"10.0","sha":"2876d28d70ed8ad055d1bde3d6136cf01f469ea8","user":{"login":"OCA","id":7600578,"avatar_url":"https://avatars2.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":93504769,"name":"maintenance","full_name":"OCA/maintenance","owner":{"login":"OCA","id":7600578,"avatar_url":"https://avatars2.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/maintenance","description":"Odoo modules for businesses that implies maintenance tasks","fork":false,"url":"https://api.github.com/repos/OCA/maintenance","forks_url":"https://api.github.com/repos/OCA/maintenance/forks","keys_url":"https://api.github.com/repos/OCA/maintenance/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OCA/maintenance/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OCA/maintenance/teams","hooks_url":"https://api.github.com/repos/OCA/maintenance/hooks","issue_events_url":"https://api.github.com/repos/OCA/maintenance/issues/events{/number}","events_url":"https://api.github.com/repos/OCA/maintenance/events","assignees_url":"https://api.github.com/repos/OCA/maintenance/assignees{/user}","branches_url":"https://api.github.com/repos/OCA/maintenance/branches{/branch}","tags_url":"https://api.github.com/repos/OCA/maintenance/tags","blobs_url":"https://api.github.com/repos/OCA/maintenance/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OCA/maintenance/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OCA/maintenance/git/refs{/sha}","trees_url":"https://api.github.com/repos/OCA/maintenance/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OCA/maintenance/statuses/{sha}","languages_url":"https://api.github.com/repos/OCA/maintenance/languages","stargazers_url":"https://api.github.com/repos/OCA/maintenance/stargazers","contributors_url":"https://api.github.com/repos/OCA/maintenance/contributors","subscribers_url":"https://api.github.com/repos/OCA/maintenance/subscribers","subscription_url":"https://api.github.com/repos/OCA/maintenance/subscription","commits_url":"https://api.github.com/repos/OCA/maintenance/commits{/sha}","git_commits_url":"https://api.github.com/repos/OCA/maintenance/git/commits{/sha}","comments_url":"https://api.github.com/repos/OCA/maintenance/comments{/number}","issue_comment_url":"https://api.github.com/repos/OCA/maintenance/issues/comments{/number}","contents_url":"https://api.github.com/repos/OCA/maintenance/contents/{+path}","compare_url":"https://api.github.com/repos/OCA/maintenance/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OCA/maintenance/merges","archive_url":"https://api.github.com/repos/OCA/maintenance/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OCA/maintenance/downloads","issues_url":"https://api.github.com/repos/OCA/maintenance/issues{/number}","pulls_url":"https://api.github.com/repos/OCA/maintenance/pulls{/number}","milestones_url":"https://api.github.com/repos/OCA/maintenance/milestones{/number}","notifications_url":"https://api.github.com/repos/OCA/maintenance/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OCA/maintenance/labels{/name}","releases_url":"https://api.github.com/repos/OCA/maintenance/releases{/id}","deployments_url":"https://api.github.com/repos/OCA/maintenance/deployments","created_at":"2017-06-06T10:11:53Z","updated_at":"2017-06-09T08:39:41Z","pushed_at":"2017-06-19T11:41:00Z","git_url":"git://github.com/OCA/maintenance.git","ssh_url":"git@github.com:OCA/maintenance.git","clone_url":"https://github.com/OCA/maintenance.git","svn_url":"https://github.com/OCA/maintenance","homepage":null,"size":14,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":1,"default_branch":"10.0"}},"_links":{"self":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/1"},"html":{"href":"https://github.com/OCA/maintenance/pull/1"},"issue":{"href":"https://api.github.com/repos/OCA/maintenance/issues/1"},"comments":{"href":"https://api.github.com/repos/OCA/maintenance/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OCA/maintenance/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/OCA/maintenance/statuses/aac05d747a93ddbb3212155653eb9971df3fb56e"}}}}
{"actor":{"display_login":"rigo1985"}}