diff --git a/document_quick_access/README.rst b/document_quick_access/README.rst new file mode 100644 index 0000000..38eec31 --- /dev/null +++ b/document_quick_access/README.rst @@ -0,0 +1,95 @@ +===================== +Document Quick Access +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/11.0/document_quick_access + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-11-0/server-ux-11-0-document_quick_access + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/250/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to search any kind of records through a launcher. +With this, we can add a QR in our reports in order to search elements faster. +It could be used to add this QR (on a label) on external documents. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +# Access on developer mode +# Access `Settings > Technical > Document Quick Access` +# Create a record selecting the model, format and priority + +Usage +===== + +# Click on the QR button upper right in the navbar or access to it with `Alt + Shift + Q` +# A Pop up will be opened. You can scan a QR / barcode +# If the QR / barcode is found, you will be redirected to the record view + +Known issues / Roadmap +====================== + +* It would be interesting to be able to read the QR without clicking the button. + Maybe using a shortcut or directly accessing it. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/document_quick_access/__init__.py b/document_quick_access/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/document_quick_access/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/document_quick_access/__manifest__.py b/document_quick_access/__manifest__.py new file mode 100644 index 0000000..781cf7f --- /dev/null +++ b/document_quick_access/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Document Quick Access', + 'summary': """ + Document quick access""", + 'version': '11.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Creu Blanca,Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/server-ux', + 'depends': [ + 'web', + 'barcode_action', + ], + 'data': [ + 'security/ir.model.access.csv', + 'views/document_quick_access_rule.xml', + 'views/assets_backend.xml', + ], + 'qweb': [ + 'static/src/xml/document_quick_access_launcher.xml' + ], +} diff --git a/document_quick_access/models/__init__.py b/document_quick_access/models/__init__.py new file mode 100644 index 0000000..41ee638 --- /dev/null +++ b/document_quick_access/models/__init__.py @@ -0,0 +1,2 @@ +from . import document_quick_access_rule +from . import base diff --git a/document_quick_access/models/base.py b/document_quick_access/models/base.py new file mode 100644 index 0000000..9ad3702 --- /dev/null +++ b/document_quick_access/models/base.py @@ -0,0 +1,18 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class Base(models.AbstractModel): + _inherit = 'base' + + @api.multi + def get_quick_access_code(self): + self.ensure_one() + rule = self.env['document.quick.access.rule'].search([ + ('model_id.model', '=', self._name) + ], limit=1) + if not rule: + return False + return rule.get_code(self) diff --git a/document_quick_access/models/document_quick_access_rule.py b/document_quick_access/models/document_quick_access_rule.py new file mode 100644 index 0000000..6ba50d2 --- /dev/null +++ b/document_quick_access/models/document_quick_access_rule.py @@ -0,0 +1,100 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 +import json +import binascii +from odoo import api, fields, models, _ +from odoo.exceptions import UserError +import re + + +class DocumentQuickAccessRule(models.Model): + _name = 'document.quick.access.rule' + _description = 'Document Quick Access Rule' + _order = 'priority,model_id' + + name = fields.Char(required=True) + priority = fields.Integer(default=16, required=True) + barcode_format = fields.Selection([ + ('standard', 'Standard'), + ('b64_standard', 'Base64'), + ], required=True, default='standard') + # All formats must have a function to determine the code from a record and + # get the record from the code + model_id = fields.Many2one( + 'ir.model', + required=True, + ) + active = fields.Boolean( + default=True, + ) + + def get_code(self, record): + self.ensure_one() + return getattr(self, '_get_code_%s' % self.barcode_format)(record) + + def _get_code_b64_standard(self, record): + return base64.b64encode( + self._get_code_standard(record).encode('utf-8')).decode('utf-8') + + def _get_code_standard(self, record): + return '%s,%s' % (record._name, record.id) + + def _check_code_b64_standard(self, code): + try: + aux_code = base64.b64decode(code.encode('utf-8'), validate=True) + except binascii.Error: + return False + return self._check_code_standard(aux_code.decode('utf-8')) + + def _check_code_standard(self, code): + return re.match("^[a-zA-Z0-9\\.]*,[0-9]*$", code) + + def _read_code_b64_standard(self, code): + aux_code = base64.b64decode(code.encode('utf-8')).decode('utf-8') + return self._read_code_standard(aux_code) + + def _read_code_standard(self, code): + params = code.split(',') + return self.env[params[0]].browse(int(params[1])).exists() + + def read_code_action(self, code): + try: + record = self.read_code(code) + except UserError: + return { + 'type': 'ir.actions.act_window', + 'name': 'Search QR', + 'res_model': 'barcode.action', + 'views': [[False, 'form']], + 'target': 'new', + 'context': json.dumps({ + 'default_model': 'document.quick.access.rule', + 'default_method': 'read_code_action', + 'default_state': 'warning', + 'default_status': _('Document cannot be found') + }) + } + record.check_access_rights('read') + result = { + "type": "ir.actions.act_window", + "res_model": record._name, + "views": [[record.get_formview_id(), "form"]], + "res_id": record.id, + "target": "main", + } + return result + + @api.model + def read_code(self, code): + formats = self._fields['barcode_format'].selection + for barcode_format, format_name in formats: + if getattr(self, '_check_code_%s' % barcode_format)(code): + record = getattr(self, '_read_code_%s' % barcode_format)(code) + if record and self.search([ + ('model_id.model', '=', record._name), + ('barcode_format', '=', barcode_format) + ]): + return record + raise UserError(_('No format has been found for this record')) diff --git a/document_quick_access/readme/CONFIGURE.rst b/document_quick_access/readme/CONFIGURE.rst new file mode 100644 index 0000000..f5b30b4 --- /dev/null +++ b/document_quick_access/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +# Access on developer mode +# Access `Settings > Technical > Document Quick Access` +# Create a record selecting the model, format and priority diff --git a/document_quick_access/readme/CONTRIBUTORS.rst b/document_quick_access/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..93ec993 --- /dev/null +++ b/document_quick_access/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Enric Tobella diff --git a/document_quick_access/readme/DESCRIPTION.rst b/document_quick_access/readme/DESCRIPTION.rst new file mode 100644 index 0000000..c7e41ce --- /dev/null +++ b/document_quick_access/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module allows to search any kind of records through a launcher. +With this, we can add a QR in our reports in order to search elements faster. +It could be used to add this QR (on a label) on external documents. diff --git a/document_quick_access/readme/ROADMAP.rst b/document_quick_access/readme/ROADMAP.rst new file mode 100644 index 0000000..9325de0 --- /dev/null +++ b/document_quick_access/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* It would be interesting to be able to read the QR without clicking the button. + Maybe using a shortcut or directly accessing it. diff --git a/document_quick_access/readme/USAGE.rst b/document_quick_access/readme/USAGE.rst new file mode 100644 index 0000000..9b23b78 --- /dev/null +++ b/document_quick_access/readme/USAGE.rst @@ -0,0 +1,3 @@ +# Click on the QR button upper right in the navbar or access to it with `Alt + Shift + Q` +# A Pop up will be opened. You can scan a QR / barcode +# If the QR / barcode is found, you will be redirected to the record view diff --git a/document_quick_access/security/ir.model.access.csv b/document_quick_access/security/ir.model.access.csv new file mode 100644 index 0000000..d0d9f1d --- /dev/null +++ b/document_quick_access/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_document_quick_access_rule_user,document.quick.access.rule.user,model_document_quick_access_rule,base.group_user,1,0,0,0 +access_document_quick_access_rule_manager,document.quick.acess.rule.manager,model_document_quick_access_rule,base.group_erp_manager,1,1,1,1 diff --git a/document_quick_access/static/description/icon.png b/document_quick_access/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/document_quick_access/static/description/icon.png differ diff --git a/document_quick_access/static/description/index.html b/document_quick_access/static/description/index.html new file mode 100644 index 0000000..fa31e3c --- /dev/null +++ b/document_quick_access/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Document Quick Access + + + +
+

