Commit Graph
159 Commits
Author SHA1 Message Date
Fabien Pinckaers 14b24c338a [IMP] remove _read_template cache as it's already cached by _compile
closes odoo/odoo#81921

Signed-off-by: Fabien Pinckaers <fp@odoo.com>
2021-12-27 10:25:23 +00:00
Xavier Morel 74241b3766 [FIX] test_lint: support fstrings in sql injection checker
Those were not accounted for, leading to fstrings passing through
unflagged.

Also update the SQL checker to be stricter but smarter:

The previous version would "fail open", unknown nodes would be allowed
through hence f-strings not being flagged when they started appearing
in arg0 position, should now fail-closed, anything that's not allowed
is forbidden.

This flags a few more cases, all of which seem acceptable upon review.

However the previous version would also only resolve arg0 (in case it
had a `NAME`, to see if that resolved to an acceptable form of
query-building). The new version performs resolution during
`_check_concatenation` and should thus allow e.g. format strings to be
separate variables (though not e.g. module-level constants, yet
anyway).

In resolution, replace the ad-hoc process by astroid's built-in
`lookup` which seems to provide the same information. Slightly more in
fact, as it yields every assignment in case of e.g. conditionals, but
making use of that would require a lot more changes in the checker so
leaving the behaviour as-is for now.

It's important to *not* use `ilookup` here, because ilookup is not
"iterable" but "inferring", and we don't want values, we want
expression ASTs for analysis.

NOTE: previous improvements as well as fixes to existing code were
only implemented in 14.0, hence this being merged in 14.0 not 13.0
despite 13.0 still being supported.

closes odoo/odoo#81721

X-original-commit: 376ccf0944dae1bc53ae9c5385977c4e6b23e083
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2021-12-27 09:36:42 +00:00
Antoine Guenet aceb086854 [FIX] base, web_editor, mail, digest: preserve comments in sent e-mails
For email design in the context of Microsoft Outlook, we want to keep
some magic Microsoft comments (Outlook conditional comment), which -
until this commit - were skipped by QWeb. These allow us to change the
rendering exclusively for Outlook so as to overcome some of its
limitations. This commit introduces a qweb rendering option
(`preserve_comments`) for when - like in mass mailing and digest - we
want to keep comments.

Part-of: odoo/odoo#80621
2021-12-08 09:35:03 +00:00
Raphael Collet ea72b1ff32 [FIX] base: warnings with context key 'validation_views'
The context key 'validation_views' is used by ir.ui.view to determine
what parts of a view arch must be validated.  Its associated value is
either True or a recordset, and having those types leads to unexpected
warnings when creating environments.

Before creating a new environment, the class Environment looks for an
existing environment with the given parameters: cr, uid, context, su.
The comparison of a context where 'validation_views' is a recordset with
another context where 'validation_views' is True, generates the warning
"unsupported operand type(s)"...

We avoid this situation by using ids instead of a recordset for the
value of the validation context key.

closes odoo/odoo#77747

X-original-commit: 210cd625a052a4d3c230a93bcba644c9a31e67ab
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-10-04 20:23:51 +00:00
Xavier Morel 5408eeda24 [FIX] base: correctly check for validity of button icons
The icon would only be checked for buttons with neither `@special` nor
`@type` which is... pretty much none of them?

Part-of: odoo/odoo#76581
2021-09-15 15:22:58 +00:00
Xavier Morel 78d1b9591c [IMP] core: _validate_fa_class_accessibility cleanups
* add t-out to set of text-generation attributes
* fix comment location
* don't handroll `iterancestors()`
* only check the `@string` on the toplevel button, doesn't really make
  sense that a button would contain a button in the first place (in
  fact it's not allowed per the HTML spec, a button can only contain
  *non-interactive phrasing content* cf 4.10.6)

