Skip to content

Commit

Permalink
Merge c31612f into 25cf9cb
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmoya committed May 31, 2017
2 parents 25cf9cb + c31612f commit 554849f
Show file tree
Hide file tree
Showing 38 changed files with 21,679 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -13,7 +13,6 @@ build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
Expand Down
79 changes: 79 additions & 0 deletions stock_scanner_web/README.rst
@@ -0,0 +1,79 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=================
Stock Scanner Web
=================

This module extends the functionality of stock scanner play scenarios on web
interface. Some features of this module are:

* Responsive layout, properly displayed on mobiles.
* Link called "Web Stock Scanner" in the inventory menu to access the website.
* Added modifications to restrict hardware usage to specific users.
* Initial View to allow user to select among various hardware devices.


Configuration
=============

To configure this module, you need to:

* Create a Scanner Hardware and add to the user. You can now do this directly
from the user form.
* Also, do not forget to enable "Sentinel: technical users" option in the
user form, as it is required by the basic stock_scanner module.


Usage
=====

To use this module, you need to go to:

* .../scanner_call/

or call it directly clicking on the "Web Stock Scanner" option of the
inventory menu.


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/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.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Angel Moya <contacto@angelmoya.es>
* Jordi Ballester <jordi.ballester@eficent.com>
* Aarón Henríquez <ahenriquez@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Saulius Žilys <saul@saulenia.eu>


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
8 changes: 8 additions & 0 deletions stock_scanner_web/__init__.py
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Angel Moya <http://angelmoya.es>
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# <http://www.eficent.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
from . import models
31 changes: 31 additions & 0 deletions stock_scanner_web/__openerp__.py
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Angel Moya <http://angelmoya.es>
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# <http://www.eficent.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Scanner Web",
"summary": "Show scenarios from stock scanner on web app",
"version": "9.0.1.0.0",
"category": "Warehouse",
"website": "https://odoo-community.org/",
"author": "AngelMoya, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"stock_scanner",
],
"data": [
"views/web_templates.xml",
"views/scanner_hardware.xml",
"views/warehouse_menu.xml",
"views/res_user_view.xml",
],
'demo': [
'demo/stock_scanner_demo.xml',
'demo/template_view.xml',
'demo/TutorialWeb.scenario',
'demo/Web_step_type/Web_step_type.scenario',
],
}
7 changes: 7 additions & 0 deletions stock_scanner_web/controllers/__init__.py
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Angel Moya <http://angelmoya.es>
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# <http://www.eficent.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import main
177 changes: 177 additions & 0 deletions stock_scanner_web/controllers/main.py
@@ -0,0 +1,177 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# <http://www.eficent.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import http
from openerp.http import request
from openerp import _


def allowed_hardware(user, t_num):
allowed = False
for hardware in user.scanner_hardware_ids:
if t_num == hardware.code:
allowed = True
return allowed


class ScannerWeb(http.Controller):

@http.route([
'/stock_scanner_web',
'/stock_scanner_web/<string:terminal_number>',
'/stock_scanner_web/<string:terminal_number>/<string:scenario_step>',
'/stock_scanner_web/<string:terminal_number>/<string:scenario_step>'
'/<string:action>/',
'/stock_scanner_web/<string:terminal_number>/<string:scenario_step>/'
'<string:action>/<string:message>/'
], type='http', auth='user')
def scanner_call(self,
terminal_number='',
action='',
message=False,
scenario_step=False,
type='http',
auth='public',
website=True,
**kwargs):
values = {} # Reset the values.
parameters = kwargs.copy()
if 'debug' in parameters:
parameters.pop('debug')
if message == 'False':
message = False
if not message and parameters:
message = kwargs
# Determine the correct hardware:
scanner_hardware = False
user = request.env.user
if terminal_number:
if not allowed_hardware(user, terminal_number):
values = {
'result':
_('Hardware {} not allowed for user {}.').format(
terminal_number, user.name)
}
return http.request.render(
'stock_scanner_web.hardware_select',
values)

else:
terminal_list = user.scanner_hardware_ids.mapped('code')
if terminal_list and len(terminal_list) > 1:
values = {
'code': 'L',
'result': terminal_list
}
return http.request.render(
'stock_scanner_web.hardware_select',
values)

elif terminal_list and len(terminal_list) == 1:
terminal_number = terminal_list[0]
elif not terminal_list:
values = {
'code': 'N',
'result': _("You do not have any hardware allowed. "
"Please contact your administrator.")
}
return http.request.render(
'stock_scanner_web.hardware_select',
values)

# Now we have a valid hardware.
scanner_hardware = request.env['scanner.hardware'].search(
[('code', '=', terminal_number)])
if not scanner_hardware:
values = {
'code': 'N',
'result': _("No valid terminal.")
}
return http.request.render(
'stock_scanner_web.hardware_select',
values)
if not message and action == 'reset':
scanner_hardware.empty_scanner_values()
try:
(code, result, value) = scanner_hardware.with_context(
stock_scanner_call_from_web=True).scanner_call(
terminal_number,
action,
message)
except Exception as e:
values = {
'result':
_('Error: %s') % e.message
}
return http.request.render(
'stock_scanner_web.error_message',
values)

