Commit Graph
62 Commits
Author SHA1 Message Date
Guillaume (gdi) be90d8abae [IMP] test_website: add a test of multi websites settings
In the website settings, one of the fields allows you to switch settings
from one website to another. Unfortunately, as soon as the user did this
the record was considered to have changed (dirty) and therefore required
a save when it wasn't necessary. The previous commit prevents the header
settings (like the website switcher) from dirtying the record. This was
really necessary because as soon as a user had several websites, it was
impossible for him to access certain settings on all these websites
(except the first one). As soon as the setting performed an action, a
save was required (because the record was dirty) and the user was
redirected to the settings again.
Steps to reproduce the issue before the previous commit:

Install website
Have multiple websites
Go to Settings > Website Settings
Change the website
=> The user is notified that the record has changed and needs to be
saved, which is not true. So far it's annoying but not critical, but if
the user continues:

Activate the "Extra step during checkout" option
Click on "Configure Form"
=> The Save/Discard dialog appears because the record is dirty.

Click on "Save"
=> The user is redirected to the settings page again and cannot access
the form configuration of the second website. (it is the same issue for
most of actions).

The previous commit fixes the issue and this commit adds a test to
ensure that the users are able to change settings of multiple websites.

task-3265100

closes odoo/odoo#126387

X-original-commit: bed37396839891da04126a71b3d6a6e5e56672b0
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
2023-06-26 22:15:17 +02:00
Jeremy Kersten 939b61822e [IMP] http_routing: server_redirect in case of 404
It is a tradeoff since we will add extra requests in case of 404 to
check if a redirect exists. But it will allow to redirect old unlinked
record to a new record.

Until now, if you delete e.g. a product instead to archive it, you have
no way to redirect old url to the new product.

closes odoo/odoo#125828

X-original-commit: 95dd21c4d69a06b56b908e138f7746ef3d131d82
Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
2023-06-21 01:24:20 +02:00
Romain Derie 37cdff405e [IMP] website, test_website: strengthen the perf testing suite
This commit ensure the expected tables are accessed when a page (not
only) is requested.

This is needed because without that, we can only check the query count
number which might be broken without being noticed:
- Commit 1 reduce queries by 2 (no need to access table X anymore)
- Commit 2 later reduce queries by 2 (less access on a table) but
  without noticing it, it also now introduce back the access of table X.

At the end the query count is still fine, but the code is not: it broke
a previous improvement while it was not necessary.

Worst, it could even lower the query count despite still breaking a
previous improvement (-3 queries +2 queries back).

Also, since the query count of a page is not exactly the same inside a
test and in real use cases, an `EXTRA_REQUEST` param is used in those
tests to abstract that change and still use the "real use case" query
count in the test to fit the reality, be human readable and easier to
write/debug.
Indeed, in test mode there is more queries due to the test cursor
rollback and savepoint, but there is one less query (the cache one).

Some commit wrongly reduced that `EXTRA_REQUEST` param making it looks
like there was an improvement while there wasn't.

This commit will help preventing all of that, ensuring the correct
tables are accessed and only those, on top of checking the query count
number (we still need to check the query count in case there is a query
not catched in the SQL table logs).

Some of the PRs/commits where it happened:
- https://github.com/odoo/odoo/commit/aa1c1b0bcb5327894c7b00d0454eebae06eaa005
- https://github.com/odoo/odoo/pull/112000/files#r1160851862

closes odoo/odoo#124939

X-original-commit: 26e1fc3abd54a1baa16cf1c99d75d501a8dc6906
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-06-15 18:51:18 +02:00
Xavier-Do ca8dc2d9b4 [IMP] base, website: small refactoring
Mainly to simplify website overrides and general api

closes odoo/odoo#121376

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2023-06-10 11:14:12 +02:00
Xavier-Do 6d5d234f15 [IMP] base: better ormcache management
1. move cache to _get_asset_paths

The `_get_asset_content` cache has many cache key that are related to a
posprocessing of the `_get_asset_paths` result, the heavy part of this
method. Moving the cache to _get_asset_content will have the benefit
to create less duplicates entries in the ormcache as well as less cache
miss.

To simplify even further, the css and js parameters are removed since
they only filter the output of get_paths, the heavy part of globing the
file will be done before that. Anyway, they are both true when called
from _get_asset_content, and the only other call, in
`_get_related_bundle` don't really need to filter them since it is not
a critical part regarding performance, and the funtional result will
stay the same.

The initial orm cache key was using `_get_template_cache_keys`, a little
overkill and possibly creating duplicates entries again. The only
context key needed is website_id for `_get_related_assets`.

Note that it is not really enough, the orm cache key should actually
contain `request.session.get('force_website_id')` as well has
`request.httprequest.host`. This will be addressed latter since a nicer
solution would be to have website_id as a unique parameter computed
earlier.

2. better _get_asset_paths cache key

The orm cache key was simplified in previous point but there is still
one concern, the website_id depends on more parameters than that:
- request.session.get('force_website_id')
- request.httprequest.host
- existing websites

The idea here is to call `get_current_website` instead of using all
parameters that could define the webiste.

In the same spirit of `_get_template_cache_keys` `_assets_path_params`
can be overriden to give extra params that are usefull to list assets
path. Those params are computed before entering the method
`_get_asset_paths`. This may latter put at a higher level latter, in
get_asset_node, to simplify the _generate_asset_nodes_cache key.

