diff --git a/barcode_action/README.rst b/barcode_action/README.rst new file mode 100644 index 0000000..33c459e --- /dev/null +++ b/barcode_action/README.rst @@ -0,0 +1,141 @@ +======================= +Barcode action launcher +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.0/barcode_action + :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-12-0/server-ux-12-0-barcode_action + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to use barcodes as launchers of actions. + +The action will launch a function that uses the barcode in order to return an action. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Actions must be configured with the following data in the context: +* model: Model where we can find the method (required) +* method: Method to execute (required) +* res_id: Id as base (optional) + +The method must return an action. Installing this module with demo data will +install a demo application that allows the system administrator to find a +partner by the external reference encoded in a barcode. + +Go to *Settings / Find partners* and scan a barcode that contains the +internal reference of an existing partner. As soon as you read the barcode +the system will redirect you to that partner's form view. + +Technical implementation of this example: + +Action:: + + + + + +Python code:: + + import json + from odoo import api, models, _ + from odoo.tools.safe_eval import safe_eval + + + class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.multi + def find_res_partner_by_ref_using_barcode(self, barcode): + partner = self.search([('ref', '=', barcode)], limit=1) + if not partner: + action = self.env.ref('res_partner_find') + result = action.read()[0] + context = safe_eval(result['context']) + context.update({ + 'default_state': 'warning', + 'default_status': _('Partner with Internal Reference ' + '%s cannot be found') % barcode + }) + result['context'] = json.dumps(context) + return result + action = self.env.ref('base.action_partner_form') + result = action.read()[0] + res = self.env.ref('base.view_partner_form', False) + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = partner.id + return result + +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 +* Eficent + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella +* Jordi Ballester + + +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/barcode_action/__init__.py b/barcode_action/__init__.py new file mode 100644 index 0000000..134df27 --- /dev/null +++ b/barcode_action/__init__.py @@ -0,0 +1,2 @@ +from . import wizard +from . import models diff --git a/barcode_action/__manifest__.py b/barcode_action/__manifest__.py new file mode 100644 index 0000000..6488ce6 --- /dev/null +++ b/barcode_action/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2017 Creu Blanca +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + 'name': 'Barcode action launcher', + 'version': '12.0.1.0.0', + 'category': 'Extra Tools', + 'website': 'https://github.com/OCA/server-ux', + 'author': 'Creu Blanca, Eficent, Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'installable': True, + 'application': False, + 'summary': 'Allows to use barcodes as a launcher', + 'depends': [ + 'barcodes', + ], + 'data': [ + 'views/barcode_templates.xml', + 'wizard/barcode_action_view.xml', + ], + 'demo': [ + 'demo/barcode_action_demo.xml' + ], +} diff --git a/barcode_action/demo/barcode_action_demo.xml b/barcode_action/demo/barcode_action_demo.xml new file mode 100644 index 0000000..c976611 --- /dev/null +++ b/barcode_action/demo/barcode_action_demo.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/barcode_action/i18n/barcode_action.pot b/barcode_action/i18n/barcode_action.pot new file mode 100644 index 0000000..d112657 --- /dev/null +++ b/barcode_action/i18n/barcode_action.pot @@ -0,0 +1,136 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * barcode_action +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: barcode_action +#: model:ir.actions.act_window,name:barcode_action.barcode_action_action +msgid "Barcode Launcher" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action___barcode_scanned +msgid "Barcode Scanned" +msgstr "" + +#. module: barcode_action +#: model_terms:ir.ui.view,arch_db:barcode_action.barcode_action_form +msgid "Close" +msgstr "" + +#. module: barcode_action +#: model:ir.model,name:barcode_action.model_res_partner +msgid "Contact" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__create_uid +msgid "Created by" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__create_date +msgid "Created on" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__display_name +msgid "Display Name" +msgstr "" + +#. module: barcode_action +#: model_terms:ir.ui.view,arch_db:barcode_action.barcode_action_form +msgid "Find" +msgstr "" + +#. module: barcode_action +#: model:ir.actions.act_window,name:barcode_action.res_partner_find +msgid "Find Partner" +msgstr "" + +#. module: barcode_action +#: model:ir.ui.menu,name:barcode_action.menu_orders_customers +msgid "Find partners" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__id +msgid "ID" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action____last_update +msgid "Last Modified on" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__write_date +msgid "Last Updated on" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__method +msgid "Method" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__model +msgid "Model" +msgstr "" + +#. module: barcode_action +#: code:addons/barcode_action/models/res_partner.py:21 +#, python-format +msgid "Partner with Internal Reference %s cannot be found" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__res_id +msgid "Res" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__state +msgid "State" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action__status +msgid "Status" +msgstr "" + +#. module: barcode_action +#: model:ir.model.fields,help:barcode_action.field_barcode_action___barcode_scanned +msgid "Value of the last barcode scanned." +msgstr "" + +#. module: barcode_action +#: selection:barcode.action,state:0 +msgid "Waiting" +msgstr "" + +#. module: barcode_action +#: selection:barcode.action,state:0 +msgid "Warning" +msgstr "" + +#. module: barcode_action +#: model:ir.model,name:barcode_action.model_barcode_action +msgid "barcode.action" +msgstr "" + diff --git a/barcode_action/i18n/es.po b/barcode_action/i18n/es.po new file mode 100644 index 0000000..4cca21b --- /dev/null +++ b/barcode_action/i18n/es.po @@ -0,0 +1,128 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * barcode_action +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2019-05-08 11:03+0000\n" +"Last-Translator: Enric Tobella \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.5.1\n" + +#. module: barcode_action +#: model:ir.actions.act_window,name:barcode_action.barcode_action_action +msgid "Barcode Launcher" +msgstr "Buscador por código de barras" + +#. module: barcode_action +#: model:ir.ui.view,arch_db:barcode_action.barcode_action_form +msgid "Close" +msgstr "Cerrar" + +#. module: barcode_action +#: model:ir.model,name:barcode_action.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_create_date +msgid "Created on" +msgstr "Creado en" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: barcode_action +#: model:ir.ui.view,arch_db:barcode_action.barcode_action_form +msgid "Find" +msgstr "Buscar" + +#. module: barcode_action +#: model:ir.actions.act_window,name:barcode_action.res_partner_find +msgid "Find Partner" +msgstr "Buscar Contacto" + +#. module: barcode_action +#: model:ir.ui.menu,name:barcode_action.menu_orders_customers +msgid "Find partners" +msgstr "Buscar contactos" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_id +msgid "ID" +msgstr "ID" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action___last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_write_uid +msgid "Last Updated by" +msgstr "Última actualización de" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_write_date +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_method +msgid "Method" +msgstr "Método" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_model +msgid "Model" +msgstr "Modelo" + +#. module: barcode_action +#: code:addons/barcode_action/models/res_partner.py:21 +#, python-format +msgid "Partner with Internal Reference %s cannot be found" +msgstr "No se ha encontrado el contacto con referencia %s" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_res_id +msgid "Res" +msgstr "Res" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_state +msgid "State" +msgstr "Estado" + +#. module: barcode_action +#: model:ir.model.fields,field_description:barcode_action.field_barcode_action_status +msgid "Status" +msgstr "Estado" + +#. module: barcode_action +#: selection:barcode.action,state:0 +msgid "Waiting" +msgstr "Esperando" + +#. module: barcode_action +#: selection:barcode.action,state:0 +msgid "Warning" +msgstr "Aviso" + +#. module: barcode_action +#: model:ir.model,name:barcode_action.model_barcode_action +msgid "barcode.action" +msgstr "barcode.action" diff --git a/barcode_action/models/__init__.py b/barcode_action/models/__init__.py new file mode 100644 index 0000000..91fed54 --- /dev/null +++ b/barcode_action/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/barcode_action/models/res_partner.py b/barcode_action/models/res_partner.py new file mode 100644 index 0000000..8a8a563 --- /dev/null +++ b/barcode_action/models/res_partner.py @@ -0,0 +1,31 @@ +# Copyright 2018 Creu Blanca +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +import json +from odoo import api, models, _ +from odoo.tools.safe_eval import safe_eval + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.multi + def find_res_partner_by_ref_using_barcode(self, barcode): + partner = self.search([('ref', '=', barcode)], limit=1) + if not partner: + action = self.env.ref('barcode_action.res_partner_find') + result = action.read()[0] + context = safe_eval(result['context']) + context.update({ + 'default_state': 'warning', + 'default_status': _('Partner with Internal Reference ' + '%s cannot be found') % barcode + }) + result['context'] = json.dumps(context) + return result + action = self.env.ref('base.action_partner_form') + result = action.read()[0] + res = self.env.ref('base.view_partner_form', False) + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = partner.id + return result diff --git a/barcode_action/readme/CONTRIBUTORS.rst b/barcode_action/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..6296b24 --- /dev/null +++ b/barcode_action/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Enric Tobella +* Jordi Ballester + diff --git a/barcode_action/readme/DESCRIPTION.rst b/barcode_action/readme/DESCRIPTION.rst new file mode 100644 index 0000000..40178e3 --- /dev/null +++ b/barcode_action/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module allows to use barcodes as launchers of actions. + +The action will launch a function that uses the barcode in order to return an action. diff --git a/barcode_action/readme/USAGE.rst b/barcode_action/readme/USAGE.rst new file mode 100644 index 0000000..d43eb9d --- /dev/null +++ b/barcode_action/readme/USAGE.rst @@ -0,0 +1,59 @@ +Actions must be configured with the following data in the context: +* model: Model where we can find the method (required) +* method: Method to execute (required) +* res_id: Id as base (optional) + +The method must return an action. Installing this module with demo data will +install a demo application that allows the system administrator to find a +partner by the external reference encoded in a barcode. + +Go to *Settings / Find partners* and scan a barcode that contains the +internal reference of an existing partner. As soon as you read the barcode +the system will redirect you to that partner's form view. + +Technical implementation of this example: + +Action:: + + + + + +Python code:: + + import json + from odoo import api, models, _ + from odoo.tools.safe_eval import safe_eval + + + class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.multi + def find_res_partner_by_ref_using_barcode(self, barcode): + partner = self.search([('ref', '=', barcode)], limit=1) + if not partner: + action = self.env.ref('res_partner_find') + result = action.read()[0] + context = safe_eval(result['context']) + context.update({ + 'default_state': 'warning', + 'default_status': _('Partner with Internal Reference ' + '%s cannot be found') % barcode + }) + result['context'] = json.dumps(context) + return result + action = self.env.ref('base.action_partner_form') + result = action.read()[0] + res = self.env.ref('base.view_partner_form', False) + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = partner.id + return result diff --git a/barcode_action/static/description/icon.png b/barcode_action/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/barcode_action/static/description/icon.png differ diff --git a/barcode_action/static/description/index.html b/barcode_action/static/description/index.html new file mode 100644 index 0000000..36addc9 --- /dev/null +++ b/barcode_action/static/description/index.html @@ -0,0 +1,482 @@ + + + + + + +Barcode action launcher + + + +
+