Part-of: odoo/odoo#76581
2021-09-15 15:22:57 +00:00
Raphael Collet 0d1908e644 [IMP] base: do partial validation of views
Here is the idea: when creating a view V that inherits another view, and
V only adds elements in the parent view, only the elements added by V
must be validated.  The other elements are not modified, and thus do not
need to be validated again.  However partial validation cannot be done
when modifying an existing view, or when the view replaces elements in
the parent view.  In such cases, the method _check_xml() validates the
whole combined architecture.

The time spent in method _check_xml() to install a database from scratch
with module sale_management went from 2.730s to 2.243s (-18%), and the
number of queries made in the method went from 2283 to 1614 (-29%).

closes odoo/odoo#75796

Related: odoo/enterprise#20633
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-09-06 15:47:03 +00:00
Raphael Collet c70c97b127 [IMP] base: refactor NameManager in views
Also speed up view validation by not calling fields_get when possible.
This avoids a call that is usually not necessary for validating a view.
Most of the time, fields can be found on the model itself.  Only
overridden fields_get() with fake fields are actually useful, like the
one of model 'res.users'.

The time spent in method _check_xml() to install a database from scratch with
module sale_management went from 3.510s to 2.730s (-22%), and the number
of queries made in the method went from 2995 to 2283 (-24%).

Part-of: odoo/odoo#75796
2021-09-06 15:47:03 +00:00
Raphael Collet eda3352cdd [IMP] base: refactor domain methods in view validation
The goal is to avoid calls to obscure methods, and make the code more
understandable.

Part-of: odoo/odoo#75796
2021-09-06 15:47:02 +00:00
Raphael Collet 5fad7a55dc [IMP] base: simplify view validation
Besides simple code improvements, remove node_info['attr_model'], and
check domain on specific elements.  Also refactor _validate_attrs.  The
changes have no impact on performance.

Part-of: odoo/odoo#75796
2021-09-06 15:47:02 +00:00
Raphael Collet 46f1912c9b [REF] base: split view validation from postprocessing
This makes it easier to optimize the algorithms for both cases:
postprocessing without validation, and validation without
postprocessing.  Also factor out some common bits like the editability
of nodes.

The net result is a speedup in performance.  The time spent in method
_check_xml() to install a database from scratch with module
sale_management went from 4.955s to 3.578s (-28%), and the number of
queries made in the method went from 3779 to 2995 (-21%).

Part-of: odoo/odoo#75796
2021-09-06 15:47:02 +00:00
Raphael Collet 331b54770e [REF] base: merge view methods _postprocess_view and postprocess, and simplify
This replaces recursive calls by a stack, which makes profiling
flamegraphs much simpler to analyze.

Part-of: odoo/odoo#75796
2021-09-06 15:47:01 +00:00
Raphael Collet 9ae8c1a7c9 [REF] base: split method handle_view_error() into _raise_view_error() and _log_view_warning()
This improves code readability but does not impact performance.

Part-of: odoo/odoo#75796
2021-09-06 15:47:01 +00:00
Raphael Collet 1de6c4e55a [IMP] base: extra optimization for safe_eval() in views
This generalizes an existing optimization and saves a few time to
validate a view.  The time spent in method _check_xml() to install a
database from scratch with module sale_management went from 5.145s to
5.044s (-2%).

Part-of: odoo/odoo#75796
2021-09-06 15:47:00 +00:00
Martin Trigaux c7bac3dee0 [IMP] *: make ir.model.data helper private
No reason to interfact with them directly in RPC
2021-08-10 13:49:04 +02:00
Benoit Socias 6f34f85c66 [FIX] base: remove branding on t-out nodes
Before this commit branding was removed only from nodes using t-esc and
t-raw.
This caused problems such as the ribbon preview rendering being
propagated across all products because the oe-model/id/xpath fields were
referencing the product card view itself.
This appeared because of the conversion from t-esc/t-raw to t-out.
The branding used to be removed from nodes using t-esc and t-raw, but it
was not removed for t-out.

After this commit the branding is also removed from nodes using t-out.
This restores the old way the ribbon preview was rendered, and therefore
also fixes the issue described in the related task.