3. better assets_node caches key

The main purpose of this part is to improve ormcache containing assets
nodes. The ormcache key contains
- to much context key
- missing session/host/env info
- unwanted boolean options.
- keys leading to the same cache value

The main goal being to reduce the size of the cache keys, decrease the
number of cache entries and improve the cache hit.
This will also make the behaviour more coherent and hopefully less bug
prone because of mismatch in parameters.

The main reason of the orm cache is the slowness of the validation of
the assets. This includes:
- listing files (dedicated orm cache)
- computing version

The cache key was depending on
- `debug`
The only relevant value for debug is "contains assets"
We dont need to differ between debug='', debug='1', debug='test',
and 'debug=assets', 'debug=tests,assets', ...
- `defer_load`, `lazy_load`, `media`
Those values are only useful to generate html node, a leightweight
operations that does not really needs to be in cache. `media` was also
used in the generation but it looks useless if we have the media on the
node. THIS NEEDS TO BE VALIDATED but in any case, since media is not
used to generate the url, it doesn't make sence to use it in the
generation.
The main idea to remove them from the ormcache key is simply to generate
the nodes outide the ormcached values.
-`async_load`
This one is similar to `defer_load` and `lazy_load` but it looks like
it wasn't used anymore. This was simply removed
- context.get('lang')
The only information needed is the direction, rtl or ltr. This means
en and fr languages, despite sharing the same css assets, will duplicate
the ormcache entries.
-`_get_template_cache_keys`
Only the lang and webiste where really relevant in this flow. Other
keys are actually useless in this flow.

Some information used in the generation where not in the orm cache key
- `self.env.user.lang` if there is no lang in the context
- `request.session.get('force_website_id')`
- `request.httprequest.host`
- ...

The proposed solution is to:
- extract any informùation needed from thecontext, request, environment
before entering the ormcache, reduce it to the minimal possible set of
values needed
```
    rtl = self.env['res.lang']._lang_get_direction(self.env.context.get('lang') or self.env.user.lang) == 'rtl'
    assets_params = self.env['ir.asset']._get_assets_params()  # website_id
    debug_assets = debug and 'assets' in debug
```

and remove a leightweight part of the logic

```
    def _get_asset_nodes(self, bundle, css=True, js=True, debug=False, defer_load=False, lazy_load=False, media=None):
        links = self._get_asset_links(bundle, css=css, js=js, debug=debug)
        return self._links_to_nodes(links, defer_load=defer_load, lazy_load=lazy_load, media=media)
```

Where _get_asset_links is the cached part, and _links_to_nodes is the
lightweight part generating the nodes based on the `defer_load`, ....

Additionnal notes:
- data-asset-version and data-asset-bundle are removed from the node
since they don't seem to be used anymore since 65d70acdbf
- async_load is removed since there is no occurence of this in the code.
- a small hack is still needed to pass javascript content instead of
links, this is only to manage css compile error and will hopefully be
removed in the future.
- a context key is still in use to generate the bundle, the
`commit_assetsbundle` but it has no impact on content and will hopefully
be removed in the future.

4. Add test for ormcache hit/miss

In this context, hit/miss is about having the same cache key for the
same result. This test demonstrates the current state, were entries are
create in the ormcache only if the key is really different and will lead
to a different result.

5. remove cache invalidation

This cache invalidation is quite agressive since everytime an
assetbundle is updated, all workers will clear their cache.

The concerned cache by this clear_cache is `_generate_asset_nodes_cache`
throug `_get_asset_nodes`.

The cache is ignored, both in dev=xml and debug=assets.

This clear cache was made conditionnal in 553ea82f81 but this does
not solve an issue we can have in production.

Lets imagine a clean solution
- all sources are updated
- all workers are restarted.

The orm caches are all empty, but since the sources
changed, all bundles will be recomputed. This means that every bundle
updated in database with save_attachement will invalidate the cache of
all workers. Rendering a pdf report of any kind using a specific bundle
will invalidate all cache. Starting a debug=assets for the first time
will invalidate all cache, even if the cache is not used in this case.

But for a regenerated bundle we would expect the ormcache to be:
- empty (did not generate the same bundle yet)
- have the same value (concurrent generation of the same bundle)

Having a different value would mean that the bundle was generated with
another version of the sources. In this case it is maybe even better not
to invalidate the cache since it could lead to an invalidation war
between two workers.

The only case where invalidating this cache is useful is when a bundle
changes, Usually if an ir_asset is created, modified, ...

There is still another rare but possible possibility to have a 404 if
the transaction is rollbacked after populating the assets node cache.
In this case, we only need to clear the cache locally in case of
rollback.

Part-of: odoo/odoo#121376
2023-06-10 11:14:11 +02:00
Xavier-Do 5594d8f191 [IMP] base, *: speedup assets unique computation
One of the most costly part of a page loading when the ormcache is cold
is computing the assets node, the unique identifier of an attachment to
validate whether the existing attachment is still valid with the current
version of the static files.

This operation needs to glob assets path in the filesystem,
get the modification date, check attachments, ...

Right now this task is not really optimized and can take some time
because of an excessive number of glob on the filesystem, unnecessary
exists to define absolute path, double computation of file list and
modified times when getting js and css bundle separately, ...

A list of modifications mainly discussed in the pr message are made
with this commit to speedup things.

