Commit Graph
100 Commits
Author SHA1 Message Date
Samuel Degueldre b258e5d294 [FIX] http: force mimetype of .js files to text/javascript
Previously, when the odoo server was running on some Windows
installations, it was possible for javascript files loaded directly from
the static folder of an addon to fail to run because the Content-Type
header was set to text/plain instead of text/javascript. This is because
the mimetypes module from the standard library honors the mimetypes from
the OS, in the case of Windows it reads a key in the registry, which can
be misconfigured to text/plain for .js files.

This commit forces the mimetype of .js files to text/javascript to solve
this issue.

closes odoo/odoo#162313

X-original-commit: 64cbe389e698398eee93ebde9c61b2ee79756380
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2024-04-18 05:53:27 +00:00
Samuel Degueldre e9a8baf95e [REF] web: simplify confusing curried functions in pyjs
Previously, methods on python objects such as sets and strings were
implemented as functions returning a function returning the result.
While curried functions can be a great tool, they're also confusing at
first glance and in this particular case they can be easily replaced by
a simple function and the usage of Function.prototype.bind to bind it to
the correct argument. We also add a simple whitelist for pyjs functions
as a sanity check as it makes no sense to call JS functions from python
code.

With this change, we can also treat functions and methods from any
object more uniformly instead of having many return points that are
treated like special cases.

task-3762958

Part-of: odoo/odoo#139451

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2024-02-28 10:08:38 +00:00
Samuel Degueldre 7070925701 [FIX] mail: stop leaking memory in onExternalClick
The onExternalClick custom hook keeps a reference to elements that may
no longer be in the DOM, this can cause entire sections of the DOM that
are no longer needed to be kept in memory, and can also retain the
associated Owl components and their data.

To solve this, we set the downTarget and upTarget to null after calling
the callback. In practice they are no longer used in the code but we are
keeping it for stable compatibility.

closes odoo/odoo#153654

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2024-02-12 22:26:16 +00:00
Samuel Degueldre bc2a3bc55c [FIX] web: stop views leaking their models
Previously, when exporting its state so that it could be restored later,
the relational model would export its config. The problem is that
because this config is a reactive object, it keeps a reference to the
components that may need to be notified by that reactive object. This
exported config was then stored on the next controller, which would be
retained by the next config, etc.

This commit fixes that by exporting a raw version of the config.

Part-of: odoo/odoo#153654
2024-02-12 22:26:16 +00:00
Samuel Degueldre 857c540f6a [FIX] web: prevent luxon objects from being made reactive
When reading values in reactive objects, Owl's reactivity system will
return reactive versions of the sub-objects to allow tracking reads in
depth, so that changes to values in deep object hierarchies can still
cause components to render themselves if needed.

Luxon objects are immutable. Since they cannot change and values inside
them cannot change either, tracking reads within luxon objects is pure
overhead.

This commit makes luxon objects non reactifiable by setting the
Symbol.toStringTag property on the luxon classes, which is what Owl uses
internally to determine if objects can be made reactive. It will also
cause some of these objects to serialize to more specific strings
instead of just [object Object], eg [object LuxonZone].

closes odoo/odoo#153540

X-original-commit: ac58cb22cd8b275f89bf387a6cea8144ce26ee65
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2024-02-12 10:44:48 +00:00
Samuel Degueldre 8f1f32d0fb [FIX] web: improve ListRenderer rendering speed
The ListRenderer disables the checkbox of all lines corresponding to a
record which cannot be selected. Unfortunately, because
`canSelectRecord` is a getter, it is invoked once per line, and this
getter in turns invokes the `editedRecord` getter which scans all record
to find which record is selected. This operation is O(n²), so it's very
slow when there are a lot of records.

This commit fixes that by computing the value once per render.

Time to render the list view of views (technical > User Interface >
views) with 600 records visible:
- before: ~1800ms
- after: ~250ms

closes odoo/odoo#149051

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2024-01-11 17:00:54 +00:00
Samuel Degueldre 07fd47ab0b [IMP] web: update owl from 2.2.6 to 2.2.7
Release notes:
https://github.com/odoo/owl/releases

Commits:
- [IMP] types: correctly support Function type for props-validation
- [IMP] app: allow to instantiate templates lazily
- [FIX] compiler: compile named slot in t-component in named slot
- [IMP] devtools: update the devtools documentation
- [IMP] owl-vision: syntax scripts, single quotes attributes and slot props highlight and switch below command
- [IMP] doc: improve documentation of useExternalListener
- [FIX] devtools: remove highlights when out of devtools
- [IMP] devtools: highlight component on select
- [ADD] owl-vision: vscode extension initial commit

closes odoo/odoo#145460