task-2527056

closes odoo/odoo#74145

X-original-commit: 9e83dd83a39b542ec0e0d3045bcffcf24406c94b
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2021-07-23 09:12:51 +00:00
Jeremy Kersten 1dccc0bc81 [FIX] base: avoid crash due to generation of key with model
Until now, when you create a view of type qweb with a model, we use the model
as first part to generate the key. Since this model can contains dot, it is
wrong and we got some key like ir.ui.view.gen_key_xyz

This bug has been seen with commit ee8756b311
which make the installation of website & sale_timesheet impossible in dev mode.

  File /home/odoo/addons/base/models/ir_ui_view.py, line 294, in _compute_arch
    arch_fs = get_view_arch_from_file(fullpath, xml_id)
  File /home/odoo/addons/base/models/ir_ui_view.py, line 166, in get_view_arch_from_file
    module, view_id = xmlid.split('.')

  Too many values to unpack

Now we never try to make key beautiful. At first view it doesn't bring any
advantage, but only bug.

closes odoo/odoo#72238

Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
2021-06-16 14:08:08 +00:00
Raphael Collet b840d33946 [FIX] base: translations of field labels in views
The commit e123aa2f30 optimizes the call
to fields_get() made in the NameManager to post-process the combined
arch of a view.  The optimization consists in avoiding translations,
with the assumption that the result is only used for validations.  It
turns out that the regular post-processing actually returns the field
descriptions as part of the result of fields_view_get().

We fix this mistake by keeping the optimization only when the flag
'validate' is true, so that the regular post-processing of a view
returns field descriptions with the expected translations.

closes odoo/odoo#72216

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-06-16 09:25:11 +00:00
Raphael Collet 7fca29b443 [FIX] base: useless view validations when validate=False
When a view is created/modified, it is required to validate it, the
validation checks the syntax, the inheritances, the fields, etc. When a
view is rendered there are a few more steps to perform like to (dis)able
the `edit` button from a view form if the user only have `read`
accesses. Those postprocess are useless when the view is validated and
should only be performed when the view is rendered.

closes odoo/odoo#68469

Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2021-06-15 08:44:03 +00:00
Raphael Collet 4f22ae270a [FIX] base: compute view.xml_id only when needed
This is a pure technical fix, computing `view.xml_id` is only needed
when there is a problem with the view.  Computing the `xml_id` is not
free, as it needs to be retrieved from the database.  During a regular
installation, there should be no problem, the view is validated without
errors or warnings.
2021-06-15 08:44:03 +00:00
Raphael Collet ee8756b311 [IMP] base: bypass _inverse_arch() in view creation
By default, whatever is written on field 'arch' is handled by its
inverse method inverse_arch(), which writes on the low-level field
'arch_db'.  When writing on 'arch_db', the cache is cleared, which leads
to performance loss because the arch needs to be re-fetched.

This optimization bypasses the inverse method on view creation, this is
safe as there is nothing wrong in the cache and makes view creation 20%
faster, and installation 7% faster.
2021-06-15 08:44:03 +00:00
Julien Castiaux 2ebcec9807 [IMP] base: prefetch all fields used by get_combined_arch
The `mode` field in used in `_combine` to distinguish `primary` views
from `extension` ones. The field has been retrieved as part of the query
done in `_get_inheriting_views` and manually placed in the cache so the
ORM doesn't perform an extra query just to retrieve the mode.

Using our benchmark (render_all_views test tag, website_sale, mrp,
contacts, crm and timesheet installed), the reported time was 18.46s
with 17890 queries performed without this improvement, it is 17.82 with
17340 queries with.

Closes #72096

closes odoo/odoo#72127

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2021-06-14 12:55:31 +00:00
Julien Castiaux e123aa2f30 [IMP] base: optimize fields_get() in NameManager
`NameManager`'s validation passes should not be language-dependent.
Fetching translated model and view information thus incurs additional
costs for no reason.  Ensure translations are never enabled for
`NameManager`'s work.