- split css and js unique
- prepare api for an in memory glob
- change api to propagate absolute path and meta information through
`ir.asset._get_paths`-> _get_asset_paths -> `_get_asset_content` ->
`AssetsBundle`

closes odoo/odoo#121159

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2023-05-17 14:47:12 +02:00
Géry Debongnie 44052d58d7 [FIX] web,base: do not display js module errors in some cases
Since saas 16.1, we added a more visible error information box when the
module system cannot find some dependencies, or if there is an error in
the JS code. This error box is very useful to understand a lot of
typical devlopment issues.  However, it was occasionally displayed in
production code.

However, we sometimes observe that the error information box was
displayed, because the request to load an assets failed with a 404.

It is unclear in which circumstance this can happen, but it seems that
the following elements are involved:

- the user has an open tab with odoo, kept open for a while
- some js code is changed on the server, which causes the previous
assets to be deleted
- the user reload its open tabs, so the browser will load the /web page
from disk, which points to the old assets files
- then it will try to load all assets, with a 404 on one of the script
- the error information box is displayed

This commit intercepts the loading error and stop displaying the error
information box, which is basically the same behaviour as 16.0 and
before. We could force a reload in that case, but it seems dangerous,
since in case of errors, it could easily lead to an infinite loop.

closes odoo/odoo#117625

X-original-commit: 0a44b5b1e008b591a716efd26217c7db7360c37b
Signed-off-by: Géry Debongnie <ged@odoo.com>
2023-04-04 16:02:12 +02:00
Yolann Sabaux afe6f967cd [FIX] base: make country code required
Steps to reproduce:
- Go to Contact-Configuration-Countries
- Remove the code of a country
- Create a new contact
- Select the country from which you deleted the code
- Put any vat number starting with country code you deleted

Issue:
Traceback

Cause:
in `_run_vat_test` we want to `country.code.lower()` -> country code does not exist

Solution:
Prevent the user to delete a country code by making the field required.

sentry-3923412146

closes odoo/odoo#113207

Signed-off-by: William André (wan) <wan@odoo.com>
2023-03-07 11:11:42 +01:00
Jeremy Kersten 2f992e6cd1 [IMP] website, test_website, website_sale: allow to find partial url
Until now, if you search for /shop/Desk for a new link, you will not
have any result.
Now we search that it match *shop*desk* so /shop/custom-desk-12 will
match.

closes odoo/odoo#114357

X-original-commit: 84a407e744b7bacab43a0213ab52002a49c5d623
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2023-03-07 02:00:03 +01:00
Christophe Monniez 442c776cb6 [FIX] test_website: remove base_url from assertions
Since Werkzeug 2.1.0, the Response.autocorrect_location_header is
disabled by default.

As it's RFC compliant and supported by browsers, the base_url is simply
removed from the assertions.

Part-of: odoo/odoo#112298
2023-02-10 14:37:30 +01:00
Denis Ledoux 5bf1207c8c [IMP] base, *: re-use env during registry loading
The goal of this revision is to re-use the environment among the
different steps of the registry loading,
instead of creating a new environment for each step.

1. Simply To avoid to repeat the line
   `env = api.Environment(cr, SUPERUSER_ID, {})`
   multiple times in the code
2. This also allows to share the context among the different
   steps. This is not yet used in this revision, but it could
   be, for instance to avoid the current repetition to add the keys
   `install_module`, in `convert_csv_import` and `xml_import._tag_record`

Part-of: odoo/odoo#108254
2023-02-01 10:25:01 +01:00
Benoit Socias 45f63ca044 [MOV] website, test_website: move test using data file to test_website
When the QWeb `<template>` loading test was introduced at [1], the
`test_website` module did not exist yet, see [2].

This commit moves that test and its related data file to `test_website`
to remove the `fake data` noise from the `website` module.
That's one of the two purpose of this `test_website` module:
- Avoid noising the website module with test only data & code
- Encapsulate in a lighter module the module operations tests, but it's
  not really the case anymore as those tests are now standalone tests.

See manifest for more details.

[1]: https://github.com/odoo/odoo/commit/9cd982bcc811cacb42f5c08db139043d2734b891
[2]: https://github.com/odoo/odoo/commit/ef03db9edd9472201cb2c08a32d20ff0f33a5fdf

closes odoo/odoo#109349

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-01-20 20:58:12 +01:00
Romain Derie ebfa84d8e3 [FIX] test_website: add test for duplicate sitemap URL fix
See previous commit, it fixes duplicate URLs from sitemap.
It appears when there is a custom defined sitemap method on a route
defined with multiple endpoints.
There will be as many duplicates as there is endpoint.

closes odoo/odoo#108670

X-original-commit: 9ca24c3020d98dcd6e9266ae76adb13afbf1bd40
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2023-01-02 09:54:12 +01:00
Romain Derie a6bf6cf44d [FIX] website, test_website: prevent fuzzy search to crash with inherits
This commit ensures that when searching on a `inherits` field of
a model (like `name` of `website.page`), it works properly when
`pg_trgm` is activated.
Indeed, `name` is a field of `website.page` record but only at the ORM
level, not in SQL, due to how `inherits` works.

So, when the `pg_trgm` extension is enabled, it will switch from ORM
queries to raw SQL query (to use the native SQL similarity feature and
not our custom python/orm one, as obviously the SQL one is better, more
powerfull/accurate and faster).
But this will actually make the code fail when searching on fields from
a model which has `inherits` and that you search on that `inherits`
model fields.