Document Quick Access

+ + +

Beta License: AGPL-3 OCA/server-ux Translate me on Weblate Try me on Runbot

+

This module allows to search any kind of records through a launcher. +With this, we can add a QR in our reports in order to search elements faster. +It could be used to add this QR (on a label) on external documents.

+

Table of contents

+ +
+

Configuration

+

# Access on developer mode +# Access Settings > Technical > Document Quick Access +# Create a record selecting the model, format and priority

+
+
+

Usage

+

# Click on the QR button upper right in the navbar or access to it with Alt + Shift + Q +# A Pop up will be opened. You can scan a QR / barcode +# If the QR / barcode is found, you will be redirected to the record view

+
+
+

Known issues / Roadmap

+
    +
  • It would be interesting to be able to read the QR without clicking the button. +Maybe using a shortcut or directly accessing it.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/document_quick_access/static/src/js/document_quick_access_launcher.js b/document_quick_access/static/src/js/document_quick_access_launcher.js new file mode 100644 index 0000000..2770e31 --- /dev/null +++ b/document_quick_access/static/src/js/document_quick_access_launcher.js @@ -0,0 +1,31 @@ +odoo.define('document_quick_access.document_quick_access_launcher', function (require) { + "use strict"; + + var SystrayMenu = require('web.SystrayMenu'); + var Widget = require('web.Widget'); + var LauncherMenu = Widget.extend({ + template:'document_quick_access_launcher.view.Menu', + events: { + "click": "on_click_find_document", + }, + + on_click_find_document: function () { + var context = {}; + context.default_model = 'document.quick.access.rule'; + context.default_method ='read_code_action'; + return this.do_action({ + type: 'ir.actions.act_window', + name: 'Search QR', + res_model: 'barcode.action', + views: [[false, 'form']], + target: 'new', + context:context, + }); + }, + }); + + SystrayMenu.Items.push(LauncherMenu); + return { + LauncherMenu: LauncherMenu, + }; +}); diff --git a/document_quick_access/static/src/xml/document_quick_access_launcher.xml b/document_quick_access/static/src/xml/document_quick_access_launcher.xml new file mode 100644 index 0000000..534bb02 --- /dev/null +++ b/document_quick_access/static/src/xml/document_quick_access_launcher.xml @@ -0,0 +1,12 @@ + + + + +
  • + +
  • +
    +
    diff --git a/document_quick_access/tests/__init__.py b/document_quick_access/tests/__init__.py new file mode 100644 index 0000000..85aedb4 --- /dev/null +++ b/document_quick_access/tests/__init__.py @@ -0,0 +1 @@ +from . import test_document_quick_access diff --git a/document_quick_access/tests/test_document_quick_access.py b/document_quick_access/tests/test_document_quick_access.py new file mode 100644 index 0000000..917d78d --- /dev/null +++ b/document_quick_access/tests/test_document_quick_access.py @@ -0,0 +1,54 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import common +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError + + +@common.at_install(False) +@common.post_install(True) +class TestDocumentQuickAccess(TransactionCase): + def setUp(self): + super().setUp() + self.model = 'res.partner' + self.model_id = self.env.ref('base.model_res_partner') + self.rule = self.env['document.quick.access.rule'].create({ + 'model_id': self.model_id.id, + 'name': 'PARTNER', + 'priority': 1, + 'barcode_format': 'standard', + }) + self.partner = self.env['res.partner'].create({ + 'name': 'Partner test', + }) + + def test_generation(self): + code = self.partner.get_quick_access_code() + self.assertTrue(code) + partner = self.env['document.quick.access.rule'].read_code(code) + self.assertEqual(partner, self.partner) + action = self.env['document.quick.access.rule'].read_code_action(code) + self.assertEqual(action['res_model'], partner._name) + self.assertEqual(action['res_id'], partner.id) + + def test_not_found(self): + code = self.partner.get_quick_access_code() + self.assertTrue(code) + self.rule.toggle_active() + with self.assertRaises(UserError): + self.env['document.quick.access.rule'].read_code(code) + action = self.env['document.quick.access.rule'].read_code_action(code) + self.assertEqual(action['res_model'], 'barcode.action') + + def test_no_code(self): + self.rule.toggle_active() + self.assertFalse(self.partner.get_quick_access_code()) + + def test_generation_b64(self): + self.rule.barcode_format = 'b64_standard' + self.test_generation() + + def test_not_found_b64(self): + self.rule.barcode_format = 'b64_standard' + self.test_not_found() diff --git a/document_quick_access/views/assets_backend.xml b/document_quick_access/views/assets_backend.xml new file mode 100644 index 0000000..de7e4f9 --- /dev/null +++ b/document_quick_access/views/assets_backend.xml @@ -0,0 +1,10 @@ + + +