In our benchmarch (py-spy with a rate of 200, render_all_view test-tag
and website_sale,mrp,contacts,crm,timesheet installated), 20% of the time
was spent in `NameManager.__init__` and thanks to this change it is
reduced to 11%. Queries count from 19995 to 17886. Total runtime from 24s
to 21.5s.

closes odoo/odoo#71419

Task: 2463632
Related: odoo/enterprise#18596
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2021-06-11 17:09:05 +00:00
Julien Castiaux 50197d7337 [IMP] base: flatten view post-processing recursion
The post-processing of a view was implemented as a recursion, the
processing of every XML node recursively processing its children nodes.
Recursion inside flamegraphs scatters sub-calls at many call depths,
which makes their analysis less obvious.  Transforming the recursion
into a loop with a stack makes the code more profiler-friendly.

Task: 2463632
2021-06-11 17:09:05 +00:00
Julien Castiaux c0ab436723 [IMP] base: fast special cases in node modifiers
The parsing of the values of attributes `attrs`, `states`, `invisible`,
`readonly` and `required` is done many times during the post-processing
of a view.  The functions `ast.literal_eval` and `safe_eval`, although
being pretty cheap, are called so many times that they represent about
10% of the time spent in `field_view_get()`.

The variables of the function were poorly named, we take this commit
opportunity to rename them: `a` => `attr`, `v` => `value`.

After analysis of what was evaluated, it turned out that 95% of the
expressions safe-evaluated were '1', '0', 'True' and 'False'. We
introduced the special cases to quickly bypass the evaluation and speed
up the rendering.

Using our benchmark (render_all_view test-tag with website_sale, mrp,
contacts, crm and timesheet installed) the runtimes are 27.58s without
this commit and 27.45s with.

Task: 2495504
2021-06-11 17:09:05 +00:00
Julien Castiaux 5815ce7753 [FIX] base: some fixes for ir.ui.view
Task: 2463632
2021-06-11 17:09:05 +00:00
9aca84895f [REF] base: view hierarchy retrieval and combination
The view methods `get_inheriting_views_arch`, `apply_view_inheritance`,
`_apply_view_inheritance` and (previously `read_combined`)
`_get_combined_arch` were complicated and not optimal performance-wise.

The previous approach to retrieve views and combine them was to perform
it recursively, one primary view at a time.  This new approach retrieves
in a single SQL query the whole tree of views to combine.  The order of
view combination has been reproduced to be fully backward-compatible.

We also introduced various optimisations such as pre-fetching and
caching.

**get_inheriting_view_arch**

The method have been renamed `get_inheriting_views` as it returns a
recordset of views instead of the xml architecture of each view.

During an upgrade, only the views that have been fully upgrade already
are safe to be used. The views returned by the query are filtered to
remove any not-upgrade-yet view. Because this part is highly specific,
it has been isolated in a dedicated private method.

View extensions can be discarded according to user groups.  The
retrieval of groups on views is also made by the same query.  This
reduces the number of SQL queries, and makes the filtering faster.

**apply_view_inheritance**, **apply_view_inheritance**

The functions were responsible to build a hierarchy of views and to
iterate it to combine the views.

The hierarchy building have been moved to `_get_combined_view` and the
actual combination have been moved to a new method `_combine` and
documented.

Task: 2541579
Meta task: 2463632