Note that in 15.2, the `pg_trgm` extension is auto installed when
possible thanks to [1] and [2].

[1]: https://github.com/odoo/odoo/commit/eedf37d6e286b995c47b946be1a6b66817094eff
[2]: https://github.com/odoo/odoo/commit/75e6b645acdc95aece506ce0249fd0760838281c

opw-3063592

closes odoo/odoo#107178

X-original-commit: 3d978caad9de2010603581687ee39a5240b74074
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-12-04 23:41:55 +01:00
Julien Castiaux 1219f043fe [FIX] http_routing: should redirect only for multilang
Define a route that is website but not multilang, e.g.

    @route('/example', website=True, multilang=False)

Login to the frontend, change the website lang to another (non-default)
lang (e.g. install french, keep english as default lang, log in the
french website) then access the '/example' controller by typing it
directly in your address bar.

You are being redirected to '/fr/example', you should not.

This commit restore the behavior pre-httpocalypse, that is the address
is kept as-is.

Note: in the comment, the 4th and 5th cases were inverted, we use this
commit as an opportunity to reorder the two.

closes odoo/odoo#105686

X-original-commit: be7a02917a66136a8d3b601d61a898b0419ff79d
Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-11-14 17:17:59 +01:00
Chong Wang (cwg) f8c2b02abe [FIX] *: adapt code to jsonb translations
Website: the context install_filename='dummy' is used to prevent
arch_updated from becoming True while updating translations of
ir_ui_view.arch_db (if arch_update becomes True, test_inherit_specific
fails)

Fuzzy search for jsonb translated fields has been adapted in the case of
website.  It may require some refactoring later.
2022-09-15 22:37:50 +02:00
Romain Derie 9c733d8c22 [IMP] website: allow controller as homepage
Before this commit, only a website.page could be used as a custom
homepage ('custom' meaning other than '/').

But it is a real use case and requirement for our users to be able to
select a controller as homepage.
For instance, an ecommerce would want its homepage to be the shop and
not a regular page from where you then have to navigate to the shop.

Right now, this can (almost) be achieved by doing some technical
advanced operations:
- Move the 'Shop' menu first in the menu navbar of the website
- Delete the specific '/' website.page for the website
- Delete the generic '/' website.page (no website_id)

That way, the system will redirect `/` to `/shop`, which is not ideal as
it should remain `/` in the URL.

That's because, until now, the homepage (`/` controller) serve order
was:
- Serve the website.page set as homepage (`website.homepage_id`),
  happens when one did select another page as homepage through the page
  properties dialog
- Serve the website.page having `/` as URL (default)
- Serve the first accessible menu if there no `/` page or other page set
  as homepage, it acts as a last resort attempt to not serve a 404 and
  to try serving relevant content (the first menu of a website is most
  likely always better than a 404)
- Serve 404

This commit allows to introduce an URL as homepage, instead of only a
website.page. It can be done through the website settings in the
backend.

There is 2 main points to keep in mind about serving the homepage:
- make sure we don't serve a 404 as the website homepage. This is the
  website entry point, serving a 404 is terrible. That's why we have
  some fallback mechanism like serving the first menu.
- We need to serve / before fallbacking to the first menu, as a lot of
  site just remove the 'Home' first menu since it is a duplicate of the
  logo, which also redirect to the homepage. In such cases, it doesn't
  mean that the user want his first menu to be the homepage. We
  shouldn't rely on such a behavior, it should just be used as a last
  resort.

With this commit, the homepage serve order is now:
- If homepage URL is set (empty by default), serve the website.page
  matching it
- If homepage URL is set (empty by default), serve the controller
  matching it
- If homepage URL is not set, serve the `/` website.page
- Serve the first accessible menu as last resort. It should be relevant
  content, at least better than a 404
- Serve 404

Most DBs will just have a website.page with '/' as URL and keep the
homepage_url setting empty.

task-2969683

closes odoo/odoo#99100

Related: odoo/upgrade#3876
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-09-09 00:56:54 +02:00
Benoit Socias 375f4dff1c [FIX] web_editor, *: clean previously shown link in link popover
*: web_tour, test_website

Since [1] when the link popover was introduced, when the URL of a link
was made empty, an validation error appeared by the previously shown URL
did still appear inside the popover.

After this commit the previously shown link is replaced by a message
that indicates that no URL is specified.
The telephone and envelope icons are now also always removed when the
URL is change: they used to be only toggled, which made it possible to
make them appear and disappear by updating an email address or a phone
number.

Steps to reproduce:
- Add an image-text snippet to the page
- Select the image
- Add a link on the image
- Specify URL
- Click on image => link popup shows the entered URL
- Make the URL field empty
- Click on image
=> link popup still showed the previously entered URL

[1]: https://github.com/odoo/odoo/commit/8fcf930a6b6b7ffb0965b0a689c7a3117962ce7e

task-2765857

closes odoo/odoo#98845

X-original-commit: f212c56d73f5dad8eb5850b0b39cc92f55706ee2
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
2022-08-25 12:05:29 +02:00
Rémy Voet (ryv) 6e1bb5ca3e [FIX] test_website: fix test when trigram psql extention is installed.
When we want to activate trigram psql extension for odoo/odoo#97294
on runbot. But one test fails (`test_01_many_records`) with it because
the website fuzzy search behavior depends on trigram extension presence.

