Commit Graph
150 Commits
Author SHA1 Message Date
Aaron Bohy ff6e89052d [REF] web,*: regroup custom hooks in core/utils/hooks
*base_automation,iap,im_livechat,point_of_sale

This commit introduces a new file in core/utils: hooks.js
This file contains custom hooks (useEffect, useService, useBus...).

The useHotkey hook is tightly related to hotkeys, so it has been
moved to core/hotkeys.

closes odoo/odoo#74535

Related: odoo/enterprise#20003
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
2021-08-02 11:13:52 +00:00
Samuel Degueldre 4c7ef96974 [REF] web: refactor debug menu to use context in env instead of service
This makes the debug menu more natural to use, and makes the difference
between the "in-dialog" and "out-of-dialog" debug contexts explicit.

closes odoo/odoo#74346

Related: odoo/enterprise#19967
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-07-30 06:01:42 +00:00
Lucas Perais (lpe) 4919e50a3d [FIX] web: core: download: error handling
Try to download a report file but knowing that the controller will raise an Exception

in the case of l10n_be: Tax Report
Remove the VAT number on the Belgian Company and export the report as xml

Before this commit, the error was not well handled, i.e. a traceback was shown

After this commit, a Redirect dialog is shown, giving the possibility to the user to go
on the company's list view and change some company's fields.

closes odoo/odoo#74021

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-07-22 06:38:20 +00:00
Aaron Bohy 8c1d226284 [IMP] web: dropdown: add "toggler" props
This commit adds an optional "toggler" props to the Dropdown
component. If set to 'parent', no toggler will be generated by
the Dropdown component. Instead, the parent element of the dropdown
will be its toggler.

closes odoo/odoo#73858

Related: odoo/enterprise#19702
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-07-19 09:12:31 +00:00
Aaron Bohy 923ba830db [REF] web: dropdown: make "menu" the default slot
The dropdown Component takes 2 slots: one for the toggler, and one
for the actual dropdown content. Before this commit, the default
slot was the toggler, and the other one was named "menu".

However, as the toggler is actually optional, and the "menu" slot
contains the central information about the dropdown, we decided to
swap them. The content of the dropdown is now the default slot and
the toggler can be specified with the "toggler" slot.
2021-07-19 08:54:31 +00:00
Francois (fge) 7dc28604d7 [FIX] web: traceback generated by hotkeys
This commit fixes the erroneous tracebacks generated by keyup events
in the hotkey overlay. (alt + key)

TASK-2591069 - BUG 3
2021-07-19 09:11:14 +00:00
Francois (fge) 55dab0e7d1 [IMP] web: use of a default OS for tests
The purpose of this commit is to have a test environment
that does not depend on the OS of the machine
on which the Odoo server is deployed.

Because the navigator.platform is deprecated, we will use the
navigator.userAgent to identify the OS.
2021-07-19 09:07:09 +00:00
Bruno Boi 300ef9ac6f [FIX] web: dropdown must close when activeElement change
When the UI active element changes, a opened dropdown should close.

Before: dropdown do not close
After: it is
2021-07-12 06:27:49 +00:00
Francois (fge)andSergey Shebanin 7f10ca0d7c [IMP] web: make the hotkey service overlay modifier customizable
From this commit:
- It is possible to modify the overlayModifier allowing to display the
overlay and to access the data-hotkeys defined in the Dom.
- Adding a hotkey using the service or hook does not add the
overlayModifier anymore.

closes odoo/odoo#73279

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Co-authored-by: Sergey Shebanin <sergey@shebanin.ru>
2021-07-09 09:16:57 +00:00
Francois (fge) 20e157dd01 [FIX] web: doesn't apply the invisible data-hotkey
The purpose of this commit is to prevent the activation of data-hotkeys
associated with hidden elements of the dom.

Task-2591069 - BUG 1
2021-07-09 09:13:58 +00:00
Jorge Pinna Puissant 54e9527ec2 [IMP] web, *: read session information from a module
* google_recaptcha, mail, partner_autocomplete, point_of_sale, website