Co-authored-by: Fabien Pinckaers <fp@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2021-06-11 17:09:04 +00:00
221254ca7b [IMP] all: read_combined(['arch']['arch'] => get_combined_arch()
The method read_combined() has been deprecated in favor of explicit
calls to read() and get_combined_arch().

There are places where we call _get_combined_arch() instead, in order to
avoid parsing the XML that has just been serialized. This saves useless
serialization-deserialization.

Task: 2541577
Meta task: 2463632

Co-authored-by: Fabien Pinckaers <fp@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2021-06-11 13:47:54 +00:00
26a8129219 [REF] base: introduce view._get_combined_arch()
Extract architecture combination out of `read_combined` to work on
`etree.Element` exclusively: since `read_combined` returns a serialized
`arch`, its own recursive calls as well as callers needing to
post-process the architecture have to re-parse the `arch` then serialize
it back.

This is wasteful and can be avoided by providing the `arch` as an
`Element`, which is what `_get_combined_arch` does.

The public method `get_combined_arch` is provided as convenience: it
basically wraps a call to `_get_combined_arch` and returns the result as
a string.

Task: 2541577
Meta task: 2463632

Co-authored-by: Fabien Pinckaers <fp@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2021-06-11 13:47:54 +00:00
Julien Castiaux ee7287430f [REF] base: ir_ui_view get_view_arch_from_file
I had troubles understanding how was the function working, I decided to
rework it a bit, ended up rewritting much of it. I hope this new
implementation is easier to understand.

closes odoo/odoo#69233

Task: 2463632
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2021-04-14 11:19:33 +00:00
Julien Castiaux fb4cf35368 [FIX] base: View error reporting can lack a context
A context is attached to the ValidationError object when elements in the
view arch are broken. This context helps to locate the error in the
source file. When the view processing fails outside of the arch
evaluation, such context is missing.

closes odoo/odoo#68157

Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2021-03-19 16:13:17 +00:00
Romain Derie 6a9b5bba9b [FIX] base, website: replicate inherit_id update on cow view
Before this commit, only whitelisted fields would be updated on cow views
during a module update.
A field would be whitelisted if he had the same value than the original view,
see it as a heuristic to not write on modified fields.

But `inherit_id` is not that simple, even if the cow view has a different value
than its original view, it doesn't mean it was modified by the user, it is just
because of the cow mechanism that assigned a copied view as inherit_id, which
is just a copy ofthe original one.

We can thus consider `inherit_id` as unchanged and whitelist it if the `key` is
the same.

In practice, it means that cow'd views did not receive the `inherit_id` updates
as in commit https://github.com/odoo/odoo/commit/c8577568a1e39f6692889b3e21652fa3b8df06b2#diff-823e5db841dca1798ff1300e243059a4e1c93343598d2be5a1d1dcd1d2d0c273R537
where `portal.my_account_link` had its `inherit_id` changed from
`portal.frontend_layout` to `portal.user_dropdow`, see https://github.com/odoo/upgrade/pull/2059:

Considering a module update changing `inherit_id` of D from A to B, the
following use cases are expected. Without this fix, D' never move:

CASE 1
  A    A'   B                      A    A'   B
  |    |                 =>                 / \
  D    D'                                  D   D'

CASE 2
  A    A'   B    B'               A    A'   B   B'
  |    |                 =>                 |   |
  D    D'                                   D   D'

CASE 3
    A    B                        A    B
   / \                   =>           / \
  D   D'                             D   D'

CASE 4
    A    B    B'                  A    B   B'
   / \                   =>            |   |
  D   D'                               D   D'

Opw: 2422773
Opw: 2422727
Opw: 2422770
Opw: 2423406
Opw: 2423859
X-original-commit: ff69f11e9c97d63d9319a8094a87af93984aba38
2021-02-12 15:52:37 +00:00
qsm-odoo 834e3f8f9b [IMP] base, *: remove read_template and review colorpicker template
*: web_editor, website

In stable versions, [1] was made as a fix to allow access to read
the colorpicker template for mass mailing users when they do not have
the read access right on ir.ui.view records.

This commit, for master, remove the need of using the confusing
read_template method by using render_public_asset instead (thus turning
the read into a render, which is the same for our colorpicker but might
be a change for potential custo). At the same time, this allows to
remove the read_template public method entirely.

Related to task-2412544

[1]: 8af75e00bdcda3d5ff4facd2f5f146e1d6bf79e4

closes odoo/odoo#64100

Related: odoo/enterprise#15580
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2021-01-06 09:30:13 +00:00
Julien Castiaux 6fc985794e [IMP] ir_ui_view: Refine error message
When installing/upgrading a module with broken xml views, the module
installation fails with an error message that should help the developer
locate and correct the error.

Before this commit, a 3-level traceback was thrown at the developer:

1. The initial ValueError containing the original error message and some
   view context information.
2. The noisy re-cast of the ValueError to a ValidationError with no
   additionnal information.
3. An additionnal re-cast of the exception to add the original source
   file path plus the entire XML source code that failed to be parsed.

We argue the error contains too much noise as developers are mostly
interrested in correcting their erronous tag of their view, they are not
interrested in `ir_ui_view` internals.

The new exception report is much less talkative, the two tracebacks from
`ir_ui_view` are logged at the `DEBUG` level. The new exception still
contains the original error message with some context on the view record
and the original source file path but it only show 5 lines of XML around
the erronous tag.

closes odoo/odoo#62757

Task: 2366612
Related: odoo/enterprise#15104
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-12-07 15:35:15 +00:00
Romain Derie 4a8aee47d3 [FIX] base: ignore user lang when comparing with arch
Without this commit, when the compare/reset view feature was reading the arch,
it would translate it.

3 issues :
- When reading from file (hard reset), it would translate the file version
- When reading current arch, it would translate it
- When reading compare view arch, it would translate it

closes odoo/odoo#62521

X-original-commit: 1aa4d3cb57844c24d8520b6b974bb36526392ecf
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
2020-11-27 12:03:57 +00:00
qsm-odoo b761191446 [FIX] base: restore t-field inheritance via non-xpath node
Commit [1] made a stupid mistake forgetting nodes with the t-field
instruction can also have the position attribute in case of inheritance
without xpath node.

... It did not crash because there actually is no case of it in the
current codebase, but this is used by some custo on our prod however.
The test introduced by mentioned commit has been extended to crash,
should this specific case be broken again.

[1]: https://github.com/odoo/odoo/commit/92ef3b2dd4655913198d10d06598b799fdcae6d0

closes odoo/odoo#61288

X-original-commit: b05c7f1e8054be4e74289ac366e0ddcc7da2228e
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2020-11-04 11:31:54 +00:00
qsm-odoo 4436039f32 [FIX] base: fix positional branding when inherited t-field sibling
The xpath branding of a node which followed a t-field node which was
added by an inheritance view was not correct. E.g.

View 1:
```
<hello>
    <world id="1"></world>
    <world t-field="a"/>
    <world id="2"></world>
    <world id="3"></world>
</hello>
```

View 2 inheriting view 1:
```
<xpath expr="/hello/world[3]" position="after">
    <world t-field="b"/>
</xpath>
```

So the result is:
```
<hello>
    <world id="1"></world>
    <world t-field="a"/>
    <world id="2"></world>
    <world t-field="b"/>
    <world id="3"></world>
</hello>
```

Now the xpath branding of world id="2" was /hello[1]/world[3], which
is correct.

But the xpath branding of world id="3" was /hello[1]/world[5] which is
incorrect as it should be /hello[1]/world[4] (as related to the
original view). This was because inherited t-field did not carry any
information they came from inheritance (as "normal" nodes would).

The side effect of this was that the incorrectly marked node was not
possible to edit (and made the editor crash on save).

closes odoo/odoo#60976

X-original-commit: 07cf2b9520fc6c79a9a7ca39929bda0bfbe85e3a
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2020-11-02 10:34:54 +00:00
Debauche StéphaneandXavier Morel 7ecb903bea [REM] *: ability to put raw modules in evaluation contexts
Co-authored-by: Xavier Morel <xmo@odoo.com>
2020-09-28 10:33:52 +02:00
Raphael Collet 1f48130d2b [REF] core: _name_search() now returns a list of ids
This provides a better API to search for records by name without the
formatting part (`display_name`).

This also simplifies all the overridings of `_name_search` that no
longer need to call `name_get()`.  The call to `name_get()` is done in
method `name_search` in a generic way.
2020-08-18 13:02:41 +00:00
Lucas Perais (lpe) 49d9771c56 [IMP] web, base: action buttons in list's controlPanel
This commit introduces a new semantics to define action and method buttons
in the list view.
The aim of this feature is to be able to do some actions on selected records, or on the entire
records' domain with the help of buttons located in the controlPanel, much like the form view header buttons.

To define such buttons, one must add a `header` node in the list view's xml definition
```
<tree>
  <header>
    <button type="action|object" name="actionId|methodName" string="button's text" context="{}"/>
  </header>
  <field name="fieldName" />
</tree>
```

task-2246383
2020-07-29 08:59:42 +00:00
Aaron Bohy e17dc1a793 [IMP] web: form: labels of several occurrences of a field
Before this commit, when the same field occurred multiple times in
a form view, all occurrences were associated with the same id, and
all occurrences of the corresponding label (if any) had the same
'for' attribute. As a consequence, besides the fact that there were
warnings in the chrome console, clicking on any occurrence of the
duplicated label focuses the first occurrence of the field.

This commit generates a unique id for each pair label/field, when
possible. However, there is a case that can't be handled
automatically: when the label isn't automatically generated (field
located outside a group, or with nolabel attribute set to "1").
Typically, in this case, there is a <label> node with "for"
attribute referencing the associated field. In this situation, the
id must be defined in the arch, and used in the "for" attribute:

  <form>
    <label for="phone"/><field name="phone"/>
    <label for="phone_2"/><field name="phone" id="phone_2"/>
  </form>

