{"action":"created","issue":{"url":"https://api.github.com/repos/OCA/server-ux/issues/21","repository_url":"https://api.github.com/repos/OCA/server-ux","labels_url":"https://api.github.com/repos/OCA/server-ux/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/OCA/server-ux/issues/21/comments","events_url":"https://api.github.com/repos/OCA/server-ux/issues/21/events","html_url":"https://github.com/OCA/server-ux/pull/21","id":338236050,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5MjE4NTU4","number":21,"title":"[ADD] barcode_action","user":{"login":"etobella","id":28590170,"node_id":"MDQ6VXNlcjI4NTkwMTcw","avatar_url":"https://avatars1.githubusercontent.com/u/28590170?v=4","gravatar_id":"","url":"https://api.github.com/users/etobella","html_url":"https://github.com/etobella","followers_url":"https://api.github.com/users/etobella/followers","following_url":"https://api.github.com/users/etobella/following{/other_user}","gists_url":"https://api.github.com/users/etobella/gists{/gist_id}","starred_url":"https://api.github.com/users/etobella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etobella/subscriptions","organizations_url":"https://api.github.com/users/etobella/orgs","repos_url":"https://api.github.com/users/etobella/repos","events_url":"https://api.github.com/users/etobella/events{/privacy}","received_events_url":"https://api.github.com/users/etobella/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-04T11:19:53Z","updated_at":"2018-07-04T12:51:25Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/OCA/server-ux/pulls/21","html_url":"https://github.com/OCA/server-ux/pull/21","diff_url":"https://github.com/OCA/server-ux/pull/21.diff","patch_url":"https://github.com/OCA/server-ux/pull/21.patch"},"body":"This module allows to use barcodes as launchers of actions.\r\n\r\nThe action will launch a function that uses the barcode in order to return an action.\r\n\r\nUsage\r\n=====\r\nActions must be configured with the following data in the context:\r\n* model: Model where we can find the method (required)\r\n* method: Method to execute (required)\r\n* res_id: Id as base (optional)\r\n\r\nThe method must return an action. Installing this module with demo data will\r\ninstall a demo application that allows the system administrator to find a\r\npartner by the external reference encoded in a barcode.\r\n\r\nGo to *Settings / Find partners* and scan a barcode that contains the\r\ninternal reference of an existing partner. As soon as you read the barcode\r\nthe system will redirect you to that partner's form view.\r\n\r\nTechnical implementation of this example:\r\n\r\nAction::\r\n\r\n        <act_window id=\"res_partner_find\"\r\n            name=\"Find Partner\"\r\n            res_model=\"barcode.action\"\r\n            view_mode=\"form\"\r\n            view_type=\"form\"\r\n            context=\"{'default_model': 'res.partner', 'default_method': 'find_res_partner_by_ref_using_barcode'}\"\r\n            target=\"new\"/>\r\n\r\n        <menuitem id=\"menu_orders_customers\" name=\"Find partners\"\r\n            action=\"res_partner_find\"\r\n            parent=\"base.menu_administration\"/>\r\n\r\nPython code::\r\n\r\n    import json\r\n    from odoo import api, models, _\r\n    from odoo.tools.safe_eval import safe_eval\r\n\r\n\r\n    class ResPartner(models.Model):\r\n        _inherit = 'res.partner'\r\n\r\n        @api.multi\r\n        def find_res_partner_by_ref_using_barcode(self, barcode):\r\n            partner = self.search([('ref', '=', barcode)], limit=1)\r\n            if not partner:\r\n                action = self.env.ref('res_partner_find')\r\n                result = action.read()[0]\r\n                context = safe_eval(result['context'])\r\n                context.update({\r\n                    'default_state': 'warning',\r\n                    'default_status': _('Partner with Internal Reference '\r\n                                        '%s cannot be found') % barcode\r\n                })\r\n                result['context'] = json.dumps(context)\r\n                return result\r\n            action = self.env.ref('base.action_partner_form')\r\n            result = action.read()[0]\r\n            res = self.env.ref('base.view_partner_form', False)\r\n            result['views'] = [(res and res.id or False, 'form')]\r\n            result['res_id'] = partner.id\r\n            return result\r\n"},"comment":{"url":"https://api.github.com/repos/OCA/server-ux/issues/comments/402470018","html_url":"https://github.com/OCA/server-ux/pull/21#issuecomment-402470018","issue_url":"https://api.github.com/repos/OCA/server-ux/issues/21","id":402470018,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjQ3MDAxOA==","user":{"login":"hbrunn","id":2563186,"node_id":"MDQ6VXNlcjI1NjMxODY=","avatar_url":"https://avatars2.githubusercontent.com/u/2563186?v=4","gravatar_id":"","url":"https://api.github.com/users/hbrunn","html_url":"https://github.com/hbrunn","followers_url":"https://api.github.com/users/hbrunn/followers","following_url":"https://api.github.com/users/hbrunn/following{/other_user}","gists_url":"https://api.github.com/users/hbrunn/gists{/gist_id}","starred_url":"https://api.github.com/users/hbrunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hbrunn/subscriptions","organizations_url":"https://api.github.com/users/hbrunn/orgs","repos_url":"https://api.github.com/users/hbrunn/repos","events_url":"https://api.github.com/users/hbrunn/events{/privacy}","received_events_url":"https://api.github.com/users/hbrunn/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T12:51:25Z","updated_at":"2018-07-04T12:51:25Z","author_association":"MEMBER","body":"looks nice indeed. Tests are missing though."}}
{"actor":{"display_login":"hbrunn"}}