Now, to read session information, the module "@web/session" must be
imported. Not that, there is also the user service with all the user
information.

closes odoo/odoo#73201

Related: odoo/enterprise#19434
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-07-08 14:13:39 +00:00
Géry Debongnie 2063b26b09 [FIX] web: add context in pyeval context
When the owl refactoring landed, we rewrote the pyjs evaluation system.
Then, we used the new system in the new code. In particular, the action
service uses it to evaluate the action domain.

But the previous code had a subtle behaviour in the special case of
evaluating domain: it added the context as a pydict object in itself, so
one could evaluate expression such as `context.get('a', 14)` to read the
value of a key in the context with a fallback.

With this commit, we uniformize this behaviour across all python
expression: the `context` key is now reserved, and used to access
anything in the current evaluation context.

closes odoo/odoo#73227

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-07-05 12:53:44 +00:00
Géry Debongnie f8ffa757c8 [IMP] web: optimize read/unlink when id list is empty
With this commit, we can simply skip performing a rpc when we know that
the id list given to read/unlink is empty.

closes odoo/odoo#73063

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-07-05 14:17:58 +00:00
Géry Debongnie 3e8ee3aedc [IMP] web: add some validation in orm service
Before this commit, orm service calls had no validation whatsoever,
which means that the requests would fail serverside, then display a
python traceback. This makes it harder for developers to find the cause
of the issue.  Also, it is easy to perfom some really basic validation
anyway.
2021-07-05 13:57:54 +00:00
Aaron Bohy 88340cc2fb [FIX] web: debug: allow to edit SearchView
Before this commit, clicking on "Edit ControlPanelView" in the
debug manager actually edited the "main" view (e.g. kanban), because
we used the wrong view id.

This commit also renames "Edit ControlPanelView" into "Edit
SearchView", which is more accurate w.r.t. to the view type.

closes odoo/odoo#72995

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-30 12:59:54 +00:00
Xavier Morel 053285afdc [FIX] web: momentjs warnings
* Without an explicit format string, moment() should be called with
  ISO date(times).
* Correctly destroy all test locales (`zz` was not destroyed at all,
  and `englishForTest` was double-destroyed instead of destroying
  `frenchForTests`).
* Avoid creating a moment object from the value `false` in date(time)
  fields.
* Disable the warning entirely in dates_tests, the contents are super
  messy and weird.
2021-06-29 05:34:16 +00:00
Lucas Perais (lpe) ac0224319e [FIX] web: utils/strings: sprintf support lazy translated strings
Have something like:
```js

sprintf("my string %s", _lt("lazy translated"));

```
Before this commit, the lazy translated term was not formatted into the string.
This was because _lt returns an object containing a custom toString function, which was not handled by sprintf

After this commit, sprintf is able to handle lazy translated strings

closes odoo/odoo#72598

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-24 09:59:05 +00:00
Géry Debongnie d4bbadd699 [REF] web: slightly improve translation system
Before this commit, "lazy translated" strings were implemented as
objects with a toString function. This is simple, but does not emulate
very well the real behaviour of a string.

In this commit, we create a LazyTranslatedSTring class which subclass
the String class, so all string methods will work as expected.

We also expose the _t function here, to make it more convenient for some
code to access the translations instead of depending on the presence of
an environment.
2021-06-24 09:40:10 +00:00
Lucas Perais (lpe) a2d49d3003 [FIX] web: error_service: bind the event handlers on browser
Before this commit, the error service bound its listeners onto window.
This may create pollution when executing more than one test instanciating an error_service

After this commit, we bind the handlers onto browser, which is fully in our control in tests.
2021-06-23 15:47:55 +00:00
Aaron Bohy a52a25d4d9 [FIX] web: DebugManager: editView: correctly load view
Before this commit, the "Edit View" debug item only worked for
kanban, list and form views. For the other views, it opened a
blank form view. The reason is that for the other views, it didn't
correctly get the id of the view to edit.

Bug reported in the wowl-bugs pad