Task 2261697
2020-07-02 13:57:37 +00:00
Victor Feyens 07e4b9e02e [IMP] base: better translation of view validation messages
* Use of new _ signature (and placeholders)
* Ensure all error messages are translated
* No translation for warning logs
* Improved/fixed validation messages

closes odoo/odoo#53804

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-07-02 09:14:33 +00:00
Paul Morelle 0ee0cb57c2 [FIX] base: make NameManager.available_fields a dict
Until version 13.0, ir.ui.view:postprocess_and_fields returned a tuple
of a string and a dict of field information.
With aae1d57829, it now returns a
defaultdict instead of the dict.

This dict comes from NameManager.available_fields, which is initialized
as a defaultdict. There is no apparent reason to have a defaultdict in
this place, apart from the usage in has_field.

Furthermore, using a defaultdict has a side-effect in the search_view
computed field of all the ir.actions.act_window. On a database, if you
access env.ref('base.paper_format_action').search_view it will contain
a stringified dict, and the string default_dict(<class 'dict'>, {...})
is used in place of just {...} under the fields key.

closes odoo/odoo#53235

X-original-commit: 4586d0fbf0bdd5959b274611c58df911e50f4ef2
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: Paul Morelle <madprog@users.noreply.github.com>
2020-06-18 10:56:31 +00:00
Martin Trigaux ba244cef01 [IMP] *: replace to new _() syntax
Using a few regex like
\((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\)
($1, $3))

