Browse Source

[ADD] barcodes_action

pull/21/head
Enric Tobella 6 years ago
parent
commit
d9012e7c96
No known key found for this signature in database GPG Key ID: 1A2546A1B7BA2451
  1. 21
      barcode_action/README.rst
  2. 5
      barcode_action/__init__.py
  3. 22
      barcode_action/__manifest__.py
  4. 2
      barcode_action/readme/CONTRIBUTORS.rst
  5. 3
      barcode_action/readme/DESCRIPTION.rst
  6. 38
      barcode_action/readme/USAGE.rst
  7. BIN
      barcode_action/static/description/icon.png
  8. 28
      barcode_action/static/src/js/action_barcode_form.js
  9. 24
      barcode_action/static/src/js/action_barcode_widget.js
  10. 12
      barcode_action/views/barcode_templates.xml
  11. 1
      barcode_action/wizard/__init__.py
  12. 22
      barcode_action/wizard/barcode_action.py
  13. 50
      barcode_action/wizard/barcode_action_view.xml

21
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.

5
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

22
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',
]
}

2
barcode_action/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Enric Tobella <etobella@creublanca.es>

3
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.

38
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::
<act_window id="sale_order_find"
name="Find Sale Order"
res_model="barcode.action"
view_mode="form"
view_type="form"
context="{'default_model': 'sale.order', 'default_method': 'find_sale_order_by_barcode'}"
target="new"/>
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

BIN
barcode_action/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

28
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);
}
});
},
});
});

24
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,
};
});

12
barcode_action/views/barcode_templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="assets_backend" name="pos_validation_barcode assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/barcode_action/static/src/js/action_barcode_form.js"/>
<script type="text/javascript"
src="/barcode_action/static/src/js/action_barcode_widget.js"/>
</xpath>
</template>
</odoo>

1
barcode_action/wizard/__init__.py

@ -0,0 +1 @@
from . import barcode_action

22
barcode_action/wizard/barcode_action.py

@ -0,0 +1,22 @@
from odoo import fields, models
class BarcodeAction(models.TransientModel):
_name = 'barcode.action'
_inherit = "barcodes.barcode_events_mixin"
model = fields.Char(
required=True, readonly=True
)
res_id = fields.Integer()
method = fields.Char(
required=True, readonly=True
)
state = fields.Selection([
('waiting', 'Waiting'),
('warning', 'Warning')
], default='waiting', readonly=True, )
status = fields.Text(
readonly=True,
default="Start scanning",
)

50
barcode_action/wizard/barcode_action_view.xml

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!--
Copyright 2017 Eficent Business and IT Consulting Services, S.L.
Copyright 2017 Creu Blanca
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
-->
<odoo>
<record id="barcode_action_form" model="ir.ui.view">
<field name="name">barcode.action.form</field>
<field name="model">barcode.action</field>
<field name="arch" type="xml">
<form string="Find">
<div class="alert alert-success text-center o_form_header"
role="alert" style="margin-bottom:0px;"
attrs="{'invisible':[('state', '=', 'warning')]}">
<bold><field name="status"/></bold>
</div>
<div class="alert alert-danger alert-dismissable text-center"
role="alert" style="margin-bottom:0px;"
attrs="{'invisible':[('state', '=', 'waiting')]}">
<bold><field name="status"/></bold>
</div>
<field name="state" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="model" invisible="1"/>
<field name="method" invisible="1"/>
<field name="_barcode_scanned" widget="action_barcode_handler"/>
<footer>
<button
name="action_cancel"
string="Close"
class="oe_link"
special="cancel"
/>
</footer>
</form>
</field>
</record>
<act_window id="barcode_action_action"
name="Barcode Launcher"
res_model="barcode.action"
view_mode="form"
view_type="form"
target="new"/>
</odoo>
Loading…
Cancel
Save