closes odoo/odoo#72523

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-23 09:44:10 +00:00
Géry Debongnie 30fce04357 [FIX] web: tolerate empty string as action context
Before this commit, calling "makeContext" with an empty string as
context description crashed. For instance, this happened with at least two
actions in Odoo:

Elearning > Courses > Contents
Fleet > Vehicules > Odometers

In both cases, the context in the action is the empty string.
Issue spotted thanks to the clickEverywhere test.

The crash was caused by the pyjs parser. This is correct (even though
the error was not clear), since an empty list of token do not represent
a valid python AST.  So, the fix is to make the makeContext function
more tolerant.

closes odoo/odoo#72490

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-21 20:44:11 +00:00
Géry Debongnie 7ca9a2012b [IMP] web: introduce errorhandler and notupdatable component
This commit adds two utility components:

- NotUpdatable: a component meant to be used when a component does not
  depend on anything from its parent, so it should not be rerendered
  whenever the parent is updated.  This is an optimization.
- ErrorHandler: a component that provides a nice way to catch errors
  in the rendering for a sub component
2021-06-18 21:31:34 +02:00
Géry Debongnie 97c88e8c06 [IMP] web: add shouldUpdate=false to some components
We add in this commit a "decorator" to make components that do not
rerender when their parent is updating them. This makes sense for some
main components that knows before hand that they do not depend on a
props change.

This commit is mostly an optimization to avoid useless work by owl, but
it also has some interesting properties: before this commit, each
dialogs would be rerendered whenever a new dialog is added. This could
be an issue if the rendering of one of them causes an error, which needs
in turn to add a dialog, ...

closes odoo-dev/odoo#970

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:34 +02:00
Mathieu Duckerts-Antoine d4070495d6 [FIX] web: traceback when assets loading fails
Before this commit, if the loading of a js or a css asset would fail
(via useAssets), a traceback with an incorrect message would appear.
This was due to the fact that a promise was rejected with an event as
parameter. We correct this by rejecting the promise with a custom error.

closes odoo-dev/odoo#960

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:33 +02:00
Michael Mattiello (mcm) 580533ecfb [REF] web, *: change dialog service api
* iap, web_tour

This commit changes the API of the dialog service.

Before, the API gave 2 functions: "open" and "close".
Now, there is only one function "add" which is the same as "open"
but returning a callback that does the close.

closes odoo-dev/odoo#940

Related: odoo-dev/enterprise#171
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:33 +02:00
Jorge Pinna Puissant 85dfc9cf49 [IMP] web: remove the Portal from dialog
In this commit, we simplify the dialog template by removing the Portal.
The Portal is no longer used, as now we always use the dialog service to
open a new dialog.

also:

- remove the dialog container class from the webclient;
- add the dialog container class to the dialog container;
- move the management of the inactive modal class to the dialog container;
- remove the dialog manager class from the dialog container;

closes odoo-dev/odoo#947

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:33 +02:00
Lucas Perais (lpe) c65e57e17b [REF] web: ui_service and block UI in @web/core/ui/
closes odoo-dev/odoo#925

Related: odoo-dev/enterprise#166
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:33 +02:00
Lucas Perais (lpe) 694e3f5904 [REF] web: services register their own component
Some services are coupled with a Component. Usually the service
handles the state of the system, and the Component displays or uses it.

To enable the communication between the service and the component
while making it private, the services should add themselves their
Component in the relevant registry, with the proper means of communication
passed in props.

This mechanism relies on c1d49d494e0ae3a94b3943186eb6d1ebd7b98a6e
2021-06-18 21:31:33 +02:00
Simon Genin (ges) 010bbcd9fe [REF] web: errors remove non-needed event
closes odoo-dev/odoo#953

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:33 +02:00
Bruno Boi 47acba560a [FIX] web: open menus in new tab
Before this commit, menus in navbar and clickable elements on the home
menu were not openable in a new tab through a ctrl-click or through the
middlemouse button.

In order to achieve that, we now use default behavior of <a href/> elements.