closes odoo/odoo#98018

X-original-commit: 0562a17f8ca1be83c80372e2300e24ab9d0458a9
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-08-12 08:53:59 +02:00
Benoit Socias 6179adb555 [FIX] website, test_website: fallback on exact search if max reached
For performance reasons, when fuzzy search was introduces it was
decided to limit the number of records used for finding fuzzy terms to
1000.  Because of this, when a database contains more than 1000
products matching words that start with the same letter, further
products are not examined. This can lead to searches not finding an
existing exact match.

This commit introduces a fallback mechanism so that, if we are in a
situation where the maximum number of examined records was fetched, we
also explicitly check for a possible exact match across all records.

Steps to reproduce:
- Do not install the pg_trgm extension.
- Have more than 1000 products containing searchable words (name,
description...) starting with the same letter.
- Add one more such product (so that it is not in the 1000 first ones).
- Search for that last product by correctly typing the word.
=> Exact match was not returned.

task-2870947

closes odoo/odoo#97657

X-original-commit: 6d24ea28b236155d542e3d2be3da379b9f4e9ce6
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-08-08 23:45:53 +02:00
Benoit Socias d7707a4a88 [FIX] web_editor, test_website: hide previously computed image size
Since [1] the file size is displayed only for images that support
processing (filter effect, crop, resize...) but when switching to an
image that does not support it, the old size remains displayed.

After this commit when an image for which the file size is not computed
is selected, the previous file size is hidden.

Steps to reproduce:
- drop a Text-Image snippet
- select the image => the size is displayed in the options block title
- replace the image with an animated gif
=> previous size did remain displayed (now size is not shown anymore)

[1]: https://github.com/odoo/odoo/commit/089ae3d28b5d2d7bdbaad133174ae54240113181

task-2729177

X-original-commit: 378f67749a51d8c0b9fb65767faceaa0844916e5
Part-of: odoo/odoo#95963
2022-07-15 14:21:57 +02:00
Gorash b3a3969b2e [FIX] website, *: href form link alternate depends on the current url
*: test_website

Issue: The url is cached and no longer depends on the url. This part
should not be cached.

closes odoo/odoo#95222

X-original-commit: 4b255ed129b0e458d3cf7f432d076913b14d5450
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-07-06 17:10:17 +02:00
99b50d18e2 [REF] test_website, *: adapt tours to new client action
*: website, website_blog, website_crm, website_event, website_forum,
   website_hr_recruitment, website_mass_mailing, website_sale,
   website_sale_loyalty, website_slides

This commit adds the current website displayed view xmlid outside of the
iframe, on its container, so that the tours registered with
registerThemeHomepageTour can continue to prepend their triggers with
the view xml id.

Introduce registerEditionTour: this function will allow tour maker to
more easily register a tour that needs to start in the iframe's backend
and go in edit mode.

See merge commit for more information.

task-2687506

Co-authored-by: Benjamin Vray <bvr@odoo.com>
Co-authored-by: Younn Olivier <yol@odoo.com>
2022-06-24 10:28:07 +02:00
Younn Olivier 9df44ecade [FIX] test_website, web_editor: adapt tests to new dialog
See merge commit for more information.

task-2687506
2022-06-24 10:28:06 +02:00
Julien CastiauxandRomain Derie fd5c6a861c [FIX] http_routing: missing 301/302 on access err
Install website and website_hr_recruitment, open /web with ?debug=1, go
to website > configuration > redirect, create a temporary (302)
redirection from `/jobs/detail/experienced-developer-4` to `/404`. Open
the `/jobs/detail/experienced-developer-4` as admin and unpublish the
page. Open the same URL via private browsing (so that you are not
connected), you get the default 403 - Forbidden page, you were not
redirected to the 404 - Not Found page.

Custom 301 (permanent) and 302 (temporary) redirections are fallback
redirections when the requested page does not exist or is not accessible
to the current user. The HTTPocalypse broke the later case, it was not
checking for existing redirection upon access error.

The use case is the one supported with [1] where people want/need to
display something better than a 403 when they unpublish a record like a
job position for instance (most of the requested cases on opw).
Indeed:
- People have link to that record/job everywhere on the internet
- The job position / record is no more relevant, and people need to
  unpublish it
- People don't want to delete it (or can't sometimes due to record
  relations)
- People don't want visitors to land on a 403, mainly because it is a
  non customizable advanced/technical page (it displays a technical
  message including the record name etc)
- Their need is to either land a their customizable friendly 404 or
  sometimes on another record to promote it.

[1]: https://github.com/odoo/odoo/commit/3b9cd536607b1631dd375ab2e5cc94eb814a6e9b

closes odoo/odoo#93981

X-original-commit: eb7eecec976570ae3301c17a04adc9c110d5b14a
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Julien Castiaux <juc@odoo.com>
Co-authored-by: Romain Derie <rde@odoo.com>
2022-06-18 00:50:34 +02:00
Romain Derie 5acddcd304 [IMP] website, test_website: new standalone tags to ease runbot configs
As we have more and more standalone tests related to the website app, it
has been decided with the runbot team to introduce a unique tag to
easily identify those tests.

The goal is to make the runbot build config easier to manage, without
the need to add the new tag name in the command.
Instead, this build will be fired by finding and testing all the
`website_standalone` tests.
The other tags are kept to easily identify what are the test related to.