Barcode action launcher

+ + +

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

+

This module allows to use barcodes as launchers of actions.

+

The action will launch a function that uses the barcode in order to return an action.

+

Table of contents

+ +
+

Usage

+

Actions must be configured with the following data in the context: +* model: Model where we can find the method (required) +* method: Method to execute (required) +* res_id: Id as base (optional)

+

The method must return an action. Installing this module with demo data will +install a demo application that allows the system administrator to find a +partner by the external reference encoded in a barcode.

+

Go to Settings / Find partners and scan a barcode that contains the +internal reference of an existing partner. As soon as you read the barcode +the system will redirect you to that partner’s form view.

+

Technical implementation of this example:

+

Action:

+
+<act_window id="res_partner_find"
+    name="Find Partner"
+    res_model="barcode.action"
+    view_mode="form"
+    view_type="form"
+    context="{'default_model': 'res.partner', 'default_method': 'find_res_partner_by_ref_using_barcode'}"
+    target="new"/>
+
+<menuitem id="menu_orders_customers" name="Find partners"
+    action="res_partner_find"
+    parent="base.menu_administration"/>
+
+

Python code:

+
+import json
+from odoo import api, models, _
+from odoo.tools.safe_eval import safe_eval
+
+
+class ResPartner(models.Model):
+    _inherit = 'res.partner'
+
+    @api.multi
+    def find_res_partner_by_ref_using_barcode(self, barcode):
+        partner = self.search([('ref', '=', barcode)], limit=1)
+        if not partner:
+            action = self.env.ref('res_partner_find')
+            result = action.read()[0]
+            context = safe_eval(result['context'])
+            context.update({
+                'default_state': 'warning',
+                'default_status': _('Partner with Internal Reference '
+                                    '%s cannot be found') % barcode
+            })
+            result['context'] = json.dumps(context)
+            return result
+        action = self.env.ref('base.action_partner_form')
+        result = action.read()[0]
+        res = self.env.ref('base.view_partner_form', False)
+        result['views'] = [(res and res.id or False, 'form')]
+        result['res_id'] = partner.id
+        return result
+
+
+
+

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
  • +
  • Eficent
  • +