As such default behaviour would conflict with <DropdownItem/> clicks,
a global click handler is added in the WebClient constructor which stops
the click event propagation under these specific circumstances
(ctrl-click inside an <a href/> element).

Besides this work, it has been found that the <Dropdown/> root element
should not always be a <div/> as it was, but sometimes it has to be
another HTML element in order to comply with the W3C specs. E.g. a
<Dropdown/> component as a first level child of an <ul/> element must
have a <li/> root element instead of a <div/> one.

Thus, a new prop is added to the <Dropdown/> component (`tag`) allowing
the developer to choose another root element: `<Dropdown tag="'li'"/>`.

closes odoo-dev/odoo#913

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:33 +02:00
Géry Debongnie 12500d8917 [FIX] web: implement missing pyjs operation
The new py interpreter was missing the subtraction of a date with a
relativedelta

closes odoo-dev/odoo#944

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:32 +02:00
Bruno Boi aab6f88439 [MOV] web,base_automation: hotkeys from webclient/ to core/
The hotkeys feature is a core feature, not only useful for the webclient.

closes odoo-dev/odoo#942

Related: odoo-dev/enterprise#172
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:32 +02:00
Jorge Pinna Puissant ff20073b21 [FIX] web: use dialog service to close the dialogs
Before this commit, the function close on dialog trigger an event to close
the dialog. This could create an issue when the dialog is not yet mounted.

Now, the function close on dialog uses the dialog service to close the dialog.

closes odoo-dev/odoo#936

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:31 +02:00
Lucas Perais (lpe) 8a530b153b [IMP] web: debugManager: re-implement "Open view" 2021-06-18 21:31:31 +02:00
Jorge Pinna Puissant 774ca5571a [FIX] web: close, already closed dialog
Before this commit, when trying to close an already closed dialog, an
error is raised.

closes odoo-dev/odoo#928

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:30 +02:00
Jorge Pinna Puissant 22bb866588 [REF] web: move parseMonetary to currency
closes odoo-dev/odoo#926

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:30 +02:00
Michael Mattiello (mcm) 41e5435d97 [REF] web, *: refactor notification service
* bus, calendar

This commit changes the notification API and adapts codes that use it
Notification API before:
    - create(...): number
    - close(id: number, wait?: number)

Notification API now:
    - add(...): RemoveCallback

closes odoo-dev/odoo#908

Related: odoo-dev/enterprise#158
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:30 +02:00
Michael Mattiello (mcm) 2384ebc689 [REF] web: refactor popover
This commit refactors the popover to make it imperative.
Popover cannot be used in templates anymore.

closes odoo-dev/odoo#914

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:30 +02:00
Aaron Bohy 2e2d6a166e [IMP] web: userService: add hasGroup function
This commit adds the 'hasGroup' function to the user service. This
function holds a cache s.t. we never do twice an rpc for the same
group. This is the equivalent of 'user_has_group' in session, in
the legacy codebase.
2021-06-18 21:31:30 +02:00
Aaron Bohy a5091fee99 [REF] *: rework webclient test helpers
This commit splits the 'getActionManagerTestConfig' helper into 2:
'setupWebClientServiceRegistry' and 'getActionManagerServerData'.

The first one is now automatically called by the 'createWebClient'
helper, as it properly setups the service registry with all services
required by the WebClient component.

The second one generates a few data (menus, actions, views...) that
can be used in tests. That helper is mainly useful for action tests
(formerly ActionManager tests) in web. With this refactoring, they
are no longer generated for each test in the whole codebase that
spawns a webclient, as before this commit.

closes odoo-dev/odoo#906

Related: odoo-dev/enterprise#161
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:30 +02:00
Bruno Boi 8fcdcc0b1c [REF] web: extract company service from user service 2021-06-18 21:31:30 +02:00
Géry Debongnie 1b549bddd1 [REF] web: improve main_component registry API to accept props
closes odoo-dev/odoo#910

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:30 +02:00
Jorge Pinna Puissant d73309de28 [IMP] web: use dialog service on action service
Until now, the action container opened/closed an action dialog directly
on the template, and relayed on the bus to communicate with the action service.
Now the action service opens/closes the action dialogs using the action service.
To do this, a new close method is created on the action service.
This commit also separates the code of dialog service and dialog container to
be more standard.