Old syntax is still compatible but starts the migration to the new
syntax that catches error.
2020-06-18 13:03:34 +02:00
fja-odoo 061ff011df [IMP] base, website: fix prewebsite specific views
Things to know about specific views:

Since the introduction of website specific views, we can have multiple
views that are related to a website (specific views). These views have
no xml_id as it is only set on the original view (generic view).
We rely on the view's key to identify related views as it is the same
for all specific views of a generic view. Also the key is equals to the
xml_id.

When a generic view is updated, we will check if the specific views have
the same values as the generic view. If it is the case, the value that
are the same are considered updatable and are updated on both the
generic and specific view. Else these are considered as noupdate.

When a generic view is created we will check if the potential parent
generic view has specific views. If it is the case we will create a copy
of the created view for each specific view.

The issue:

The method that checks if a created/updated view has specific views is
located in website. When we update a module, each modules are
initialized and updated in a specific order. If a generic view that has
specific views located in a module loaded before website this view's
specific views will not be updated/created as the method does not exist.
This issue is mainly affecting portal views at the moment.

The solution:

For write:
We now COW(copy on write) the views in base module, meaning this will
apply to all qweb views that are duplicated and not only the website
specific ones.

For create:
We  will create the generic view as before but wait until we have
updated all the modules to gather all generic views that are supposed
to have a specific view but don't and create the specific views.
This will result in a change of behavior being that if a specific view
that have a parent is deleted it will be recreated on update
(same behavior as a generic view).