Forward-port-of: odoo/odoo#145342
Forward-port-of: odoo/odoo#145236
Signed-off-by: Géry Debongnie <ged@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-12-11 17:21:12 +00:00
Samuel Degueldre c191a08f03 [FIX] web, web_tour: fix auto-start, tour priority and tour resetting
Previously, if a tour was added to the registry after the tour service
started, it would not be registered and could not be started. A previous
PR ( odoo/odoo#125055 ) fixed this behaviour, but did not auto-start the
corresponding tour if needed. This commit fixes that.

It also runs "auto" tours in exclusive mode, ie only one tour at a time,
to prevent the check delay from being impacted by other tours which can
lead to unwanted behaviour, especially with bootstrap modals, which are
not immediately closable as soon as they start displaying, and can cause
some test tours to fail.

Tours that auto-start no longer reset to the first step when refreshing
the page, and when multiple tours are running in parallel and can show
their pointer on the same screen, the tour with the highest
priority/lowest sequence is now the one to show their pointer, instead
of it being the one that was started first.

task-3377185

closes odoo/odoo#143598

X-original-commit: 4bba22763436645e94b484fc1cca3752effa9a25
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-12-01 18:14:11 +00:00
Samuel Degueldre eb1d96e011 [FIX] web: correctly display module errors in the qunit suite
Since the module loader rewrite, it now reports errors directly in the
DOM. The error alert also has the class "modal" so that in case a tour
comes accross a page with module loading errors, it will only look for
elements inside it and fail. But in the QUnit test suite, modals are
invisible by default, causing the page to be blank in those cases.

This commit adds a css rule to make sure that this error alert is shown,
and updates the code that was previously used to report these errors in
the qunit suite to instead simply check for errors reported by the
module loader.

closes odoo/odoo#143589

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-11-25 05:41:45 +00:00
Samuel Degueldre 5385b65384 [FIX] web: correctly use readonly value in datetime field
Previously, the datetime field read the value for readonly directly in
the attrs when extracting its props when available. This resulted in 2
separate bugs:
- in debug mode, props validation of the datetime picker would fail, as
it expects to receive a boolean for the `range` prop.  This was caused
by the fact that required was the raw attribute (a string) instead of
the boolean and ended up being propagated to the `range` prop
- outside of debug mode, the value for required did not cause a crash
but any value for required that was not empty would be interpreted as
truthy, causing the field to always be display itself as though it is
required. In non-range mode, this is invisible, but in range mode, it
would always show the second datetime input and the arrow between the
beginning and end date, even with required being 0/False, or a python
expression that may evaluate to false

This commit fixes that by instead reading the value for required from
the dynamic infos provided to `extractProps`, which will always be a
boolean and contain the value of the evaluated expression when
appropriate.

closes odoo/odoo#143509

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-11-24 23:57:36 +00:00
Samuel Degueldre 86635b5cc6 [IMP] web: extract owl app creation logic into helper
Currently mounting an owl application using the Odoo web framework takes
a good bit of boilerplate. This is both annoying but also creates the
opportunity to misconfigure created applications. This commit exctracts
the application creation logic to a helper function which will make it
much easier to create Owl applications correctly.

task-3580007

closes odoo/odoo#142498

Related: odoo/documentation#6493
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-11-21 20:06:45 +00:00
Samuel Degueldre 02aac0f59c [FIX] website: add step delay
Part-of: odoo/odoo#139209
2023-11-02 21:02:44 +00:00
Samuel Degueldre eaa6e4fdb3 [FIX] website: correctly debounce adaptAnchor
Previously, we attempted to debounce in what appeared to be an override
of the onWillStart method, but this method doesn't actually exist on the
parent classes and as such is never registered with the onWillStart
hook. This commit fixes that by registering it in an override of the
setup method instead.

task-3439226

Part-of: odoo/odoo#139209
2023-11-02 21:02:44 +00:00
Samuel Degueldre 30733c8f3c [REF] web: remove useless rpc/fetch patching code
Previously, when creating the public root, we would patch the rpc
service and the browser.fetch function so that they would rewrite the
relative URLs that they fetched to target the Odoo server. This is
useful when the public root is mounted on pages that are hosted on a
different server than the Odoo server, in particular, this was
historically useful for embeding the livechat widget in a website not
hosted by Odoo.

In odoo/odoo#122834 the livechat was refactored and got its own boot
code that does the same thing, making this code no longer useful. In
addition, in odoo/odoo#133153 the baseUrl we use no longer refers to the
session prefix which was configured by the livechat previously, but
simply refers to the origin of the page where the code is hosted, making
it a no-op.

These factors mean that the code removed by this commit is now
completely useless, which is why this commit removes it.

closes odoo/odoo#136672

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-10-03 20:17:38 +00:00
Samuel Degueldre be4f674ff9 [IMP] web: public component service
This commit introduces the publicComponentService, which makes it easy
to mount OWL components in the front end. All public components will share
the same env and therefore the same services.

To define an OWL Component in a public template, first create an owl component
and add it to the "public_components" registry in javascript, then use
<owl-component name="key"> in the template, where key is the key you used when
registering your component. If you want to pass props to your component, you can
give it a props attribute in the template, containing the props as JSON.

Example:

My Public Component:

```js
class MyPublicComponent extends Component {...}
registry.category("public_components").add("my_public_component", MyPublicComponent);
```

My Public Template:

```xml
<templates>
    ...
     <owl-component
        name="my_public_component"
        props='{"title": "My First Public Component"}'/>
    ...
</templates>

```

Part-of: odoo/odoo#136159
Co-authored-by: Samuel Degueldre <sad@odoo.com>
2023-09-29 09:21:51 +00:00
Samuel Degueldre 4aaee61a5f [REF] website_slides: remove usage of legacy dialog to enroll
The Dialog widget is deprecated and will soon be removed, this commit
converts the usage of this dialog for the enroll buttons to use the new
dialog service.

To avoid duplicating the opening logic in the Quiz code, the selector of
the widget that opens the dialog now targets the #wrapwrap and uses
event delegation for the button, avoiding the need to manually spawn the
dialog for buttons added to the DOM after the first load.

closes odoo/odoo#135476

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-09-18 10:14:07 +00:00
Samuel Degueldre 4327c062d8 [REF] web, *: remove moment.js library
The moment.js library is officially done and no longer recommends its
use for new projects. As such, we have been progressively moving to
luxon instead. Until recently, we still had some libraries that depended
on it, and some leftover calls to it. This is no longer the case, and as
such, the library can be removed completely.

closes odoo/odoo#135182

Related: odoo/enterprise#47304
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-09-13 08:20:37 +00:00
Samuel Degueldre 5b61256976 [IMP] web: datetime picker support for custom invalidity/class per day
This commit allows users of the datetime picker service to pass
functions that will be called to check the validity of specific days or
that generate a class for a given day. This can be useful in some
contexts for example when you want to prevent the user from selecting
days on the weekend for certain operations, or to highlight some days
where a given product is not in stock.

closes odoo/odoo#134647

Related: odoo/enterprise#47061
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-09-12 17:16:20 +00:00
Samuel Degueldre 239d8c0a06 [FIX] website: fix editor unable to open with filled date field
In odoo/odoo#133349 some code in website was adapted to use the new
datetime picker and luxon instead of tempusdominus and moment, but some
conversions were improperly performed causing a crash that would prevent
the website editor from opening. This commit fixes this issue and also
formats the chosen default date/datetime correctly while within the
editor.

This commit also fixes a minor issue with props validation of the
datetime picker, where we would give it an empty string instead of null
or false, causing props validation to fail in debug mode.

closes odoo/odoo#134493

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-09-12 17:16:18 +00:00
Samuel Degueldre 19217ce64b [FIX] web: restore legacy rpc error handling
Previously we removed some code related to handling errors in legacy
RPC, that would wrap errors in an object and give them an event that
could be defaultPrevented to mark the error as handled, but this code is
still needed. This commit restores it.

closes odoo/odoo#134693

Signed-off-by: Michaël Mattiello (mcm) <mcm@odoo.com>
2023-09-07 14:45:30 +00:00
Samuel Degueldre 910897fc97 [REF] web, *: remove tempusdominus date(time) picker lib
As tempusdominus relies on jQuery, we have written our own date(time)
picker in owl. This commit converts the remaining uses of the
tempusdominus date(time) picker and replaces them by our own.

closes odoo/odoo#133349

Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
2023-09-04 09:19:08 +00:00
Samuel Degueldre 6580a435a9 [IMP] web: improve datetime picker support for time
This commit improves the support for time in the datetime picker by
doing two things:
 - allow to pick seconds by giving a rounding value of 0
 - check minDate and maxDate by accounting for the time when the picker
is in datetime mode instead of only checking the date

Part-of: odoo/odoo#133349
2023-09-04 09:19:08 +00:00
Samuel Degueldre 8faef71242 [FIX] web: fix datetime picker disabling incorrect periods
Previously, if you specified a min or max date for the datetime picker
and zoomed out to the month/year/decade view, it would disable some
months/year/decade incorrectly, this was caused by the code checking if
the beginning of the period was in the min-max range instead of checking
if the period had any overlap with the min-max range.

This commit fixes that by checking for overlaps instead.

closes odoo/odoo#133911

X-original-commit: 7cb61dca99be4b0a1c35f0ec762c1bda318ec043
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-09-01 15:09:57 +00:00
Samuel Degueldre 77c1f9df71 [REF] web: remove useless legacy mapping services
These services are no longer used and are dead code, remove them.

closes odoo/odoo#133565

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
2023-08-30 09:25:12 +00:00
Samuel Degueldre 736acbf995 [REF] web, *: remove legacy date and datetime picker
*: mrp_subcontracting, project

This widget is no longer used and is simply dead code. This commit
removes it and references to it in assets bundles.

closes odoo/odoo#133139

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
2023-08-25 11:00:05 +02:00
Samuel Degueldre 2d5d2ea86d [FIX] test_website_slides_full: bump timeout of certification tour
This tour takes ~60 seconds which is very close to the default timeout
for tours, which can cause it to fail randomly. This commit bumps the
timeout to avoid this issue.

closes odoo/odoo#133088

X-original-commit: f312967ca217a2153534bbe26814de20fd5a904b
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-08-25 07:31:39 +02:00
Samuel Degueldre 6f95be6884 [REF] *: remove web.assets_common
*: auth_password_policy, bus, event, im_livechat, mail, mass_mailing,
mrp_subcontracting, point_of_sale, pos_self_order, project, stock,
survey, web, web_editor, web_tour, website, website_event,
website_forum, website_sale, website_slides, base

Historically, the web.assets_common bundle was used to contain assets
that were needed by both the frontend and the backend. In practice, this
caused a bunch of issues where people would add things in assets common
that were not needed by both, and it was also abused as a way to get
bootstrap working in unrelated places by only using that bundle's css.

Because of this, as a first step, the assets_common stop being used in
the frontend, but was left everywhere else.

This commit removes the bundle completely, and moves the files that used
to be in that bundle in the other bundles that need them, this will
allow those bundles to evolve independently going forward.

in im_livechat and mail, some of the unneeded legacy code was removed, this
allows us to avoind including all of the legacy code from web in the
livechat embed bundle and in the dicuss public bundle respectively.

closes odoo/odoo#132190

Related: odoo/enterprise#45884
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-08-24 15:11:05 +02:00
Samuel Degueldre 9210bbf5fb [IMP] web: improve time taken to parse owl templates
This commit removes some code that would allow one to define multiple
templates with the same name, and would cause the the last template with
a given name to override the previous one. This doesn't happen in
practice, nor should it, and the code that is used to allow it
repeatedly queries the document for a selector that is difficult to
process (selecting for elements with a specific attribute value,
especially when many elements in the document have that attribute).

A simple profile, with the crm and project apps installed, brings the
time that it takes to load the owl templates from ~200ms to ~35ms

closes odoo/odoo#132044

Signed-off-by: Francois Georis (fge) <fge@odoo.com>
2023-08-16 17:48:10 +02:00
Samuel Degueldre 627259e0da [IMP] web: update owl from 2.2.4 to 2.2.5
Release notes:
https://github.com/odoo/owl/releases

Commits:
[FIX] compiler: fix xmlns attribute not being set correctly in firefox
[FIX] compiler: fix t-call at root of template causing crashes
[REF] compiler: minor cleanup
[FIX] devtools: fix inspected path

closes odoo/odoo#131082

X-original-commit: ad9db912c45ebd49d9df87fbaee1f8b49421b081
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-08-07 20:59:06 +02:00
Samuel Degueldre c4b7d65e2e [FIX] web: stop leaking event listeners on EventBus in QUnit suite
In odoo/odoo#120893, the mail team changed their test utils so that they
would always start all services. This can cause issues because services
do not have any built-in destruction/cleanup mechanism, as in a
production application they are only supposed to be started once. Some
services add event listeners on global objects, in particular, the
tour service adds an event listener on the tour registry which is
global. If this event listener is not cleaned up, every time the tour
service is started, a reference to the environment in which this tour
service is being started is leaked. Since the environment contains all
started services, it is typically a pretty heavy object, especially
since in this context, all services are started instead of a select
subset.

This commit fixes that by patching the EventBus class to automatically
remove event listeners that were added on an event bus after the test,
in a similar fashion to what we do for some global objects like window
or the document's body.

closes odoo/odoo#130373

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-08-02 06:18:09 +02:00
Samuel Degueldre 8f68a146bf [IMP] web: check for undesirable module dependencies
Previously, we have accidentally made some core modules depend on some
modules outside of the core folder (eg views), this is undesirable as it
can make assets bundle hard to write using globs, and can make it easy
to introduce circular dependencies, it also doesn't make sense from a
code-organisation perspective.

This commit introduces a QUnit test that checks the modules in some
folders only depend on other whitelisted folders.

closes odoo/odoo#129982

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-07-31 20:54:01 +02:00
Samuel Degueldre 2d42501a5b [FIX] mail, web: fix memory leak in QUnit test suite
With the discuss refactoring, two memory leaks were introduced:
- the activity service opens a broadcast channel for cross-tab
communication.  Because services have no destruction mechanism, the
broadcast channel is never closed, and since most tests create their own
test environment with services, each test would leak an instance of the
activity service as it is captured by the bound onmessage function. The
activity service holds a reference to the mail store which results in a
large leak
- the RelativeTime component creates a timeout so that it can update its
time every minute or every hour depending on how old the message is,
this timeout is cleared when the component is destroyed. This component
tries to initialize the value of its timeout to `null`, but it does so
*after* calling the method that actually sets the timeout, causing the
timeout to be overriden with null and never cleared

The BroadcastChannel problem has been solved by adding BroadcastChannel
to the browser object, and patching it in the test setup code of web, as
it's a generic problem with BroadcastChannels. The timeout problem has
been fixed by simply reordering the lines so that we don't override the
timeout and it gets correctly cleared when the component is destroyed.

closes odoo/odoo#128768

X-original-commit: bd25f14d7a746fe48e09edea7ebb4aaa4634fbdc
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-07-17 19:26:05 +02:00
Samuel Degueldre 9d6f23c20b [FIX] web: avoid monokai ace editors leaking memory in qunit suite
When attempting to instantiate an ace editor with a given theme, ace
will first create the editor with the default theme (textmate) which is
always loaded, and register a callback to be called after the
non-default theme has been loaded. This callback holds a reference to
the editor's renderer which can itself retain large objects such as an
entire owl application. These callbacks are not cleared even if the
corresponding editor is destroyed.

Because in tests, the theme "monokai" was not included and ace cannot
load it on its own, all tests that attempt to create an ace editor with
that theme will leak memory. This commit fixes the issue by adding
theme-monokai to the qunit suite assets.

closes odoo/odoo#129813

X-original-commit: e8c77c5737c2170bb6b53d3e667aec7318dde5b8
Related: odoo/enterprise#44653
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-07-27 10:32:56 +02:00
Samuel Degueldre 34bdde7204 [IMP] web: add tests and comments for reactivity utils
The reactivity utils were initially an ad-hoc solution to some problems
that came up when using the reactivity in places that are not
components. As it turned out that these needs are actually quite common,
the utils that were originally duplicated in many modules were moved to
the core utils in web, but there were no tests for these utils, and the
Reactive class was not documented.

This commit adds some tests for the reactivity utils and a docstring
motivating the existence of the Reactive class.

closes odoo/odoo#125549

Signed-off-by: Géry Debongnie <ged@odoo.com>
2023-06-19 16:40:01 +02:00
Samuel Degueldre 81be42d8f9 [FIX] *: ensure tour tips are correctly translated
*: account, crm, crm_iap_mine, event, hr_expense, hr_holidays,
hr_recruitment, lunch, mail, mass_mailing, point_of_sale, project,
purchase, purchase_stock, sale, survey, web, website, website_blog,
website_event, website_forum, website_sale, website_slides,
test_main_flows

In odoo/odoo#111103 the tour system was rewritten. The previous tour
system used to depend on the `root.widget` js module, and this module
was an async module that indirectly depended on `session_bind` which
would load the translations, meaning that the js module definition code
of the tours would only run after the translations were loaded. This is
no longer the case with the new tour system, this means that the module
definition code is executed as soon as the dependencies of that module
are fulfilled, which is generally befoe the translations are loaded,
causing most tour tips to not be translated.

This commit adds a hacky workaround for this problem: it creates a new
module that has a default export which is a promise, and has a legacy
alias, this creates an async module that waits for the translations to
be loaded. This module is then imported for its side-effect in all
onboarding tours, causing them to be translated correctly once again.

This commit also needs to convert the steps key in the tours internal
registry to a getter. In previous versions, the steps were directly
added as is to the internal state of the tour service, but since
odoo/odoo#122834 the steps are now mapped, and without a getter, any
edits to the steps occurring after registration will not be taken into
account. This causes issues in some modules that change original
behaviour of other modules (eg accounting makes invoices into a menu in
the accounting app instead of a top-level app in the home menu) as they
need to edit the steps of existing tours to make them work.

In a separate PR, we will implement a more proper fix by changing the
API of the tour manager so that we no longer need this workaround.

closes odoo/odoo#125284

X-original-commit: d130699ba82dc9919c9116f4b64a5e461ebb6319
Related: odoo/enterprise#42655
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
2023-06-19 13:35:28 +02:00
Samuel Degueldre fcdd2acc5a [REF] pos*: namespace component templates, remove useless super calls
pos*: l10n_ae_pos, l10n_co_pos, l10n_fr_pos_cert, l10n_in_pos,
point_of_sale, pos_discount, pos_epson_printer, pos_hr, pos_loyalty,
pos_mercury, pos_restaurant, pos_sale, pos_sale_product_configurator,
pos_six

Previously, none of the templates of the pos were namespaced, this means
that depending on context, you have to access them differently: in xpath
the module prefix is necessary even if the template name itself isn't
namespace, but in owl components you cannot use the namespaced version
because owl doesn't have the notion of modules.

This commit namespaces the component templates of all the pos modules so
that it's consistent with the rest of the code base. It also removes
some extraneous calls to super.setup() that were leftover and are not
necessary for components extending directly owl's base Component.

closes odoo/odoo#124069

Related: odoo/enterprise#42094
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-06-08 14:32:34 +02:00
Samuel Degueldre cb2a53d573 [REF] point_of_sale, pos*: adapt import to moved files
pos*: l10n_co_pos, l10n_fr_pos_cert, l10n_gcc_pos, l10n_in_pos,
l10n_sa_pos, pos_adyen, pos_discount, pos_epson_printer, pos_hr,
pos_hr_restaurant, pos_loyalty, pos_mercury, pos_restaurant, pos_sale,
pos_sale_loyalty, pos_sale_product_configurator, pos_six, pos_stripe

The previous commit reorganizes the files in the pos, this commit
renames all of the imports of those files to match their new location.
This is done in a separate commit to allow git to better keep track of
the changes and apply forward-ports more seamlessly.

Part-of: odoo/odoo#123498
2023-06-05 17:51:06 +02:00
Samuel Degueldre 97bfa68dfb [MOV] point_of_sale: reorganize static/src folder for easier navigation
Previously, the pos followed the convention established in Odoo for a
very long time to organize its static source files, one folder for js,
one for css and one for xml. In a component-based workflow this makes it
hard to work with as the template of a component is very far in the file
tree from the component itself.

This commit adopts the new convention from the web module, and locates
the js and xml of components in the same folder. It also renames all
files to follow the convention of the rest of odoo that file names
should be snake_case. Some files had additionally been renamed to more
accurately reflect their purpose.

The imports and some renaming will be done in a following commit to
allow git to track changes to the files better.

Part-of: odoo/odoo#123498
2023-06-05 17:51:06 +02:00
Samuel Degueldre c7ce04a8ed [REF] point_of_sale, pos_hr: remove HeaderButton
The HeaderButton component is used once and is mostly presentational,
this commit inlines it into the navbar.

closes odoo/odoo#122035

Related: odoo/enterprise#41336
Signed-off-by: Monnom David (moda) <moda@odoo.com>
2023-05-24 14:27:59 +02:00
Samuel Degueldre 6f18cffb60 [REF] point_of_sale, pos*: remove BackendButton component
pos*: point_of_sale, pos_hr, pos_restaurant, pos_sale

This component is purely presentational and contains no code, it's also
only used once (it was actually used a second time in pos_hr only
because the way the xpath was written would replace the existing
instance with a new one with an added t-if, we can just use an attribute
xpath instead).

Existing xpaths have been adapted such that the burger menu's dropdown
structure is better semantically (an unordered list containing list
items, instead of containing list elements inside of random divs)

Part-of: odoo/odoo#122035
2023-05-24 14:27:59 +02:00
Samuel Degueldre ebe526241f [REF] point_of_sale, pos_restaurant, pos_sale: remove useless base class
The IndependentToOrderScreen base class is used when a main screen
should not be stored on the order (so that it can be restored when the
order is selected again). Its implementation is simply a class with a
static flag, and a super simple close method which just calls the
equivalent method on the pos store. It has been removed and the classes
extending it have been adapted.

Part-of: odoo/odoo#122035
2023-05-24 14:27:59 +02:00
Samuel Degueldre 190fefc9ca [REF] point_of_sale: remove MobileOrderWidget
It's a very short component with no oevrrides that contains almost no
logic and whose template is ~10 lines of code. It has been inlined into
the ProductScreen.

Part-of: odoo/odoo#122035
2023-05-24 14:27:58 +02:00
Samuel Degueldre 09db8c2775 [REF] point_of_sale, pos_sale: remove orderManagement context
Previously, the pos used singletons of reactive object to create shared
state between components that could be imported. This is an ugly
solution and this kind of "module level" object is difficult to patch or
mock during tests. It's also a non-standard way to manage shared state.

This commit simply adds this piece of shared state to the pos store,
which is meant to hold the shared state of the pos.

Part-of: odoo/odoo#122035
2023-05-24 14:27:58 +02:00
Samuel Degueldre d49476e0f8 [REF] pos_sale: remove unused mobile order management screen
The mobile order management screen has never worked. A previous commit
partially fixed it and caused it to now be rendered, but it's always
rendered in a way that makes it no different from the desktop order
management screen. The code has been dead for so long that allowing the
code to go through the dead path crashes and after fixing the crashes
the layout is broken. As such, this commit removes it entirely, and if
the flow needs improvement on mobile it will be done as part of a
separate task instead.

Part-of: odoo/odoo#122035
2023-05-24 14:27:58 +02:00
Samuel Degueldre cfcd25df39 [REF] point_of_sale: remove CurrencyAmount component
It's only used twice, in a single component, and it's used to do
different things, one of which is just handled by formatCurrency
already. It's been inlined to the only other use site.

Part-of: odoo/odoo#122035
2023-05-24 14:27:58 +02:00
Samuel Degueldre acbf806030 [FIX] point_of_sale: fix indeterministic order of payment methods
Previously, pos payment methods were ordered by sequence only, this can
cause issues because the default cash payment method is considered to be
the "first", ie the one with the lowest sequence, but because they are
created with a sequence of 0 by default, if there is more than one cash
payment method, their order is indeterminate.

This can cause issues if the order of payment methods given to the pos
application during load_pos_data doesn't match the order of the payment
methods obtained in get_closing_data, as tests will use the first cash
payment method when paying, and then compute the cash difference with
the default cash payment method which is supposed to be the first
received in load_pos_data. If the order is different then the cash
difference will not match what's expected and the test will randomly
fail.

This commit adds the id to the _order of the pos payment method model,
causing the ordering to be deterministic. It also removes the order from
the search params used for this model in load_pos_data, as it was
already the default ordering but was now masking the correct order newly
defined on the model.

closes odoo/odoo#121797

X-original-commit: b78c93a697baed3a01cac9319ccdc479d3bfd840
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-05-19 14:34:51 +02:00
Samuel Degueldre ba29387924 [REF] pos*, web: use reactivity to react to changes in UI size
pos*: point_of_sale, pos_restaurant, pos_sale

Previously the pos would rerender the entire UI when the window was
resized. In practice, most components do not care about the size of the
UI for their rendering, and so we're doing a lot of needless work, and
also using an owl feature (deep renders) whose perennity is not certain
(we may want to remove the ability to do deep renders completely in the
future).

This commit changes the pos code to use the ui service `isSmall` field,
makes the ui service reactive so that components can subscribe to
changes inside of it with `useState`, and makes the ui service update
its internal state at most once per animation frame, instead of after
100ms without resizing, so that resizing the viewport results in a
smoother user experience.

closes odoo/odoo#121343

Signed-off-by: adgu-odoo <adgu@odoo.com>
2023-05-15 13:59:22 +02:00
Samuel Degueldre 3fb24aa05e [REF] pos*: use fine grained reactivity instead of deep renders
*: l10n_ae_pos, l10n_co_pos, l10n_fr_pos_cert, l10n_gcc_pos,
l10n_in_pos, point_of_sale, pos_discount, pos_hr, pos_loyalty,
pos_mercury, pos_restaurant, pos_sale, pos_six

The code of the pos was one of the first adopters of owl 1, as such, the
code was not initially written to take full advantage of the owl
reactivity system that would eventually make its way into owl 2. In
order to convert the code quickly when migrating to owl 2, a big
shortcut was taken: whenever something in the state of the pos changed,
the entire UI would be rerendered. While this works decently well in
practice, it can create confusing situations because the mental model
needed to understand how components work in the pos is different from
the rest of the code base.

This commit changes the existing code to use the typical fine-grained
reactivity model used everywhere else: components individually subscribe
to the pieces of state that they use and will rerender on their own when
this state changes. In order to achieve this, the pos global state has
been removed from the environment and should now be access through the
use of the custom hook `usePos` which will subscribe the component to
the state that it reads. This also has some minor performance benefits
as we only render the parts of the UI that actually need to update
whenever there is a state mutation, instead of the entire UI which can
be expensive in some cases (eg, the product screen will filter all
products during rendering to find only the products that match the
search, which is expensive when there are a lot of loaded products)

closes odoo/odoo#120992

Related: odoo/enterprise#40873
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-05-12 19:54:57 +02:00
Samuel Degueldre 1f90799ff9 [IMP] point_of_sale, pos_loyalty: make pos tours run on mobile
The previous commit highlighted the fact that the pos is not really
tested on mobile. This commit creates a new class that extends the
TestUi class from point_of_sale, which runs most of the pos tours, and
runs all the same tours on mobile.

In order for these tours to run to completion correctly, a bunch of tour
utils have been adapted to add mobile-only steps or fork a step into two
mutually exclusive steps that run only on desktop or only on mobile. A
tour in pos_loyalty has been adapted to the change in the pricelist
selection utility function.

closes odoo/odoo#120791

Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-05-09 11:57:23 +02:00
Samuel Degueldre af2b9eab4c [FIX] pos_restaurant: stop crashing in mobile
In odoo/odoo#120070 the pos assets bundle were refactored to stop
including the entirety of assets_backend. In doing so, jQuery.ui is no
longer present in the bundle. pos_restaurant adds an addon for jQuery.ui
to make its widgets work on mobile, but since the original library is
not present, this causes a crash when touch events are available (ie on
touch screens).

This commit fixes that by removing the addon entirely, since none of the
pos depends on jQuery.ui anymore.

Part-of: odoo/odoo#120791
2023-05-09 11:57:23 +02:00
Samuel Degueldre c313f5912f [REF] *: stop using assets_backend in the pos
*: l10n_ae_pos, l10n_co_pos, l10n_fr_pos_cert, l10n_gcc_pos,
l10n_in_pos, l10n_sa_pos, point_of_sale, pos_adyen, pos_discount,
pos_epson_printer, pos_epson_printer_restaurant, pos_hr,
pos_hr_restaurant, pos_loyalty, pos_mercury, pos_restaurant,
pos_restaurant_adyen, pos_restaurant_stripe, pos_sale, pos_sale_loyalty,
pos_sale_product_configurator, pos_six, pos_stripe, web

Previously, the pos assets included almost the entirety of the
assets_backend. Most of the contents of the assets_backend is completely
useless in the PoS, meaning that the PoS will load slower because it
loads much more JS than it needs. It also means that it gets all the
side effects of this bundle (global event listeners, among other things)
that we don't want.

This commit removes the dependency of the pos assets on the
assets_backend to solve these issues. The pos assets are now their own
bundle with only what is needed in the PoS.

As for the unit testing bundle, the same logic applies but
unfortunately, because the unit testing code from web that we want to
use (eg automatic cleanups, cleaning of registries, etc) depends on the
legacy code, we need to include a lot more files than would otherwise be
needed. This situation will probably be improved as legacy code is
removed from web, but in the mean time, it is not very important for
this bundle to be lean, as it's a test bundle and loading speed is less
important.

Linked to: odoo/enterprise#40502

closes odoo/odoo#120070

Related: odoo/upgrade#4626
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-05-05 17:06:38 +02:00
Samuel Degueldre 7f8266c5e5 [REF] point_of_sale: stop using bus in PartnerListScreen
This bus will be removed in a future commit. Because busses are very
general purpose and add a layer of indirection through event
dispatching, they are a poor solution to cross component communication.
Generally, child to parent communication is done by calling callbacks
received as props, and parent to child communication is done by passing
props. In rare cases, a child wants to give finer control to the parent
component. In this commit, we replace the use of the bus by a pattern
similar to React's `useImperativeHandle`: the parent component passes an
object to the child component, which the child component then fills with
the imperative API it wants to expose.

Part-of: odoo/odoo#120070
2023-05-05 17:06:37 +02:00
Samuel Degueldre db4b11141d [REF] point_of_sale, web: factor report downloads out of action service
Previously, downloading reports was only possible by going through the
action service. In a few places, we want to download reports from the
PoS, but it doesn't make sense to load the action service and all its
dependencies in the PoS. In order to allow reports to be downloaded
without the action services, some functions are extracted out of the
action service itself and into report utils, which the action service
calls. These utils can now be used from the PoS without requiring the
action service and its dependencies be included in the PoS assets.

Part-of: odoo/odoo#120070
2023-05-05 17:06:37 +02:00
Samuel Degueldre d11bf24dea [REF] pos*, web: make pos service start asynchronously
*: point_of_sale, pos_hr, pos_restaurant

Previously, the pos service started synchronously, but doing anything
meaningful with it needed to be done after it was "ready", meaning it
had loaded and processed the data. The reason for this is that we need
to start the services before we mount the chrome, but in the pos we want
to show the loader immediately while the data is loading. This means
that any service that depends on the pos service in a meaningful manner
has to be written in a convoluted way, where it starts as a dummy
service and then overwrites itself in the env when it's actually ready.

This commit allows to write services that depend on the pos service more
naturally, by making the pos service properly asynchronous, meaning its
dependents will only be loaded once it's actually ready. To work around
the loader issue, the loader is mounted as a separate owl appplication
with not services, this application is shown over the chrome and when
the chrome mounts, it hides the loader and destroys the loader
application after the fade-out transition.

closes odoo/odoo#119908

Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-04-28 13:33:15 +02:00
Samuel Degueldre d270fbda24 [IMP] point_of_sale: introduce unit testing infrastructure code
Historically the point of sale hasn't had many unit tests as they are
difficult to write because the pos depends heavily on data. The
webclient also suffers from this problem and has created a lot of
infrastructure code that can be reused in the pos by simply implementing
a few routes in the mock server and loading the proper services during
the test. This commit adds a super basic test that just mounts the
chrome with mocked services and checks that it's there.

closes odoo/odoo#117290

Related: odoo/enterprise#39123
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-04-06 16:12:02 +02:00
Samuel Degueldre 8d35700aaf [REF] point_of_sale, pos_restaurant, *: stop using legacy environment
*: web

This commit removes the use of the legacy environment from the PoS, as
it is no longer needed. This will allow us to more easily use the new
unit testing infrastructure from web.

Part-of: odoo/odoo#117290
2023-04-06 16:12:02 +02:00
Samuel Degueldre 45d08db3c4 [REF] point_of_sale: move customer display logic to service
Previously, the customer display logic was split among multiple places:
the customer display button, the hardwareProxy service and the pos
global state. This commit extracts most of the logic to a new service
instead, and encapsulates the behaviour of a local display (popup
window) and a remote display (through an iot box) in separate classes.

Part-of: odoo/odoo#117290
2023-04-06 16:12:02 +02:00
Samuel Degueldre a838223a35 [REF] web: remove dependency of js module system on guardedCatch
guardedCatch is a legacy feature meant to differenciate promises
rejected as control flow from promises rejected because of an error. In
recent years we have settled on the stance that using promise
rejections, which are treated as errors by the language in many ways, is
a bad idea. This commit removes the dependency of the odoo module system
on this legacy feature.

closes odoo/odoo#117457

Signed-off-by: Géry Debongnie <ged@odoo.com>
2023-04-03 17:07:30 +02:00
Samuel Degueldre 25cbd9c4e7 [REF] point_of_sale, pos*: convert ProxyDevice to ES6 class and service
*: pos_epson_printer, pos_restaurant, pos_six

This commit continues the work of reducing the reliance of the pos
modules on legacy features from the JS framework, such as core.Class and
mixins, by converting the ProxyDevice class to ES6 (and renaming it
HardwareProxy, to avoid confusion with DeviceProxy from iot). It also
makes it available as a service in the new environment so that we can
hopefully get rid of the legacy environment in the near future.

closes odoo/odoo#114821

Related: odoo/enterprise#37991
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
2023-03-30 15:09:14 +02:00
Samuel Degueldre 38f463af32 [FIX] web: restore error dialogs for erroring js modules
In 64fc704527, we made it so that when an
async module throws an error, we catch the error and log it so that we
can mark the module as being in error. This means the error is now
invisible to the error service.

We do not want to rethrow the error, as this would stop us from loading
the rest of the modules, but we can still allow the error service to see
the error by simply dispatching it as a promise rejection in a separate
async call stack, allowing us to continue loading modules but also
giving the opportunity to the error service to see the error if it is
started.

Closes #92192

closes odoo/odoo#115230

X-original-commit: facc0f0c022df94487ef9518348f039b56c7b536
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-03-17 19:22:05 +01:00
Samuel Degueldre 54058db0ab [REF] point_of_sale, pos*: replace use of legacy rpc with orm service
*: l10n_co_pos, l10n_fr_pos_cert, point_of_sale, pos_loyalty,
pos_mercury, pos_restaurant, pos_sale, pos_sale_product_configurator

This is a step in the direction of making the pos no longer depend on
the legacy environment.

closes odoo/odoo#114668

Related: odoo/enterprise#37906
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-03-10 11:23:51 +01:00
Samuel Degueldre b795fe45f6 [FIX] point_of_sale: fix crash when closing session with draft orders
In odoo/odoo#112219 we removed the usage of useListener for
cross-component communication, one such use was to close the pos from
the closing popup. The closeSession method was moved from the closing
popup to the store but the corresponding error handling method wasnt. It
appears that the closeSession method doesn't need to be on the store at
all, only the closePos method. This commit moves the closeSession method
back to the closing popup, so that it has access to the
handleClosingError method again.

closes odoo/odoo#114127

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-03-02 16:01:22 +01:00
Samuel Degueldre 15bc39d3ef [FIX] pos_restaurant, *: allow selecting a table while offline
*: point_of sale, web

Previously, the error handling code was refactored and centralized, in
doing so, we broke the ability to select a table while offline: when
selecting a table we ask the server about the orders for the table. When
offline, this creates an error that was previously caught, and showed an
offline error popup, but continued the rest of the flow normally. The
refactoring centralized the display of offline errors to an error
handler, but removed the catching, causing the error to interrupt the
flow.

This commit fixes that by catching the error again, and when it's a
ConnectionLostError, it dispatched the error in a separate async call
stack (using Promise.reject) so that the display of offline errors is
still centralized, the the flow can continue normally.

closes odoo/odoo#114077

X-original-commit: f45f5e644b4b219b968fa19737d75cc710c823f3
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-03-02 11:23:42 +01:00
Samuel Degueldre 54c2ba1806 [FIX] pos_restaurant: fix crash when trying to pinch on touch screen
In odoo/odoo#112610 the draggable/resizable behaviour of the floor
screen was refactored, and in doing so the FloorScreen was converted to
a Component from a LegacyComponent. Doing so makes `this.el` unavailable
in the component but it was still using that for the pinch, causing a
crash.

This commit fixes that issue by using a ref instead of using
querySelector on this.el.

closes odoo/odoo#114058

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-03-02 00:27:53 +01:00
Samuel Degueldre 7d451e2200 [FIX] point_of_sale: fix crash when switching to pos in new tab
In odoo/odoo#112219 the closePos method was moved to the pos store, but
one call site was improperly adapted and tried to call the closePos
method on the Chrome component instead of on the pos store, this commit
fixes that.

closes odoo/odoo#114009

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-03-01 23:28:29 +01:00
Samuel Degueldre 1b1fd52148 [REF] point_of_sale, pos_restaurant: refactor draggable behaviour
Previously, the resize behaviour and the draggable behaviour were
completely separate, even though a lot of the logic for both behaviours
is common to both. This commit replaces both of these behaviours with a
hook: useMovable that lets the user drag an object around, but lets the
caller customize the behaviour on drag: when dragging a table or the
debug menu, we want to move the object around by setting its position in
its container, but when dragging a resize handle around, we want to
resize the table while keeping the handle position in the table the
same.

This commit also makes a bunch of popups non draggable as it doesn't
make sense for them to be draggable: you cannot interact with the
content behind the popup for as long as the popup is open (unlike the
debug menu), and serves no functional purpose, and may occasionally
confuse users.

closes odoo/odoo#112610

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-02-15 10:14:39 +01:00
Samuel Degueldre 621c8cf5fe [REF] pos_restaurant: rewrite resize logic for tables on floor screen
The previous code had a lot of repetition and made use of deprecated
features such as useListener. This commit refactors the resize logic by
creating a simple ResizeHandle component that encapsulates the drag
handle logic, it then communicates delta in x and y to the EditableTable
which applies it to the correct side and adds constraints on the
coordinates.

It also slightly improves the UX for round tables by also giving them
"corner" drag handles, which let you resize two dimensions at once
instead of just one, this also makes the code more uniform between the
table types, the only difference being where we position the drag
handles so that they're visible.

closes odoo/odoo#112430

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-02-13 11:29:55 +01:00
Samuel Degueldre 6d8ebdf829 [REF] point_of_sale, pos*: remove PosComponent
*: pos_discount, pos_hr, pos_loyalty, pos_restaurant, pos_sale, pos_six

Previously, all components in the pos and related apps would inherit
from the PosComponent base component, this component contained a bunch
of methods that were as such available on every component in the pos
passively. In previous commits, a bunch of these methods have been moved
either to the pos store or to their own services, so that component
dependencies are explicit instead of every component having a clobbered
namespace and having access to everything implictly.

This commit factors out the last method of the PosComponent,
`setSyncStatus` and as such the PosComponent is now empty and can be
removed completely, as can the Gui singleton utility which was used to
access these methods from outside of components.

Components in the pos modules now inherit from LegacyComponent which
PosComponent extended. The end goal is to remove the use of
LegacyComponent as well, but currently it is still needed as components
in the pos modules make extensive use of `useListener` which requires
the shim for `this.el` provided by LegacyComponent. This is nonetheless
a first step in that direction.

This commit also removes some components that were used in the navbar as
they were very small and it made more sense to just have the behaviour
they implement directly in the navbar component or elsewhere. Most of
the CashMoveButton was moved to the CashMovePopup, the TicketButton has
so little behaviour that moving that behaviour to the navbar itself
makes sense.

closes odoo/odoo#112295

Related: odoo/enterprise#36860
Signed-off-by: Heinz Robin (rhe) <rhe@odoo.com>
2023-02-09 18:07:23 +01:00
Samuel Degueldre 0d537e58a9 [REF] pos*: move show(Temp)Screen, make number_buffer and popup services
*: l10n_fr_pos_cert, point_of_sale, pos_discount, pos_hr,
pos_hr_restaurant, pos_loyalty, pos_mercury, pos_restaurant, pos_sale,
pos_sale_product_configurator, pos_six, pos_stripe

Continuing to move things out of the Chrome god component, this commit
does the following things:

 - moves the showScreen and showTempScreen methods and the corresponding
closing methods into the pos store so that components that need them can
access them through the pos service in a more explicit way. To that end,
these methods have been removed from PosComponent and Gui.

 - introduces a popup service instead of using a bus in the env, this is
mechanically very similar but closer to what's done in web and hopefully
a first step to using the dialog service instead. It also removes the
showPopup method from the PosComponent and Gui, to make components
depending on the popup service explicit.

 - makes the number buffer into a service instead of being a directly
imported singleton, which will enable it to be used with hooks instead
at a later point, and allows easier dependency injection in tests.

 - removes showNotification from the PosComponent and Gui, the
notification system was already converted to a service in a previous
commit for the same reasons as showPopup and the end goal is to use the
notification service from web to reduce duplication.

closes odoo/odoo#111844

Related: odoo/enterprise#36668
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-02-07 16:38:34 +01:00
Samuel Degueldre e57719733d [REF] point_of_sale, *: move things out of Chrome and store
*: pos_hr_restaurant, pos_restaurant

This commit continues the work of simplifying the Chrome component, it
moves the popup controller and the notification to their own component
and service, and moves the state of the notification, sound and debug
widget into their own services.

closes odoo/odoo#111553

Related: odoo/enterprise#36573
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-02-01 14:38:03 +01:00
Samuel Degueldre 207f15ba8b [FIX] point_of_sale: make pos usable when loading partners in background
Previously, when a database had a large amount of partners and they were
loading in the background, the PoS became progressively more slugglish
to the point of being unusable after ~10.000 partners were loaded and
for as long as all partners were not loaded. This was caused by the
client side database building a large string of text containing all
partner information to use for local searching of the partners. Any time
a batch of partner was loaded, this string would be reconstructed from
scratch, and this string would be around ~1MB by the time 10k partners
were loaded, causing a significant slowdown after every partner loading
request came back.

This commit fixes that by chunking the string by batch of 1000 partners
and only updating the string for the batches of the partners that were
just loaded, instead of updating the entire string, which brings brings
the performance of the PoS back into usable territory.

There were also some reactivity-related issues which have been fixed in
owl separately.

closes odoo/odoo#111388

X-original-commit: 4974782c61d7e283875da6ea40149072b1a36cdc
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-01-31 10:30:57 +01:00
Samuel Degueldre 7c3194ef73 [FIX] pos*: add missing arguments forwarding in _super calls
*: l10n_fr_pos_cert, l10n_gcc_pos, pos_hr, pos_loyalty, pos_mercury,
pos_restaurant, pos_restaurant_adyen

In odoo/odoo#109928 the custom inheritance system of the pos was removed
and a bunch of modules were adapted. In a lot of those places, the
_super calls didn't forward the arguments to the super method, resulting
in broken methods. This commits fixes that.

closes odoo/odoo#110962

Related: odoo/enterprise#36269
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-01-25 16:37:10 +01:00
Samuel Degueldre ef67615e97 [FIX] web: correctly destroy apps created for legacy MockServer
A recent change in owl exposes live (non-destroyed) apps on the window.
This change causes the memory used by the QUnit test suite to balloon
out of control. The reason is that when creating a mock environment, we
create a standaloneAdapter to serve as the legacy MockServer's parent,
but this standaloneAdapter creates a dummy owl application and this
application is never destroyed. This commit fixes the problem by
registering a cleanup to destroy the application at the end of the
running test.

closes odoo/odoo#110889

X-original-commit: 27ff522cd6b0c3be32be623e375052e63bb1a04f
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2023-01-25 08:18:04 +01:00
Samuel Degueldre ae1cd3d5bb [FIX] web: update jQuery to 3.6.3
This version of jQuery fixes a number of bugs in jQuery compared to
3.3.1

Some legacy list tests related to the handle widget have been skipped,
we consider this acceptable because:
- there are no remaining uses of the handle widget in a legacy list view
in the code base. The only remaining usage of the legacy list view is in
the SelectCreateDialog legacy, which is only used in our code base by
the very few legacy client actions that will be converted before v17
- the tests are only broken in enterprise, and the widget appears to
work fine in practice, suggesting a problem with the way tests drag and
drop rather than an actual problem with the code
- spending time to debug tests that will be obsolete within the next few
months and also appear to not correlate to an actual breakage of the
functionality is not worth it.

task-2291793

closes odoo/odoo#106960

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-01-23 16:01:21 +01:00
Samuel Degueldre 76a44b29f5 [FIX] web: improve performance in list views with date/datetime fields
When rendering the list view, we evaluate the evalContext for each field
so that we can give it infos such as readonly, required, invalid or
empty. In doing so, date and datetime feels are serialized and added to
the evalContext, but serializing dates can be slow, especially when not
using the default English locale. Internally, luxon checks whether the
locale is English which instantiates an Intl object which can be slow
and this is compounded by the fact that the method is called hundreds of
time in a single render.

This commit caches serialized dates and datetimes in a WeakMap, as the
luxon Date objects are immutable, this is safe, and because these
objects are not recreated often, it also eliminates a lot of the calls
to luxon's toFormat. In the quotation list view, this brings the render
time from ~1100ms to ~270ms. While this is still slow and further work
will be undertaken to make the evalContext lazy (so that only
date/datetimes which are actually used are serialized), it is a good
first step and brings the performance back to a level where the list
view is reasonably usable.

closes odoo/odoo#110103

X-original-commit: 64eeeef4d3d93a9b2753520e0067aa7996988d4c
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2023-01-17 12:58:59 +01:00
Samuel Degueldre b34429b984 [IMP] web, test_lint: forbid private class fields
We don't want private class fields to be used in Odoo because they limit
how classes can be patched from the outside, extensibility is one of
Odoo's biggest strength and we do not want to limit it.

This commit adds the `no-restricted-syntax` rule to eslint configs with
a rule that forbids private class fields.

closes odoo/odoo#109664

Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
2023-01-11 17:58:41 +01:00
Samuel Degueldre 4e31216c5d [FIX] point_of_sale, *: prevent block-header from blocking whole pos
*: pos_hr_restaurant, pos_restaurant

In #108891 the navbar was extracted out of the Chrome and into its own
components, but when a temp screen is shown, an overlay is placed over
the navbar to prevent the user from using it to navigate away as this
can break some flows, and the overlay was not moved inside the navbar.
This caused the overlay to go over the entire Chrome which was not the
goal.

This commit moves the block-header overlay into the navbar (and adapts
some code to make the tempScreen state accessible inside the navbar).

closes odoo/odoo#109456

Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-01-09 16:39:18 +01:00
Samuel Degueldre 86e2cc1167 [REF] point_of_sale: move DebugWidget out of Chrome
Continuing the work of making Chrome a less bloated component with no
clearly defined responsibilities, this commit extracts the DebugWidget
out of the Chrome component and registers it as a main component
instead.

closes odoo/odoo#108891

Related: odoo/enterprise#35406
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2023-01-05 14:32:48 +01:00
Samuel Degueldre ca7b48ea89 [REF] point_of_sale: get rid of useless util functions
The getFileAsText function can be replaced with the now well supported
Blob.text() function, the nextFrame function is used in precisely one
place and is needlessly complicated.

Part-of: odoo/odoo#108891
2023-01-05 14:32:48 +01:00
Samuel Degueldre 6a7459c1c0 [REF] point_of_sale, *: refactor error handling
Previously, the error handling was done inside of Chrome. This is
unecessary as none of the error handling code needs access to the Chrome
instance. Instead, this commit moves the error handling to standard
error handlers.

This commit also removes a bunch of ad-hoc error handling code that was
doing try/catch around some RPCs, only to catch the error that happens
when the client is offline. In a lot of those cases the code would
display any other type of error as an unknown error instead of letting
the error service do its job and in almost all cases the only difference
with the default handler is that the offline message was slightly
customized to tell the user more precisely which operation failed, which
doesn't seem necessary.

Part-of: odoo/odoo#108891
2023-01-05 14:32:48 +01:00
Samuel Degueldre 43529c8573 [REF] point_of_sale, *: extract navbar and remove ChromeAdapter
*: pos_hr, pos_restaurant, pos_six

The Chrome component a bloated "god component" that coordinates entirely
too many things which makes it hard to reason about, navigate, and
debug.

This commit extracts the navbar section of the chrome component into its
own component, and makes the sound player into its own self-contained
service.

This commit also merges the ChromeAdapter component into the Chrome
component, there is no reason for these to be two separate components.

Part-of: odoo/odoo#108891
2023-01-05 14:32:47 +01:00
Samuel Degueldre a5c0889748 [IMP] odoo,web: tests: ease memory leak debugging
This commit adds (in comments) the necessary code to (more) easily
detect memory leaks in the qunit test suite. Running the test with
those lines uncommented would log information about the heap size
after each test module and the delta of the module, after garbage
collecting.

Useful regexes to extract information from the log:
```
remove lines not containing "delta: ":
`(^.*?delta: .*$\n)|(^.*$\n)` => $1

extract deltas:
`.*suite (.*) -.*gc: (\d+).*delta: (-?\d+).*` => $1,$2,$3
```

closes odoo/odoo#108620

X-original-commit: 0d5cb1659468f01f1b6f88deca0b46c1810111b0
Related: odoo/enterprise#35224
Signed-off-by: Samuel Degueldre <sad@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-12-23 19:19:15 +01:00
Samuel Degueldre f7f16bd85d [FIX] web: correctly log full traceback for uncaught errors
Previously, we added some handling so that errors that were not
defaultPrevented would have their traceback logged by the error service
instead of the default behaviour of the browser, because not all
browsers correctly log error chains (errors with causes). This did not
actually work because the errorEvent was written on the object at the
top of the error chain and checked on the error at the bottom of it.

This commit fixes that by just looking at the event on the uncaught
error.

closes odoo/odoo#108463

X-original-commit: cefba026ad7fe453da840a948e25d29d4d1837e9
Signed-off-by: Géry Debongnie <ged@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-12-23 12:10:55 +01:00
Samuel Degueldre deacb8c94b [FIX] web: remove incorrect usage of patch in mock_env
Previously, when restoring service metadata after clearing it, we would
use the patch function instead of an Object.assign. This is probably a
relic of a previous version of the code that used patchWithCleanup, but
in this context it is completely wrong, as we are giving something other
than a string as the patch name and no object at all as the patch value.

closes odoo/odoo#108390

X-original-commit: b83ab5061fe15e69f6c0703baf6f1eec61332f0e
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-12-21 07:59:57 +01:00
Samuel DegueldreandAaron Bohy 78188249ca [FIX] bus, web: clean up event handlers and message ports correctly
This commit fixes two things:

- The owl compatibility layer adds an `on` and `off` method on owl's
EventBus so that it can keep being used as it used to in owl 1. To do
this, it needs to keep track of the the callbacks that are attached to
it and by whom. To do this it keeps a Map where the "owners" are keys.
When calling `off` to remove event listeners, we remove the callbacks
but did not remove the owner from the Map, causing the EventBus to
always hold a strong reference to any object that was given as the owner
to the `on` method, preventing the item from being garbage collected.
Objects that do this are typically components, and components hold a
reference to their owl application that contains the entire tree of
components. This was particularly problematic in tests where components
are created and destroyed at a rapid pace.

- The mock websocket creates a MessageChannel so that it can mock the
server side of the websocket, but it never closes that MessageChannel's
MessagePorts, which can cause garbage collection to be slow to happen
[1] (in practice it looks like these are basically never garbage
collected unless closed). This commit registers a cleanup to close the
message ports after the execution of the current test.

[1]: https://html.spec.whatwg.org/dev/web-messaging.html#ports-and-garbage-collection

closes odoo/odoo#108309

X-original-commit: 4facc396a4e8036592a473002253d5a5daf41a19
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
2022-12-19 16:49:06 +01:00
Samuel Degueldre 990b10aece [REF] point_of_sale, *: convert legacy modules to ES odoo modules
*: l10n_co_pos, l10n_fr_pos_cert, l10n_gcc_pos, l10n_in_pos,
l10n_sa_pos, pos_adyen, pos_discount, pos_epson_printer,
pos_epson_printer_restaurant, pos_hr, pos_loyalty, pos_mercury,
pos_restaurant, pos_restaurant_adyen, pos_restaurant_stripe, pos_sale,
pos_sale_product_configurator, pos_six, pos_stripe

We are about to refactor most of the Javasript code base of the point of
sale and related modules. In doing so, we will move a lot of files and
modernize the entire code-base. In order to avoid diffcult rebases,
their conversion to odoo-modules is done as a first step to avoid
getting lots of conflicts on files that were unindented, which marks the
entire file as being in conflict. Conflicts will occur during forward
ports but they will be easier to manage as the changes will be much
smaller in scope, and the author will have the context of the change
that causes the conflict in mind when dealing with it.

closes odoo/odoo#107621

Related: odoo/enterprise#34910
Signed-off-by: Trinh Jacky (trj) <trj@odoo.com>
2022-12-14 11:41:52 +01:00
Samuel Degueldre 2b33d2113e [FIX] web: make originalError the root of the error chain
Previously, when calling error handlers, we would give them a new error
created by the error service, as well as an `originalError` which is the
error that was caught by the error service. In some cases, this error is
part of an error chain, eg: errors that happen in the owl lifecycle are
wrapped in an `OwlError`, so that when an error occurs in a callback
passed to a lifecycle hook, the position where the hook was called to
register the offending callback is part of the stack trace.

In practice, most error handlers only care about the error that caused
the entire error chain (the root) when deciding whether they should
handle the error or not, eg: an RPCError should be handled by the rpc
error handler, regardless of whether it occured in an event handler or
in a component's willStart. It already reads the traceback to display on
the UncaughtError provided by the error service as this traceback
contains the entire error chain stack information and is annotated with
source maps by the error service.

This commit makes it so that the `originalError` passed to handlers is
now the root of the error chain, it also sets the `cause` of the
UncaughtError which is passed to handlers as the error that was caught
by the error service, so that if a handler needs to inspect the error
chain to know whether it can handle the error or not, it can still do
that.

related to OPW-3069633

closes odoo/odoo#106720

X-original-commit: dd6f103b1635868e03a7aa40eb7186861d22d377
Signed-off-by: Michaël Mattiello <mcm@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-11-28 18:51:47 +01:00
Samuel Degueldre a1e7e3ef7e [FIX] web, *: tours correctly break when there are missing deps
*: im_livechat, website_livechat, website_slides

In c989ff3, the odoo module system has been changed so that it now
errors out when modules are defined but have missing dependencies and
cannot run. Unfortunately, tours are defined in a single bundle,
`assets_tests`, and this bundle is used everywhere tours need to run,
but some of these tours depend on modules that only exist in the backend
and others on modules that only exist in the frontend. We don't want to
break up the `assets_tests` bundle as this creates a poor developer
experience, and so the solution that was chosen at the time is that when
the `assets_tests` bundle is defined, we ignore all module dependency
errors.

This causes a problem however, which is that if a module dependency is
missing in production code, the page will be broken by the module error
(which is expected) but if the `assets_tests` are present, which is the
case when running tours and tests, then it won't, meaning the tours will
happily pass despite the application being broken, which is
unacceptable.

This commit fixes this issue by replacing the assets_test bundle by a
new bundle (`__assets_tests_call__`) within which all module dependency
errors are ignored, which lets dependency errors that are hapenning in
other bundles (ie in production code) happen even during the tests.

Because of this, this commit also fixes the dependency errors that
already existed but were previously silent:

- for im_livechat and website_livechat, the code was refactored to use
the standard mechanism that we use elsewhere to add data directly in the
page: we store the data in __session_info__, and the module that exposes
that data is always present, instead of having a module that's defined
conditionally, which causes issues when non-conditional modules depend
on it.
- in web, the `report_assets_common` bundle was used alongside
`assets_common` but without `assets_frontend` or `assets_backend`.
Reports do not need any js and it appears that it already had what it
needed as far as css is concerned except for one fontawesome override.
Code was changed so that the js from the bundle is not included and it
reports no longer use `assets_common`, the js part of the bundle is no
longer used.
- in website_slides, the `slide_embed_assets` bundle is used alongside
`assets_common` without using `assets_frontend` or `assets_backend`
which is required for `assets_common` to function, the approach here was
to simply take the files from `assets_common` and remove the files that
were causing issues. This bundle should be trimmed at some point, as it
contains way too many things that it does not need.

The file colors.js was also moved to core, as it isn't graph specific
and was causing dependency issues with a field that was importing it.
Fields shouldn't depend on files in specific views' directory.

closes odoo/odoo#104794

Related: odoo/enterprise#33909
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-11-17 15:59:16 +01:00
Samuel Degueldre ba805c0582 [FIX] web: fix scss compilation errors being hidden by js module error
In c989ff339d, odoo module errors now
block the interface with an error message. Currenltly, in order to
support lazy-loading scenarios, the way that scss compilation errors are
displayed to the user is by attempting to import a module that may or
may not be present, and doing nothing when it's not present.

This commit fixes that by instead, writing the compilation error message
to a global variable, logging it in the console, and creating a service
that will display that error on start.

closes odoo/odoo#104671

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-11-07 09:12:04 +01:00
Samuel Degueldre c989ff339d [IMP] web: report module loading errors in the DOM
Previously, if there were module loading errors, they would typically
happen before the error service was ready, and so there is almost always
no user-facing error that shows up even though the application state may
be severely corrupted. This can be very confusing for developers who are
not used to working with JS and might not check the devtools console.

This commit makes it so that the module system will replace the contents
of the body with an error when some modules were unable to be loaded,
with the list of modules and the reason, so that the developer is not
confused as to why things aren't working as expected.

closes odoo/odoo#104155

Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-10-27 15:41:15 +02:00
Samuel Degueldre 94f81ed41d [FIX] base: fix sourcemap header offset
in b1d57adf6ff3 the size of the header added to source files while
concatenating them was reduced, but the corresponding offset use when
generating source maps was not adapted, causing source maps to drift
further and further from the actual source location the further in the
compiled asset the line is.

This commit fixes that by decrementing the header offset as needed.

closes odoo/odoo#102651

X-original-commit: 4d4585ee6c905c2a3adc4692098c1a3544417629
Signed-off-by: Géry Debongnie <ged@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-10-08 11:35:14 +02:00
Samuel Degueldre 6df381527f [FIX] web: align progressbar to the right of the field
closes odoo/odoo#102611

X-original-commit: fae1d7a3e22bb6d295ca7d0550d425a9b1af934e
Related: odoo/enterprise#32487
Signed-off-by: Adrien Dieudonné (adr) <adr@odoo.com>
2022-10-07 14:37:39 +02:00
Samuel Degueldre 3ca0c506ba [FIX] web: fix percentage pie field broken style
The percentage pie field was broken in enterprise, because the rules
that it needs are overwritten in enterprise but scoped to the legacy
version only.

This commit moves the community rules so that they always apply and are
not overwritten, it also removes an extra level of wrapper on the field.

X-original-commit: e3dfb1bbaa7aa2bf2bed62fb278e09c739503f4b
Part-of: odoo/odoo#102611
2022-10-07 14:37:38 +02:00
Samuel Degueldre 89013fa42a [PERF] mail, web: accelerate page loading by lazy-loading emoji data
Previously, the emoji data that is used in the emoji grid was part of
the main assets bundle. This file is almost 500kB and the data it needs
is only needed when opening the emoji grid. This commit moves this file
into its own bundle and only loads it when opening the emoji grid
instead.

This PR also batches the inserts in the emoji model, bringing the time
it takes to do those inserts from ~8000ms to ~800ms.

closes odoo/odoo#102562

X-original-commit: e272e4fc6abce3153cce3748d8a5a7df63565916
Related: odoo/enterprise#32468
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-10-07 13:37:11 +02:00
Samuel Degueldre f3f5e28fef [FIX] account, web: restore single line layout for order line in edition
When the section and note fields were converted, the section and note
text field ignored the list-specialisation of the text field, resulting
in a textarea with a minimum height of 50 in list view which causes the
line to be too high. It was also not using the o_field_text class which
among other things hides the resize handle on the text area which looks
weird in list view. This commit fixes that.

closes odoo/odoo#102465

X-original-commit: 5735f89245f8efa980069973b3dbe94beac59061
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-10-06 21:24:43 +02:00
Samuel Degueldre f45fc34110 [FIX] web: prevent scrollbar in form_nosheet
Previously, in form views without a sheet (eg in wizards), there would
be a scrollbar on the content. This is caused by the fact that
outer groups have gutters of size 5 in desktop which creates negative
margins on the row of 1.5rem which is 18px with the default size, but
the nosheet form view only has 16px of padding on the sides, causing the
groups to be 4 pixels too wide.

This commit fixes this by adding the correct padding classes on the
form view when it doesn't have a sheet.

closes odoo/odoo#102357

X-original-commit: 8d7bcc8eee7a333e8e463469177a1a86f9928254
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-10-06 17:00:15 +02:00
Samuel Degueldre 493a521466 [FIX] mail: restore chatter flex-grow to match attachment preview
Recently, the chatter was migrated to owl. When doing this, it lost its
flex-grow property, whereas the attachment preview has kept it, which
causes layout shift when moving from a record without an attachment
preview to another with one and vice versa. This commit fixes that.

closes odoo/odoo#102323

X-original-commit: 6228500a3f3cdb17286d50f2662f3e7b0226f667
Signed-off-by: Géry Debongnie <ged@odoo.com>
2022-10-06 13:06:02 +02:00
Samuel Degueldre 211ee645fa [FIX] web: fix checkbox taking up more vertical space in some contexts
It was missing the bootstrap form-check class

closes odoo/odoo#102321

X-original-commit: 4218a3ed6022032577c2764deefa7923db32cf89
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-10-06 13:05:59 +02:00
Samuel Degueldre 9c59d9a4a0 [FIX] web: support <widget> in list new view
When converting the list view to owl, the support for view widgets was
overlooked as this feature is not used very extensively and was not
tested.

This commit adds support for them and adds a test for it.

closes odoo/odoo#102193

X-original-commit: 9098c1d3cd4af8f324b5b09668e92822575f932d
Signed-off-by: Géry Debongnie <ged@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-10-06 10:42:40 +02:00
Samuel Degueldre 01aaca36b7 [FIX] web: log source of QUnit test failures in info instead of error
This allows easier parsing of the logs for indeterministic errors, so
that when the same error happens in different build, it has the same
error message, as the stack trace contains the file name of the assets
which get generated with a different hash every time, while also
preserving the existence of potentially useful tracebacks to debug
indeterministic issues.

closes odoo/odoo#100028

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2022-09-12 17:33:48 +02:00