+
+
+

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/barcode_action/static/src/js/action_barcode_form.js b/barcode_action/static/src/js/action_barcode_form.js new file mode 100644 index 0000000..4eedc51 --- /dev/null +++ b/barcode_action/static/src/js/action_barcode_form.js @@ -0,0 +1,23 @@ +odoo.define('barcode_action.form', function (require) { + "use strict"; + + var FormController = require('web.FormController'); + + FormController.include({ + _barcodeHandleAction: function (barcode, activeBarcode) { + var record = this.model.get(this.handle); + var self = this; + return self._rpc({ + model: record.data.model, + method: record.data.method, + args: [[record.data.res_id], barcode], + }).done(function (action) { + if (action) { + self._barcodeStopListening(); + self.do_action(action); + } + }); + }, + }); + +}); diff --git a/barcode_action/static/src/js/action_barcode_widget.js b/barcode_action/static/src/js/action_barcode_widget.js new file mode 100644 index 0000000..ad875d9 --- /dev/null +++ b/barcode_action/static/src/js/action_barcode_widget.js @@ -0,0 +1,24 @@ +odoo.define('barcode_action.field', function (require) { + "use strict"; + + var AbstractField = require('web.AbstractField'); + var field_registry = require('web.field_registry'); + + var ActionBarcodeField = AbstractField.extend({ + init: function () { + this._super.apply(this, arguments); + this.trigger_up('activeBarcode', { + name: this.name, + commands: { + barcode: '_barcodeHandleAction', + }, + }); + }, + }); + field_registry.add('action_barcode_handler', ActionBarcodeField); + + return { + ActionBarcodeField:ActionBarcodeField, + }; + +}); diff --git a/barcode_action/tests/__init__.py b/barcode_action/tests/__init__.py new file mode 100644 index 0000000..1050b9e --- /dev/null +++ b/barcode_action/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_find diff --git a/barcode_action/tests/test_partner_find.py b/barcode_action/tests/test_partner_find.py new file mode 100644 index 0000000..ad57923 --- /dev/null +++ b/barcode_action/tests/test_partner_find.py @@ -0,0 +1,24 @@ +# Copyright 2018 Creu Blanca +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo.tests.common import TransactionCase + + +class TestPartnerFind(TransactionCase): + + def test_partner(self): + partner_obj = self.env['res.partner'] + ref = 'testing_partner_internal_reference' + partner = partner_obj.create({ + 'name': 'Testing partner', + 'ref': ref, + }) + # We should find the partner when the ref is found + self.assertEqual( + partner.id, + partner_obj.find_res_partner_by_ref_using_barcode(ref).get( + 'res_id', False)) + # No partner is found, then there is no res_id on the result + self.assertFalse( + partner_obj.find_res_partner_by_ref_using_barcode( + '%s-%s' % (ref, ref)).get('res_id', False)) diff --git a/barcode_action/views/barcode_templates.xml b/barcode_action/views/barcode_templates.xml new file mode 100644 index 0000000..52d3bcd --- /dev/null +++ b/barcode_action/views/barcode_templates.xml @@ -0,0 +1,12 @@ + + +