Command without this (which need to be edited for each new tag):
```
--standalone cow_views,cow_views_inherit,theme_views,theme_upgrade
```
Now:
```
--standalone website_standalone
```

X-original-commit: a28c181b7f934bed06adccd2678d6c6db47422fe
Part-of: odoo/odoo#93109
2022-06-08 16:50:56 +02:00
Romain Derie 5a8d6c351b [IMP] website, test_website: avoid a query on res_company_user_rel
Manual forward port, commit was lost from 15.2 to master. Either it
seemed not needed after the httpocalypse refactoring, or was simply
lost during the rebase.

-----

We can remove an useless SQL Query for public user on every single page
serve, if we directly set the website's company_id in the available
company_ids of the public user.

Indeed, the public user from a website always have the same company_id
as the website.

We can then do that directly and bypass the next line which will
always be true in the case of the public user, making a read for
nothing.

task-2774979

closes #85419

X-original-commit: c95ab6f

[1]: https://github.com/odoo/odoo/commit/728ade674cb12c64718efda56b0d5d542e319cba

closes odoo/odoo#87856

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-04-06 19:32:44 +02:00
Romain Derie aa1c1b0bcb [FIX] website, *: correct wrong query count after httpocalypse
*: test_website, website_blog (test perfs)

An error regarding tests was not catch during httpocalypse [1] review.
The test query counts were lowered in website by 2 everywhere, but it
shouldn't have as there were no SQL perf improvement from this
refactoring regarding website.
The query count actually decreased because the test-only SQL Savepoints
got divided by 2, probably thanks to a low level test improvement in
the PR.
But outside of tests, there were no SQL Query gained.
This should have been reflected in the `EXTRA_REQUEST` variable
instead.

Before:
Savepoint > Rollback > Savepoint > [Actual SQL Queries] > Rollback
After:
Savepoint > [Actual SQL Queries] > Rollback

It is important to fix it because:
1. (Minor) There is a de-sync between the query count in the test and
   the actual query count (in the logs outside of tests), making it
   hard to figure.
2. (Major) Some controller got then wrongly lowered to 0 query counts
   instead of 2. An incoming PR in master would then make those tests
   expects negative query counts, which doesn't make any sense.

[1]: https://github.com/odoo/odoo/pull/78857
Note that the exact commit can't be found by bisect as those don't work
on their own, DB can't be started due to circular import.

Part-of: odoo/odoo#87856
2022-04-06 19:32:44 +02:00
Martin Trigaux f41ec39abe [IMP] base: get_view_id becomes private
Add new helper get_view
Remove dangerous documented comment

Part-of: odoo/odoo#85110
2022-03-29 10:56:16 +02:00
Romain Derie b0285d0e88 [IMP] website, test_website: add tests for broken flows in httpocalypse
Some flows were broken in httpocalypse, sadly those were not tested.

X-original-commit: 6161987c94544162de16eb2544295d152f123d17
Part-of: odoo/odoo#85340
2022-02-28 13:53:08 +00:00
Romain Derie dad8dca0da [IMP] website, website_blog, *: also test perf of real use cases
* test_website

The `nocache` URL param was introduced with [1] which allows to bypass
the cache when serving a page.
Bypassing that cache, despite not being the most common flow, was done
in the perf tests since that commit. Ultimately, it was not testing
real use cases anymore (despite still being useful as it would still
prevent perf killer feature to be merged).

This commit ensures the perf tests are also tested with cache.

[1]: https://github.com/odoo/odoo/commit/cbf8d3b3047c94a2ff7fb197bbae92a402e0b58b

task-2774979

closes odoo/odoo#85261

X-original-commit: 5d44d890021cfc7767daa1f366e636288e84f1f6
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-02-24 17:49:56 +00:00
Julien Castiaux c0647b5c52 [REF] core: HTTPocalypse (14) changes all addons
This commit is the 14th commit of a comprehensive refactor of our HTTP
framework. See odoo/odoo#78857 for complete historic, discussions and
rationnals.

* `request.uid = x` => `request.update_env(user=x)`.
* `request.context = x` => `request.update_env(context=x)`.
* `request.context = dict(request.context, x=y)`
   => `request.update_context(x=y)`.
* `request.cr = None` => `request.cr.close()`.
* `http.mono_db()` => `request.db`.
* `http.dispatch_rpc()` => `service.dispatch_rpc()`.
* `@service.model.check` => `service.model.retrying()`.
* `request.endpoint`
   => `env['ir.http']._match(request.httprequest.path)[0].endpoint`.
* `request.routing_iteration `=> `removed`.
* `request.jsonrequest` => `request.dispatcher.jsonrequest`.

Note that `request.params` is now set much later in the process. If you
are in a situation where you values from the query string or the
http body you can use `request.get_http_params()`.

Note that using the new `request.future_response`, it is possible to
add headers and cookies on the response object before the response
object is initialized. Please note that headers/cookies saved on
the future response will NOT be injected in case of error.

PR: odoo#78857
Task: 2571224
2022-02-24 13:30:51 +00:00
Julien Castiaux 3d7f49b2f5 [IMP] *: Don't override HttpCase.base_url() in tests
HttpCase.base_url() was introduced with ded278b9c2 but many tests were
using the name attribute already. The tests have been adapted to use the
new method.

closes odoo/odoo#82910