try:
scenario = scanner_hardware.scanner_check(terminal_number)
except Exception as e:
values = {
'result':
_('Error: %s') % e.message
}
return http.request.render(
'stock_scanner_web.error_message',
values)

scenario_step = request.env['scanner.hardware'].\
search([('code', '=', terminal_number)]).step_id
step = scenario_step and int(scenario_step) or 0
header = False
lines = False
if code == 'L':
header = ''
lines = []
for line in result:
if len(line) != 2 and line[0] != '|' and line[0] != '#':
lines.append({
'href': '/stock_scanner_web/%s/%s/action/%s' % (
terminal_number, step, line),
'label': line})
elif len(line) != 2 and line[0] == '|':
header = line[1:]
elif len(line) == 2 and line[0] != '|':
lines.append({
'href': '/stock_scanner_web/%s/%s/action?message=%s' %
(terminal_number, step, line[0]),
'label': line[1]})
elif len(line) != 2 and line[0] == '#':
lines.append({
'href': False,
'label': line[1:]})
header = header or message or _('Main Menu')
lines = lines
elif code in ['M', 'E', 'F', 'C', 'N', 'Q', 'T']:
header = result[0]
lines = result[1:]
elif code == 'R':
header = ''
lines = result
if code != 'W':
if header and header[0] == '|':
header = header[1:]
result = {
'header': header,
'lines': lines
}
lang = request.env['res.lang'].search([('code', '=', user.lang)])
values = {
'code': code,
'result': result,
'value': value,
'scenario': scenario,
'step': step,
'terminal_number': terminal_number,
'show_numpad': scanner_hardware.show_numpad,
'decimal_point': lang and lang.decimal_point or 'E'
}
if not message and action == 'reset':
values['action'] = 'reset'
return http.request.render('stock_scanner_web.scanner_call',
values)
15 changes: 15 additions & 0 deletions stock_scanner_web/demo/TutorialWeb.scenario
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<scenario>
<id>stock_scanner.scanner_scenario_tutorial</id>
<model_id/>
<name>Tutorial</name>
<notes/>
<sequence>0</sequence>
<parent_id/>
<shared_custom>False</shared_custom>
<warehouse_ids>OpenERP S.A.</warehouse_ids>
<warehouse_ids>Shop 1</warehouse_ids>
<warehouse_ids>Shop 2</warehouse_ids>
<active>True</active>
<type>menu</type>
</scenario>
11 changes: 11 additions & 0 deletions stock_scanner_web/demo/Web_step_type/Web_step_type.scenario
@@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<scenario>
<id>scanner_scenario_web_type</id>
<model_id>scanner.hardware</model_id>
<name>Stock Scanner Web Type</name>
<sequence>200</sequence>
<parent_id>stock_scanner.scanner_scenario_tutorial</parent_id>
<active>True</active>
<type>scenario</type>
<Step id="scanner_scenario_web_step_web" name="Web Step" step_back="False" step_stop="True" step_start="True"/>
</scenario>
@@ -0,0 +1,9 @@
# flake8: noqa
# Use <m> or <message> to retrieve the data transmitted by the scanner.
# Use <t> or <terminal> to retrieve the running terminal browse record.
# Put the returned action code in <act>, as a single character.
# Put the returned result or message in <res>, as a list of strings.
# Put the returned value in <val>, as an integer

act = 'W'
res = 'stock_scanner_web.step_web_template'
8 changes: 8 additions & 0 deletions stock_scanner_web/demo/stock_scanner_demo.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<openerp>
<data noupdate="0">
<record model="res.users" id="base.user_root">
<field name="scanner_hardware_ids" eval="[(4, ref('stock_scanner.scanner_hardware_1'))]"/>
</record>
</data>
</openerp>
20 changes: 20 additions & 0 deletions stock_scanner_web/demo/template_view.xml
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="step_web_template" name="step_web_template">
<form method="get" t-att-action="'/stock_scanner_web/%s/%s/action' % (terminal_number, step)" class="search_class form-inline">
<h3>
Web Step Example
</h3>
<div>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png"/></a>
<p>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.</p>
<p>To contribute to this module, please visit
<a class="reference external" href="https://odoo-community.org">https://odoo-community.org</a>.</p>
</div>
<div class="form-group">
<input type="text" name="location_name" class="search-query form-control" autofocus="autofocus"/>
</div>
<button type="submit" class="btn btn-primary pull-right">Submit</button>
</form>
</template>
</odoo>
8 changes: 8 additions & 0 deletions stock_scanner_web/models/__init__.py
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Angel Moya <http://angelmoya.es>
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# <http://www.eficent.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import res_user
from . import scanner_hardware

0 comments on commit 554849f

Please sign in to comment.