closes odoo/odoo#52629

X-original-commit: b1a90ee2bb441aa52e3cf4607c43fb464b55b1d7
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
Signed-off-by: fja-odoo <fja-odoo@users.noreply.github.com>
2020-06-08 17:23:59 +00:00
Adrian Torres 0ab6b20717 [FIX] base: return super().unlink() for ir.ui.view.unlink()
Commit bca2926b01 introduced a fix for
ir.ui.view unlinks during uninstall but forgot to return the result of
the super() call to unlink which broke behaviour downstream.

This commit restores the proper behavior of returning the result of the
call to super.

Closes #52364

closes odoo/odoo#52435

X-original-commit: a3d91cc8691794d8f93ef416830b09fabcf08b66
Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
2020-06-04 13:33:24 +00:00
Raphael Collet 84a595301e [REF] expression: use and return a Query object
The management of the join contexts now relies on the `Query` object,
that has all the necessary logic to do so.  The refactoring also removes
the class `ExtendedLeaf`, which is no longer necessary: the join
contexts are all managed by a single `Query` object, and the parsing
stack now only contains triples like (leaf, model, table_alias).

Also inline directly the SQL translation made in `_to_sql`, which
overall simplifies the management of SQL parameters in the domain
compilation.  The algorithm is illustrated in the code itself.
2020-05-20 07:56:44 +00:00
fja-odoo 1eb7c577ec [FIX] website_theme_install, base: fix theme update
When a theme module is updated the changes made on a view are considered
as user changes, prenventing the view from being updated in the future.

Fixed by comparing the arch being written with the arch of the original
view. If it is the same the record should not be noupdate.
Plus added a test to make sure the theme views receive theme updates
after being updated once.

Introduced by: https://github.com/odoo/odoo/commit/4acf177b4c55f3a16362cbeafea3d332ef4fe819

closes odoo/odoo#51557

X-original-commit: 221470ab9c9eda3f3a4e2da0fa1a7bb23d6288cc
Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-05-19 15:42:55 +00:00
Nicolas Lempereur 86ecb86069 [FIX] base: groups also distribute branding
When there is a:

`groups="..."`

on a qweb view, when you edit the view with the editor then save all
groups will be removed since they are processed (so either we don't see
`groups` in the rendered view, or we don't see the element itself).

With this change, the "where should this part be saved when edited"
branding will be distributed to elements with `groups` attribute.

Added test without change failed with:

  AssertionError: {'data-oe-model': 'ir.ui.view', 'data-oe-id': '827',
                   'data-oe-field': 'arch'} != {}

because branding was added to `root` tag before change.

opw-2253576
closes #51489

closes odoo/odoo#51548

X-original-commit: c77bd5b043b7d2a795d0fc70c8e83b308a357224
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2020-05-19 14:07:00 +00:00
Martin Trigaux 8eb575a1cf [IMP] base: allow using groups_id on ir.ui.view
Allow groups_id on top level view as a way to relax the access of some
views

There was some scenarios where ir.ui.view were still needed to be
accessible.
For instance the website.snippet is needed to display the website
editor sidebar to designers. The website.compiled_assets_wysiwyg is
needed to display the app switcher on the website to employees.

This should cover most of the cases where a view still must be
accessible and no specific controller is available.
2020-05-14 13:59:10 +02:00