Signed-off-by: Julien Castiaux <juc@odoo.com>
2022-01-17 16:56:01 +00:00
Romain Derie 90f411ea03 [FIX] (test_)website: fix standalone tour
Use theme_default instead of theme_common.
Instead, theme_common is not available when only website is installed as it
depends of the design-themes repository.

closes odoo/odoo#82587

X-original-commit: a10522c6509caf7f09f21e6da3224d5865f0ba6a
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-01-12 11:19:04 +00:00
Romain Derie adcf0c277a [FIX] test_website: add test for 308 redirect and qs
With a 308 redirection from `/url` to `/new_url`:
Links like `/url?a=a` should be rewritten to `/new_url?a=a` and not
`/new_url?a=a&a=a`.

closes odoo/odoo#82099

X-original-commit: bae72fd70c4d3682bff9e148cac1408ca5603b76
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2022-01-04 10:26:16 +00:00
Romain Derie 90a9dce222 [FIX] base, (test_)website: remove the copy_ids orphan leftover
Before this commit, if a theme record (eg `theme.ir.ui.view`) was deleted,
its copy_ids would not be.
While this is perfectly normal and wanted behavior when this is done in a
website context (to not alter other websites), it shouldn't be the case when
performing a theme update through CLI/Migration (or if the user find a way to
update the module through the UI).

Fixes https://github.com/odoo/upgrade/pull/3048
task-2593407
opw-2680866
opw-2685951
opw-2685124
opw-2679040

closes odoo/odoo#81953

X-original-commit: 3146dd72e6cb07d6e78ca763325f13dd54de0086
Related: odoo/design-themes#548
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2021-12-28 11:47:05 +00:00
Romain Derie 6dd7207b6f [FIX] web_editor, web_unsplash, test_website: make unsplash work
Since cfe079221c, unsplash is not working anymore as that commit did not adapt
the unsplash code to that change.

task-2581567

closes odoo/odoo#76617

X-original-commit: 9a4723628e868836c7bbe8bec31ec9b6ce3f2554
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2021-09-16 10:01:14 +00:00
Gorash 5913b7265e [REF] base,*: refactor Qweb engine
* Remove AST in favor of pure Pyhon. This should make it easier for
developers to understand and create new directives because they do not
need to know AST.

* Remove `t-call-options` as it has been merged into `t-options` for more
consistency. Support for t-call-options is retained.

* Use generators for lists. This increases performances as the rendering
can be sent directly without having to wait for the creation of the
entire list.

* Optimize expressions runtime computation by pre-computing the static
parts.
Example:
'<' + 'div' + '>' + '<' + dynamic_value + '>'
Now compiles as:
'<div><' + dynamic_value + '>'
2021-08-03 15:37:54 +00:00
Romain Derie d6d83a0142 [IMP] test_website: add tests for image upload progress bar
Progress bar on image upload was introduced with #65828 in saas-14.3.

Since, it has been broken in saas-14.3 with 3765ac1 which broke the flow for
image unrecognized by PIL, see the other commit of this PR.

It was also completely broken in master (saas-14.5) with the wowl refactoring,
where no progress bar were shown at all. It would show empty toastr.
This was fixed with #74027

This commit introduces a complete testing suite for that progress bar:
  - Single image upload
  - Multi image upload
  - Success upload
  - Unsupported error
  - Unrecognized error

task-2607393
Closes #74122

closes odoo/odoo#74454

X-original-commit: 381d432faf8d19e71ff1d63c29a14064a6d7f57f
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2021-08-02 13:57:41 +00:00
Romain Derie 7ea3a73c18 [FIX] website: use correct url code to get canonical url
Before this commit, we would compare a lang `code` (used in context) and a lang
`url_code`. For languages where those 2 are differents, the `if` condition
would always be falsy, making the canonical URL impossible to be reached.

Technically, this condition is used to get the translated name of records to
later construct the canonical URL.

Since the canonical URL will be incorrect and unreachable, the whole system to
tell search engine/crawler about translation won't work since no
`alternate/hreflang`[1] will be set in the DOM.

[1] see https://developers.google.com/search/docs/advanced/crawling/localized-versions

--------

Technical explanation:
- italian language `code` = `it_IT`, `url_code` = `it`
- belgian french language `code` = `fr_BE`, `url_code` = `fr_BE`
Install those languages on website as secondary languages.
Translate blog `Travel` to `Voyager` in french and `Viaggi` in italian.
Visiting `/fr_BE/blog/travel-1/post/post-1` will redirect to
`/fr_BE/blog/voyager-1/post/post-1` as it should, and the canonical URL will be
set to that same URL.
Visiting `/it/blog/travel-1/post/post-1` will redirect to
`/it/blog/voyager-1/post/post-1` as it should, but the canonical URL will be
set to `/it/blog/travel-1/post/post-1`.

opw-2486918

closes odoo/odoo#69918

X-original-commit: 733411fe03b924832d6b10cadf93c8fc09cc5802
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
2021-04-27 12:14:38 +00:00
Jeremy Kersten"Romain Derie <rde@odoo.com>""Jeremy Kersten <jke@odoo.com>"
10d7477043 [FIX] test_website: add tests for website.rewrite
Basic tests & tests of the 3 fixes of #64328

Be sure that we have a beautiful error page and not a black/white error
Be sure that slug_matching with 308 redirect works as expected and don't
raise a RequestUID exception.

closes odoo/odoo#64889