closes odoo-dev/odoo#900

Related: odoo-dev/enterprise#156
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:30 +02:00
Géry Debongnie 1092475171 [IMP] web: give proper name to memoized functions
closes odoo-dev/odoo#905

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-06-18 21:31:29 +02:00
Michael Mattiello (mcm) 38ae01d6b5 [IMP] web: improve error management
- Error handlers have been simplified, handlers don't returns functions
anymore and take 3 params: env, uncaughtError and originalError.
- Source maps have been reintroduced.
- The original error message and name are now concatenated to
the "wrapper" error ones.

closes odoo-dev/odoo#895

Related: odoo-dev/enterprise#154
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:29 +02:00
Géry Debongnie 9850b8e4dc [REF] web: allow services to specify async methods
This commit improves the service API to allow the service creator
to mark some methods of the service as 'async'. This is a very
important feature when we consider the fact that a component calling
such a method may be destroyed before the asynchronous work is
complete. In that case, we do not want any code from the component
to be executed. Such async method, when called in a component (i.e.
when the service was obtained with the useService hook), will be
wrapped in such a way that the returned promises will not be resolved
if the component is destroyed.

Note that it only impact method calls for services obtained from the
useService hook, not calls for the actual service obtained from the env.

closes odoo-dev/odoo#886

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:29 +02:00
Mathieu Duckerts-Antoine 80b02e833d [IMP] web: reintroduce triggerEvent helper
Writting tests in which input/select elements are involved can become quickly cumbersome
when some external libraries are used somewhere to interact with/manage them. Indeed, change some
input/select value normally triggers some event of a precise form and this has to be properly mocked
in the tests if one expect the libraries to react properly.
The present commit reintroduces the old helper "triggerEvent" (and its generalization "triggerEvents")
that should help in that kind of task.

closes odoo-dev/odoo#887

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-06-18 21:31:29 +02:00
Mathieu Duckerts-Antoine f4160d5907 [IMP] web: allow to parse more numbers
The present commit reintroduces several number parsers that were previously defined in web.field_utils:
parseFloatTime, parseInteger, parseMonetary, and parsePercentage. Some minor simplifications in their API
have been brought. Notably, the "field" parameter has been removed. Indeed, we expect those parsers
to be used in more specific contexts than before so that the advantage of having a common API (value, field, options)
has become less important.
2021-06-18 21:31:29 +02:00
Julien Mougenot a688f13cd4 [IMP] web: improve debug Menu extensibility
This commit renames the DebugManager to "DebugMenu", changes the
structure of its registry and the signature of its hook (useDebugMenu).

In the previous DebugManager:
- the "debug" registry was flat;
- new items were declared and created with the "useDebugManager" hook;
- these items were arbitrary functions returning a set of items.

The problem with that system was its extensibility, meaning that no
external module could hook on these arbitrary functions passed to the
hook.

In the new DebugMenu:
- the "debug" registry has multiple levels:
  > root: "global" items, found in most debug menus
  > subcategories: each subcategory has a name corresponding to the
    context it's instantiated in (e.g.: the "view" subcategory will only
    contain views-related debug menu items)
- all items are pre-declared in their corresponding category, and either
return a debug menu item or null;
- the hook activates/deactivates categories, and passes a context which
will be used by the item factories (passed as argument).
2021-06-18 21:31:29 +02:00
Michael Mattiello (mcm) b59024f6ba [IMP] web: use the error class to handle errors
Before this commit, error handlers checked the error name to know if
they should be executed.

Now, they check the instance type of the error to be more accurate on which
error an handler deals with.

This commit also changes `emptyRejectionErrorHandler` sequence number
because it had more priority than `rpcErrorHandler` and `lostConnectionHandler`.
2021-06-18 21:31:29 +02:00