diff --git a/barcode_action/README.rst b/barcode_action/README.rst new file mode 100644 index 0000000..21cd785 --- /dev/null +++ b/barcode_action/README.rst @@ -0,0 +1,21 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. diff --git a/barcode_action/__init__.py b/barcode_action/__init__.py new file mode 100644 index 0000000..3efbf5f --- /dev/null +++ b/barcode_action/__init__.py @@ -0,0 +1,5 @@ +# 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). + +from . import wizard diff --git a/barcode_action/__manifest__.py b/barcode_action/__manifest__.py new file mode 100644 index 0000000..2de79ab --- /dev/null +++ b/barcode_action/__manifest__.py @@ -0,0 +1,22 @@ +# 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': '11.0.1.0.0', + 'category': 'Reporting', + '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', + ] +} diff --git a/barcode_action/readme/CONTRIBUTORS.rst b/barcode_action/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..02397ae --- /dev/null +++ b/barcode_action/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Enric Tobella + 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..c9c1f52 --- /dev/null +++ b/barcode_action/readme/USAGE.rst @@ -0,0 +1,38 @@ +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. For example + +Action example:: + + + +Python example:: + + @api.multi + def find_sale_order_by_barcode(self, barcode): + sale_order = self.search([('name', '=', barcode)]) + if not sale_order: + action = self.env.ref('sale_order_find') + result = action.read()[0] + context = safe_eval(result['context']) + context.update({ + 'default_state': 'warning', + 'default_status': _('Sale Order %s cannot be found') % barcode + }) + result['context'] = json.dumps(context) + return result + action = self.env.ref('sale.action_quotations') + result = action.read()[0] + res = self.env.ref('sale.view_order_form', False) + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = sale_order.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/src/js/action_barcode_form.js b/barcode_action/static/src/js/action_barcode_form.js new file mode 100644 index 0000000..dad2cea --- /dev/null +++ b/barcode_action/static/src/js/action_barcode_form.js @@ -0,0 +1,28 @@ +odoo.define('barcode_action.form', function (require) { +"use strict"; + +var FormController = require('web.FormController'); + +FormController.include({ + _barcodeHandleAction: function (barcode, activeBarcode) { + if (this.mode === 'readonly') { + this.do_warn(_t('Error : Document not editable'), + _t('To modify this document, please first start edition.')); + return new $.Deferred().reject(); + } + 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 !== undefined){ + 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..5e5bbdf --- /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/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 @@ + + +