In order to detect if a barcode scanner is being used, we detect the
delay between keypresses. The value is hardcoded to 55 ms. However, in
the case of a bluetooth scanner, this delay is often not enough,
resulting in an incorrect capture of the barcode.
We add the config parameter `barcode.max_time_between_keys_in_ms` which
allows the user to fine tune this delay for his hardware.
opw-806398
There is a subtle issue happening in tests when we override a widget
property for the duration of the test and try to restore the initial state at
the end by rewriting on the property. It actually changes the widget, by
having a function bound to the sub widget prototype instead of its ancestor.
This in turns can cause weird interactions with the class system.
We introduced a proper way to temporarily patch a class/widget by adding
a method in testUtils to do exactly that. This commit simply uses that
method to prevent unwanted interactions in barcode tests
related to rev 0d19ee989d
It was broken following the refactoring done in saas16, resulting in
barcodes being handled on all the displayed forms and it was problematic
in the case of a form dialog openned over a "fullscreen" form view.
This was particularily problematic for the scrap dialog in the
stock_barcode module.
Resetting the key 'test_barcode_handler' to its value before the
test was technically the best solution, as a test should leave the
environment unchanged. However, in this case, the widget is
undefined (there is obviously no 'test_barcode_handler').
Whereas this should not be a problem (the fields in the registry
are supposed to be accessed using get(), and the presence of a
key mapping undefined is equivalent to the absence of the key in
this case), this breaks a test in Studio if the latter one is
executed after the barcode test. This is because Studio browses the
map of the field registry to access each field's prototype. When it
encounters an undefined value, it crashes.
This was the case about 15minutes ago. But before pushing we
decided to change the Barcode override of FormController to
directly use handlers of the FormController when it could (e.g.
to handle 'Edit', 'Discard' actions). This wasn't a good idea as
those handlers don't return anything, and the barcode mechanism
requires its handlers to return a deferred. So basically, it
crashed when such a barcode was scanned. Having a test suite is
nice, but you should not forget to relaunch it before pushing...
The barcode mechanism is supposed to handle commands PAGER-FIRST
(go to first record referenced in the pager) and PAGER-LAST (go
to last record). Before this rev., it wasn't the case.
We needed to add an option 'notifyChange' to the updateState
function of the pager, to ensure that the form is correctly
reloaded when the pager cursor is manually set (by the barcode
handler) on the first or last element.
The barcode mechanism is optimized to (in certain conditions),
directly increment the quantity of a numerical field inside an
x2many, without performing any RPC, and then re-rendering the
x2many to display the new value.
Before this rev., it seemed to work fine, but when the view was
saved, those changes of quantity were lost. This was because the
changes weren't correctly notified to the model (the quantity
field being inside an x2many, the correct update command for the
x2many should be generated).
When a barcode field with widget="barcode_handler" is in a form
view, an onchange RPC should be done each time a barcode is
scanned.
Before this rev., it worked by chance because the views using it
don't define a 'pack_operation_product_ids' field.
Anyway, this widget is meant to be generic, so it shouldn't
hardcode a fieldname.
Before this rev. a warning was displayed when a barcode mapping an
invisible button was scanned. It shouldn't, for the following
reason. In the stock.picking form view, two buttons with
barcode_trigger='validate' are in the page ('Start Inventory' and
'Validate'), and there is always at least one of them that is
invisible. So when scanning the 'validate' barcode, we don't want
a warning to be displayed, as there is potentially another button
that is able to handle the request.
When scanning a command barcode, the view shouldn't be redrawn
after the operation corresponding to the command is executed,
for two reasons: first, it is useless as the view has already
been reloaded, and second, it may cause issues if it has been
destroyed meanwhile.
For example, when scanning barcode O-CMD.MAIN-MENU from a
picking form view: a do_action is performed to go back to the
main barcode client action (so the current form view is destroyed),
but an handler tried to redrawn the destroyed form view, which
produced a crash because the session was required by Date fields,
and it couldn't be provided (there were no more parent listening
to provide it).
When a keypress event is triggered in a 'field_float_scannable'
widget, the event is first catched by the barcodes mechanism, and
then manually re-triggered. However, the way it was done implied
that the environment was notified of each keypress event, so if
there was an onchange on that particular field, an onchange RPC
was done at each keypress.
Moreover, the focus was lost at each keypress as well.
This option has been removed with the new views but was used in barcode.
The form renderer was also dealing with some part of the autofocus
but this should only be handled by the controller.
The logic is now only in the controller and a test case has been added.
Since the new views, most of the barcodes feature was
broken. This commit re-enables the support of commands like
'edit', 'save', 'cancel', 'previous' and 'next'.
Also changed javascript event handler to jquery event handler to
make barcodes testable in phantomjs.
* web_editor, web_planner, website
The 'Dialog' class is used in both backend and frontend. Also, lots of
actions can be done without the use of any modal. It thus makes sense
to lazy load its related xml only when a first modal is opened.
This change also allows to get rid of the "base_common.xml" file as the
dialog template is the only remaining one in there and, in the future
website update, it will allow to not load any static XML file on website
page loadings.
Before this commit, the JS parser would add 0 after the input, then add the ean key.
Whereas reportlab.graphics.barcode fills the input with 0's on the left, then add the key
http://pydoc.net/Python/reportlab/2.5/reportlab.graphics.barcode.eanbc/
At: Ean13BarcodeWidget.__init__()
This commit makes the ean parser coherent with the lib the python uses
Usecase: A person scans various products in a warehouse or the network is slow.
Only one request per product must be made, the rest is changing the number locally
and all performed scans (products or actions) must not be lost.
The mutex ensures that the scan is performed in the correct order.
Since the new views merge, a lot of design elements were broken. This
was particularly impacting the fields in the editable list view; indeed
the editable list view is not using an inline form view anymore so the
fields in the list were not properly styled as the LESS was still
defined assuming the form view environment (for example the invalid
fields were red for o2m fields in form view but not in editable list
view even though they got the right CSS class).
This commit refactor the LESS following these rules:
- No more division of non-layout and layout rules. Dividing LESS rules
in x_layout.less and x.less was a mistake. Many rules can be
considered to be layout and not layout at the same time, developers
always have to switch from one file part to the other, many CSS
selectors (and rules!) are duplicated for nothing, ...
- Field style is extracted from x_view.less and put in the new
fields.less file. As before, the fields_extra.less will contain the
rules specific to community so that the enterprise repo can override
those by replacing the whole file.
- Many classes have been renamed so that o_form_x_y becomes o_x_y as
many classes can now be applied outside of form view. These classes
should not be used in templates anyway.
The commit also changes the DOM of fields so that it is more minimalist
(no useless parent div, etc).
Input elements are not automatically styled anymore, they have to get
the o_input class explicitely. This allows to fix lots of small style
bugs of previous versions (required monetary field had not the proper
style, readonly m2m tags appeared as editable, ...). This also improves
the LESS code.
The editable list view should also completely stop flickering on chrome
and firefox.
The commit also removes the orange outline on list view dirty cells.
The commit also removes deprecated static xml, LESS and other code.
Notice there are still styles to restore/fix and LESS to improve.
With the new views, the barcode mechanisms were completely broken,
because the view and widget JS code was totally changed.
This commit update and refactor all that code to make it work with the
new design philosophy. Also, it update the coding style.
The RPC system was not completely satisfactory, we decided to prepare
the future and do it properly. This commit introduces the new rpc
system, which replace the previous new one. We now simply have a
method, this._rpc, which takes a dictionary of parameters. The idea is
that depending on the parameters, it is able to add correct default
value when necessary.
For situations where we don't have the this._rpc method, we can use the
rpc.query method, which takes the same arguments, but directly calls
ajax.rpc instead of triggering up some events.
Commit cef659783514f8935cc46a496f71063d022e8dac changed the way domains
are computed but forgot to change the values representation used by the
Kanban view. This commit fixes that and adds tests to make sure it does
not happen again.
This commit introduce a full redesign of all JS views. We started
basically from scratch. The goal was to unify all the various views
under a common framework, to make them testable, to make then usable in
different conditions (in studio, or in the frontend), and to make our
lives easier.
Some important points are:
- we introduced new coding guidelines (camelCase, 80 chars width, ...)
- we have a brand new testing framework (still QUnit based)
- kanban view moved to the web addon
- calendar view (formerly web_calender) moved to web as well
- the tree view was removed
- all new code should be documented
We hope that this code is the start of a new era for the Odoo web
client, we want to have a high quality codebase, well documented, well
tested, well designed.
Work done by the framework team: mostly aab, ged, chm, dmo, qsm
On firefox pressing special keys such as: Left Arrow or Backspace
trigger a keypress event.
This is different from google chrome which only generate a keydown and
keyup event.
There was thus two issue when using a FieldFloatScannable and firefox:
1. Keys such as ArrowLeft: would still be catched by FieldFloatScannable
and be added programatically to the field but since Odoo didn't fix
them a ASCII NUL character (0x0) would be added (in firefox it is
represented by a large space).
2. Keys such as Backspace: would still be catched by FieldFloatScannable
but were modified and corrected by Odoo so the corresponding ASCII
character was added (ASCII BS character (0x8) for backspace).
The feature in FieldFloatScannable which add the character is used to
add characters for which the browser had been prevented to display them.
Thus this fix:
- for issue 1 and 2: only use the feature of FieldFloatScannable if the
event was previously prevented and the current one is a forgery.
- for issue 2: add "Backspace" and "Delete" as specials characters which
should not be modified or stopped by the scanner heuristic.
opw-706352
Suppose the following usecase: you scan the first product of the
picking. A server onchange is then triggered. You scan the same product
a second time, before the first onchange has returned. You expect that
the first onchange is completely executed before running the second one.
This was not the case. Moreover, some onchanges were not be able to
work with the invalid state of the formview at some times, and crashed.
The previous implementation was wrong because id didn't run the main
barcode processing mechanism inside a Mutex. It was also wrong because
it didn't correctly wait for the onchange to execute (a previous barcode
onchanges or some classic ones) before setting the barcode field.
Using the constructor `new Event()` is not supported in IE >= 9.0
(tested on IE 11). It raises the below error:
`Object doesn't support this action`
This revision implements the Polyfill `CustomEvent()` suggested
by the MDN here:
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
and uses it if the `new Event()` call fails.
opw-690984
Before, the '_set_quantity_listener' function was opening a 'window.prompt'
which had different comportment depending the navigator. For example,
the focus was not allways on the input field, the enter key 'Cancel'
the prompt or 'validate' it.
So to improve the usability and the consistancy we used a dialog instead
a prompt, to manage the focus and the 'Enter' key pressed when we want to
set a quantity.
When we are trying to set the quantity on a mobile device, we get
a traceback saying that we cannot call the 'find' function on the
elements returned by '_get_records'.
This '_get_records' function returns a 'Collection' when called on a tree
view and an 'Array' when called on a kanban view. When we are working
on a mobile device, most of the one2many are displayed as kanban.
The thing is when we work with the object returned by '_get_records' we
call a 'find' method on it, which is implemented by Odoo's Collection class.
So when we call 'find' on an 'Array' we actually call 'Array.prototype.find' which
is implemented on most desktop browser and on some mobile browser [1]. This is what
caused the traceback on Chrome in Android.
To fix this issue, we enforce '_get_records' to always return an 'Array' and we ensure
that, when working on this 'Array', we use '_.find'.
[1] https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/find
The quantity event handler is not correctly unbound when its action
is deleted, resulting in multiple window.prompt asking the quantity
of the products if you go mulitple times trough a view when a widget
implementing the barcode thing is used.
There seems to be a bug in the framework ("barcode_scanned" events
are registered the same way than the "keypress" one on core.bus
but they don't have suffer from the same issue).
It's possible to trigger click on form view's button with the help
of the "barcode_trigger" attributes. However, we don't want to be
able to execute clicks on items that aren't clickable by the user.
That's why we wrote the following condition: if the elem is visible
OR is a child of a .dropdown-menu, we trigger the click.
The second condition was always true since we used the jquery's
parent function which return an empty list when no result, and
an empty list is truthy.