X-original-commit: 3af11f0b6db0efb6c912b25bcd04d2cbe9a07d57
Co-authored-by: "Romain Derie <rde@odoo.com>"
Co-authored-by: "Jeremy Kersten <jke@odoo.com>"
2021-02-01 14:51:20 +00:00
Benoit Socias 28f0853a2d [FIX] web_editor, test_website: will fix the deletion of custom snippets
This commit is a manual forward port of #62555. The tour test needed to
be adapted because the navigation flow is slightly different: upon
custom snippet creation, the editor page used to be saved and reloaded
in 14.0 but this is not the case anymore.

Before this commit the deletion of custom snippets failed because the
button click event got intercepted by the drag'n'drop mechanism.
The currentTarget of the event was used in an asynchronous call where it
had already been replaced by the jQuery's event bubbling mechanism when
invoking the other handler.

After this commit the deletion of custom snippets works again and a test
tour is introduced to make sure it does not get broken again

task-2405854

closes odoo/odoo#63108

X-original-commit: 4de0519d5b54634604e22b32d91a099695378088
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2020-12-10 08:28:14 +00:00
Adrian Torres ca91e13dee [IMP] testing: forbid module operations during testing
With this commit, module operations such as install, upgrades and
uninstalls are henceforth forbidden inside unit tests and instead such
tests must be performed with standalone Odoo scripts.

This is done because module operations during tests are not
transactional, this can leave the registry in an unclean state and
further tests may be affected by this, it also creates a new registry
which complicates registry cleanup if anything crashes,
because the registry to be cleaned up is not the same one that crashed.

Instead, what should be done is a script that imports odoo as a library,
and loads the database necessary then performs whichever operations
necessary. This script should contain a single function with a single
parameter (env) and should be decorated with
@odoo.tests.common.standalone in order to be executed properly, this
decorator accepts any amount of positional parameters as tags that can
be specified when calling the script in order to execute only a select
subset of scripts.

Special tags are: 'all' and <module_name>, these are generated
automatically, the first will execute ALL scripts available whereas
<module_name> will execute all scripts introduced by said module.

When calling the test_module_operations script, only scripts found in
*installed* modules will be executed, script discovery is only possible
if the code is loaded therefore it is only possible if the module is
installed.

closes odoo/odoo#49669

Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2020-04-22 07:45:53 +00:00
Raphael Collet 962412c309 [FIX] test_website: upgrading inside a test is really not a good idea
Because: (1) the upgrade starts by committing the current cursor; then
(2) the upgrade instanciates a new registry to use for the database; and
(3) the test cleanup involves setting up the old registry, which creates
a new environment referring to the new registry!

The points (2) and (3) makes the field setup crash when it relies on
data stored on the registry itself: the field in the old registry tries
to set up with data stored on the old registry.

closes odoo/odoo#48920

X-original-commit: f5e5aba9e203b42b661cc3b503fd37051ec20f93
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-02 23:54:32 +00:00
Jeremy KerstenandRomain Derie 6d6b505598 [IMP] website: perf - add cache for website frequent fields
The dispatching layer of Odoo (common to any call) can avoid a query on website
if those 3 values are cached.
Note that for complex business flows, there won't be any gain since website
infos will have to be fetched at some point.

About user_id:
In most cases, for a website page you will need to browse the website btw so
we don't remove this request previously. But in case of a simple image, the
controller /web/content need the public user just to set the request.uid in
auth_public but no other info from website.

With this commit, we don't do the 'select * from website where id in()'
request on each controller declared in auth='public' but use the user_id
from the cache. (Invalidated by the write on website_id)

task-2211013

Co-authored-by: Jérémy Kersten <jke@odoo.com>
Co-authored-by: Romain Derie <rde@odoo.com>
2020-03-26 18:12:50 +00:00
Romain Derie af68fcde48 [IMP] website: clean and add perf tests
- Refactor for easier readability
  - Add a test to ensure menu hierarchy scale correctly.
  - Add tests for image controllers
  - Add test for assets controllers

task-2211013
2020-03-26 18:12:47 +00:00
Jeremy Kersten dc77f67cad [FIX] website: match get/post in is_multilang_url
Old heuristic is not more True:
Force to check method to POST. Odoo uses methods : ['POST'] and ['GET', 'POST']

We have some controller that only allow 'GET' method, so we need to check GET
also when we try to know if an url is multilang or not.

This commit fix case where a controller '/test' only allow GET and you were in
another language that the default, in this case, the rendered url in qweb was
/get instead of /<lang>/get.

Closes #37223

closes odoo/odoo#40519

X-original-commit: c7650106f8588083be12812600a6c94ba703fd6f
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-11-26 14:35:46 +00:00
Yannick Tivisse 02bb326a6e [IMP] test_website: Adapt tests to work with/without demo data 2019-11-05 16:18:10 +01:00
Jeremy Kersten 3a7033463e [FIX] website: allow authenticate in json multidb
Before this commit launch a server with --db-filter that match at least 2 dbs name
Try to authenticate

You will have an error request is unbound when you try to access request.env

Now we retrieve the user from self instead of the request.

New test to ensure rpc authentication is tested.

Related to commit 245ef4b1

closes odoo/odoo#38969

X-original-commit: 4b3400c430bec7539aada0619fd203978daca2d8
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2019-10-17 15:35:11 +00:00
Christophe Simonis d74b451805 [MERGE] forward port branch 13.0 up to f4105eb9c7 2019-10-09 02:08:17 +02:00