Commit Graph
1012 Commits
Author SHA1 Message Date
Chong Wang (cwg) 09a4762be4 [IMP] test_translation_import: support testing exported pot files
test exported pot files

Part-of: odoo/odoo#142329
2023-11-27 12:39:51 +00:00
Isaac Gallart Bochons ca217195d7 [FW][FIX] base: postgres subprocess error when dumping database
When Odoo is installed with the latest version of the PostgreSQL client (postgres-client or postgres-client-16) and running in Docker (possibly other environments as well but not reproduced so far), executing `pg_dump` via `exec_pg_command` fails with

    Database backup error: Postgres subprocess ('/usr/bin/pg_dump', '--no-owner', '--file=/tmp/tmpmnqiktog/dump.sql', '15TEST') error 1

This seems to be because `os.devnull` is being opened in *read* mode which is incorrect (as it's written to). It's not entirely clear if older `pg_dump` simply ignored the non-writable stdout or if docker adds some restrictions which cause the failure.

Either way this can be solved by either opening `os.devnull` in write mode or switching to the `DEVNULL` constant. While the function is deprecated in 16.0 (7f14631fe8) and removed in master (ae3056f3f4fca82c6aee69bf201532e14829c45e) the latter is not a huge change and it a touch cleaner.

fixes #139687

closes odoo/odoo#143198

Forward-port-of: odoo/odoo#142987
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2023-11-22 21:45:11 +00:00
Thibault Delavallée a03ae3765e [IMP] base: fallback on 'email_re' when getadresses fails
When 'getadresses' fails at parsing some input and give us a result like
'gmail.com' (see previous commit adding test cases) we fallback on using
'email_re' which is better at finding email addresses in a global string.
We use it only in this specific case as fallback mechanism to rely on
'getadresses' when possible.

Task-3572208

X-original-commit: odoo/odoo@8e61a3b690
Part-of: odoo/odoo#141856
2023-11-17 16:11:51 +00:00
Chong Wang (cwg) 7b55483e23 [FIX] core: fix typo for ormcache
fix typo in #119813 for ormcache

closes odoo/odoo#141008

X-original-commit: a242da98b533f5d6c11c68f9d973a26a47f17074
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Chong Wang (cwg) <cwg@odoo.com>
2023-11-04 09:05:36 +00:00
Jinal Patel b16d7754f5 [FIX] tools: Avoid to delete translation for views
Issue is translation of view which doesn't have website_id
and website module is installed in thast case will be lost
after upgrade due to this commit:
https://github.com/odoo/odoo/pull/129518/commits/85940335216de8a4225793095ee2d9a165e3ef71

closes odoo/odoo#140830

Opw: 3496112
X-original-commit: a014f55409d938965c835bd0dd5b2ce8e9345472
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-11-03 00:49:04 +00:00
uso-odoo ecc6066642 [FIX] tools,spreadsheet_account: prevent traceback for day out of month
In the 'Accounting Settings' of 'Fisical Year', When the User tries to set
'February' as a month and the 29th as a Day and Save it, It will allow the user
to save but when the User opens the spreadsheet dashboard in the terminal,
same error will be generated.

Steps To Produce:-

1) Install the 'spreadsheet_account' module
2) Go to Settings -> Accounting
3) In the 'Fiscal Periods' of 'Fiscal Year', In 'Last Day' select
   'February' month and set 29 as a Day
4) Go to the Accounting module, Customer->Invoices
5) In the 'Favorites', Select 'Insert Link in a Spreadsheet'.
6) Open Spreadsheet, Click on the 'Dashboard' Tab

The Error will be generated in Backend(Terminal)

Applying these changes will resolve this issue.

sentry - 4079962029

closes odoo/odoo#140011

X-original-commit: 1323829d3b5e134300f326f86c887f1cad6119f4
Signed-off-by: Laurent Smet (las) <las@odoo.com>
2023-10-27 14:22:02 +00:00
Chong Wang (cwg) 2d08f97c07 [IMP] core: support delay translation
Jsonb data structure of model_terms translated fields' columns
'{
	"en_US": "<div>Apple</div>"
	"fr_FR": "<div>Pomme</div><div>Banane</div>"
	"_fr_FR": "<div>Pomme</div>"
}'::jsonb

"column" IS NULL OR "column"->>'en_US' IS NOT NULL

"column"->>'lang'
1. stores last confirmed value
2. logically fallbacks to
    COALESCE(
        "column"->>'lang',
        "column"->>'en_US'
    )

"column"->>'_lang'
1. stores translations and the last written html/xml structure
2. shares the same html/xml structure with other "column"->>'_lang'
3. logically fallbacks to
    COALESCE(
        "column"->>'_lang',
        "column"->>'lang',
        "column"->>'_en_US',
        "column"->>'en_US'
    )

Context:
1. `delay_translations`(new) only write values to _langs while keeping
translations for langs when the written value has at least one translatable term
2. `check_translations`(new) read _langs values to create translation mapping
for the translation dialog
3. `edit_translations` read values whose translatable terms are wrapped by
`<span></span>` with term information for the TRANSLATE mode of website

Potential issue
since the record value of a model terms translated field is logical content
dependent (check_translations, edit_translations), all computed field computed
from any model terms translated field should also be marked.
@api.depends_context('lang', 'edit_translations', 'check_translations')

Data flow for column value, cache value and record value
(make sure the window is wide enough to see the graph)

                             +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+
                             ' Record(str):                                          '
                             '                                                       '
                             ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
                             ' | "<div><span data-oe-model='model'                 | '               {            read fr_FR             {
                             ' | data-oe-id='id' ...>French</span></div>"          | ' <------------ } context.get('edit_translations')  } <+
                             ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+  |
                             ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+  |
                             ' | "<div>French</div>"                               | '               {            read fr_FR             {  |
                             ' |                                                   | ' <------------ } context.get('check_translations') } <+
                             ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+  |
+~~~~~~~~~~~~+               ' +---------------------------------------------------+ '                                                      |
{ read fr_FR { ------------> ' | "<a>French</a>"                                   | '                                                      |
+~~~~~~~~~~~~+               ' +---------------------------------------------------+ '                                                      |
  ^                          '                                                       '                                                      |
  |                          +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+                                                      |
  |                                                                                                                                         |
  |                                                                                                                                         |
  |                                                                                                                                         |
  |                          +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+                                                      |
  |                          ' Cache(dict):                                          '                                                      |
  |                          '                                                       '                                                      |
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' |                                                   | ' -----------------------------------------------------+
  |                          ' | "_fr_FR": "<div>French</div>"                     | '
  |                          ' |                                                   | ' <----------------------------------------------------+
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
  +------------------------- ' |                                                   | '               {              fetch fr_FR               {
                             ' | "fr_FR": "<a>French</a>"                          | '               }    context.get('edit_translations')    }
  +------------------------> ' |                                                   | '               {  or context.get('check_translations')  {
  |                          ' +---------------------------------------------------+ '               +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
+~~~~~~~~~~~~~~~~~+          '                                                       '                                                      ^
{   fetch fr_FR   {          +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+                              COALESCE(               |
+~~~~~~~~~~~~~~~~~+                                                                                                     "c"->>'_fr_FR',     |
  ^                                                                                                                     "c"->>'fr_FR',      |
  | COALESCE(                                                                                                           "c"->>'_en_US',     |
  |     "c"->>'fr_FR',       +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+                                  "c"->>'en_US'       |
  |     "c"->>'en_US'        ' Database(jsonb):                                      '                              )                       |
  | )                        '                                                       '                                                      |
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' | "_fr_FR": "<div>French</div>"                     | ' -----------------------------------------------------+
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' +---------------------------------------------------+ '                                                      |
  +------------------------- ' | "fr_FR": "<a>French</a>"                          | ' -----------------------------------------------------+
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' | "_en_US": "<div>English</div>"                    | ' -----------------------------------------------------+
  |                          ' +---------------------------------------------------+ '                                                      |
  |                          ' +---------------------------------------------------+ '                                                      |
  +------------------------- ' | "en_US": "<div>English1</div><div>English2</div>" | ' -----------------------------------------------------+
                             ' +---------------------------------------------------+ '
                             '                                                       '
                             +- - - - - - - - - - - - - - - - - - - - - - - - - - - -+

Task: 3043340
Part-of: odoo/odoo#139819
2023-10-27 11:35:03 +00:00
Sanchit Gupta 22619de8b5 [FIX] tools: Wrong Translation in default language
[Here](https://github.com/odoo/odoo/blob/a277faa2ffab7559fcbad95fcc1e8fd6a26d756b/odoo/tools/translate.py#L1645) If 'en_US' is exist in new_values then as a default language 'en_US' translations are loading due to that translation of default language gone lost

OPW -3482255

original translation look like this
![translate](https://github.com/odoo/odoo/assets/127722128/5c788ace-fcec-4783-b036-c6b77bea3083)

 if default language is dutch for example then instead of dutch language english's translations are there
```
en_US : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">I transalted to english</p>
  </t>
</t>
fr_BE : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">this french</p>
  </t>
</t>
nl_NL : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">I transalted to english</p>
  </t>
</t>
```
 arch_db look like this
```
en_US : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">I transalted to english</p>
  </t>
</t>
fr_BE : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">this french</p>
  </t>
</t>
nl_NL : <t t-name="website.test">
  <t t-call="website.layout">
          <p class="o_default_snippet_text">this dutch</p>
  </t>
</t>
```

closes odoo/odoo#139111

X-original-commit: 542851c50182f32327f9cd3607081515899ddb76
Signed-off-by: Raphael Collet <rco@odoo.com>
Signed-off-by: Sanchit Gupta (sagu) <sagu@odoo.com>
2023-10-26 06:16:14 +00:00
Mathieu Duckerts-Antoine 998ef1f63a [IMP] tools: ignore set in view expressions
Now that some field attributes like invisible are given by Python expressions
and that those can involve some set operations, we have to ensure that
the views can be validated if they use such operations. We do that and
add a test.

closes odoo/odoo#139451

Signed-off-by: Géry Debongnie <ged@odoo.com>
2023-10-25 17:03:19 +00:00
Karnav Sojitra 2d55340797 [FIX] tools: raise validation error while invalid expression
When the user tries to modify the view with an invalid xpath expression,
an XPathSyntaxError traceback will appear.

Steps to produce:
1. Install the Accounting module.
2. Settings > Technical > UI > Views > Open any view
3. Invalidate expr syntax and try to save, thus an error will be generated.

Error: XPathSyntaxError: Invalid expression

This commit handles XPathSyntaxError by raising ValidationError
instead of a traceback.

sentry-4377014622

closes odoo/odoo#139435

X-original-commit: 2af583d0b803b3334b871002e447d3211eb09bc2
Signed-off-by: Achraf Ben Azzouz (abz) <abz@odoo.com>
2023-10-25 11:37:36 +00:00
Martin Trigaux 0a1abb5e45 [IMP] tools: allow to use Markup and gettext
Before this commit escape was needed to use a Markup object as a
parameter, hence loosing the fallback mechanism in translations

>>> escape(_("Order %s has been confirmed")) % Markup("<a>%s</a>") % order.name
Markup("Order <a>SO42</a> has been confirmed")

Now it is possible to explictly give a Markup object to the gettext call

>>> _("Order %s has been confirmed", Markup("<a>%s</a>") % order.name)
Markup("Order <a>SO42</a> has been confirmed")

Part-of: odoo/odoo#139316
2023-10-24 21:09:58 +00:00
Chong Wang (cwg) e15b75efb4 [IMP] core: export record translation
Currently, bulk-importing translations for non-module loaded data is hard
1. PO file import works fine, but exporting a PO template for non-module loaded
data is near impossible (since PO exports will only export entire modules)
2. Import of translated values during csv/excel file import is not supported

This commit fix the issue by improve 1 which reuses the translation export
wizard for modules to export translations for non-module records. So that user
can export translations for selected records with a domain and import the po
file after translating

[DEBUG MODE] Settings -> Translations -> Export translations -> Export Type
("model") -> Select `Model to Export` and `Model Domain` -> Export
The framework will
1. create external ids for records without external ids
2. export translations for stored translated and inherited translated fields

closes odoo/odoo#138531

Task: 3463505
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-10-23 20:07:20 +00:00
Raphael Collet c041919f1b [IMP] core: introduce _order_to_sql() to replace _generate_order_by()
The new method should be used to generate an SQL object that represents
how to order by a field in an SQL query.  We introduced the auxiliary
method _order_field_to_sql() so that one can specify some SQL for
ordering by a given field with a simple method override.

Part-of: odoo/odoo#138019
2023-10-20 09:35:18 +00:00
Raphael Collet 31caff2834 [IMP] core: add named parameters to SQL wrapper
For very large bits of SQL code with potentially repeated terms, it is
useful to use named parameters instead of positional parameters:

    sql = SQL(
        "SELECT %(column)s FROM %(table)s WHERE %(column)s IS NOT NULL",
        table=SQL.identifier("foo"),
        column=SQL.identifier("foo", "bar"),
    )

Part-of: odoo/odoo#138019
2023-10-20 09:35:17 +00:00
Raphael Collet 0627e9940d [IMP] core: type annotations in SQL wrapper and Query
Part-of: odoo/odoo#138019
2023-10-20 09:35:17 +00:00
Demesmaeker 211a5bb13b [IMP] sale(_management,_pdf_quote_builder),*: improve pdf quote builder
Following 116879e17e81657f48a7d11780d8d30715ecc68f a few improvements were needed to make it more
complete.

task-3484125

closes odoo/odoo#137522

Related: odoo/enterprise#48563
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2023-10-17 08:53:06 +00:00
Thomas Lefebvre (thle) 7a33a52371 [FIX] google_calendar,microsoft_calendar: use ReadonlyDict
To avoid developers to update the dict of `_events`
in their overrides, to not alter by mistake
the default behavior.
Using a frozendict will force them to create a copy
of the dict.

closes odoo/odoo#123261

Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
2023-08-17 18:43:10 +00:00
Aaron Bohy daf05d48ac [IMP] *: views: deprecate active_* keys from evalContext
This commit aims to simplify the evaluation context used to
evaluate expressions used in views (invisible, required, readonly,
domain and context attributes). For now, the evaluation context is
typically the current record (there's a key for each field in the
view). In addition to that, there're static keys (that may conflict
with field names): uid, allowed_company_ids, current_company_id,
active_id, active_ids and active_model.

The motivation of this commit is at some point to get rid of the
3 active_* keys, because they are misleading and basically useless.

The notion of active_* exists, but it is something else: when you
are in a form view (let's say the form of a partner) and you open
its opportunities (by clicking on the stat button), the list view
of opportunies shows up and in the context, there're 3 keys
active_*, referring to the record from which we came. One can
easily access those information with context.get("active_*"), in
python or in view archs.

However, almost all `active_id` found in archs were actually used
to refer to the id of the current record. Indeed, for now, in the
evaluation context of a record, the value of the `active_id` key is
always the id of the record. So this commit adapts them to
directly use `id` instead. There was no use of active_ids, and
a single use of active_model which was removed (active_model is
the res_model of the view, so it isn't really necessary).

This commit doesn't drop the support of those keys, it deprecates
them. They will be removed for v18. A warning will be displayed if
they are used.

closes odoo/odoo#136665

Related: odoo/enterprise#47917
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-10-10 00:54:04 +00:00
Martin Trigaux 22ab49e343 [IMP] *: use file_path and file_open
Replace all the calls to get_resource_path to the better file_path or
directly use file_open when not needed

Doing both a get_resource_path and file_open means checking twice that
the file exists.
Doing a simple path concatenation before a file_open is safe.
If given to another method (e.g. etree.parse), calling file_path is
the prefered method.

Note that get_resource_path used to return False when the file does
not exists while file_path/file_open raises a FileNotFoundException

closes odoo/odoo#135607

Related: odoo/upgrade#5187
Related: odoo/enterprise#47475
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2023-10-06 14:33:43 +00:00
william b83c4fff34 [IMP] convert: autofill sequence fields
Motivations:
* `sequence` is not super intuitive for new devs
* It makes "useless" noise in data files
* It is redundant when what we want to see in the file is the same as
  what we want to see on the user screen.
Do you understand anything related to sequences in here?
https://github.com/odoo/odoo/blob/15.0/addons/l10n_lu/data/account_tax_report_line.xml
Explicit is not always better than implicit.
* It is not implicit like using `id`  it is natural and visual and saves
  a lot of chore for adding and maintaining sequences.

Implementation
* It is optional, with the option set on root xml tags

Part-of: odoo/odoo#85750
2023-10-06 13:08:51 +00:00
Louis (loco) 94b55d913b [FIX] web_editor, *: store the correct mimetype of an image with a shape
*: tools

Steps to reproduce the bug:
- Add an image on the website.
- Replace it by a "jpeg". Note that the mimetype of the image is
"image/webp" at the upload since [1].
- Add a shape on the image.
- Save and Edit.

-> If you check on the available "Format", the mimetype of the
"original" is "webp" but it should be "jpeg".

Before this commit, there were two types of mimetype data attribute:
- `mimetype`: the current mimetype of the image.
- `originalMimetype`: the mimetype of the image without a shape.
Before [1], it was also the mimetype of the original image. However,
since [1], the user has the possibility to change the mimetype of the
image so the "originalMimetype" attribute does not always refer to the
mimetype of the original image anymore.

To resolve the problem, another data attribute has to be introduced.
Here is a summary of the mimetype related attribute:
- `mimetype`: the current mimetype of an image.
- `originalMimetype`: the mimetype of the image before a shape has
been applied. It is needed when removing a shape to recover the correct
mimetype.
- `mimetypeBeforeConversion`: the mimetype of the original image. It is
needed in order to be able to change the format of an image and come
back to the original one.

In the case of an uploaded "jpeg" image on which a shape has been
applied, `mimetypeBeforeConversion` is "image/jpeg", `originalMimetype`
is "image/webp" (since [1]) and `mimetype` is "image/svg+xml".

The `loadImageInfo()` has been adapted to also handle the case of an
image that has already been loaded but that does not have the
`mimetypeBeforeConversion` attribute (for example all the images that
were uploaded on the website before this commit). In this case, the
mimetype attribute is kept and not set to the original one as the user
could have changed it.

[1]: https://github.com/odoo/odoo/commit/0449fe85cb0e1d639a4e1aeba26e90906f79254d

task-3449866

closes odoo/odoo#137424

X-original-commit: 730588b802506844e6ca54df312333bfd8df1d52
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2023-10-04 18:27:03 +00:00
Victor FeyensandMorgane Demesmaeker 6d1a78286a [ADD] sale_pdf_quote_builder:
When enable, this new feature adds the possibility to set a PDF header, footer and some product
documents to the quotation report.

These PDF can contains forms that'll then be filled using Odoo database.

This replace the previous sale quotation builder feature.

task-3249142

closes odoo/odoo#133773

Related: odoo/upgrade#5168
Related: odoo/documentation#5863
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: Victor Feyens <vfe@odoo.com>
Co-authored-by: Morgane Demesmaeker <edm@odoo.com>
2023-10-03 19:19:57 +00:00
Xavier Morel e2752a04ff [FIX] safe_eval: 3.11 compatibility
Complement on 1e35315399 (#112450):
alongside the split between forwards and backwards jump we missed that
3.11 has a specialized version of each for the `is None` and `is not
None` cases. A use of that was added in standard in 16.5 (#120446) but
more generally it makes sense that server actions would support
conditional tests against `None`, probably...

closes odoo/odoo#137099

X-original-commit: 3227ae45fb79cd08a102aecb484e4f0a4f2597c1
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2023-09-29 13:11:58 +00:00
Jinal Patel 6609a56f8b [FIX] tools: Avoid to delete translation for Structured Model fields
Issue: Translation missing after upgrade when the customer had any
       other language except English and he changed the value instead
       of translation.

In this commit, avoid to delete the translation.

closes odoo/odoo#137087

Opw: 3489453
X-original-commit: b3bfdf676d0daedbd71501d153170f37e97c94d8
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-09-29 13:11:54 +00:00
Raphael Collet 758780c03b [IMP] core: remove parameter 'extra' from Query.join() and Query.left_join()
Part-of: odoo/odoo#134677
2023-09-27 03:01:45 +00:00
Raphael Collet 66a0cdd637 [IMP] core: make an API to get rid of Query._raw_joins
Part-of: odoo/odoo#134677
2023-09-27 03:01:45 +00:00
Raphael Collet 6a61d2b322 [IMP] core: use SQL wrapper in Query
Part-of: odoo/odoo#134677
2023-09-27 03:01:45 +00:00
Raphael Collet 020ddc3a6b [IMP] core: introduce SQL wrapper
We introduce a new class of objects to wrap SQL code together with its
parameters.  It is designed to be easily composable and to discourage
SQL injections.  Its API is similar to the methods of module 'logging':
the code is a format string, and the positional parameters are meant to
be merged into it using the string formatting operator.

    # default and increment are parameters of the SQL code in first argument
    term = SQL("COALESCE(value, %s) + %s", default, increment)

    # term can safely be injected into another SQL, besides regular parameters
    query = SQL("SELECT %s FROM mytable WHERE id = %s", term, id_)

The SQL wrapper can return the final SQL code string as query.code, and
the corresponding parameters as query.params (list).  The cursor method
execute() can now take an SQL object, and execute it just like

    cr.execute(query.code, query.params)

It is quite easy to make SQL objects safe against SQL injections: if the
code is a string literal, then the SQL object is guaranteed safe,
provided the SQL objects within its parameters are themselves safe.

Part-of: odoo/odoo#134677
2023-09-27 03:01:44 +00:00
jorv 16179c9399 [FIX] core: assert _get_func_code code argument
closes odoo/odoo#33682

Signed-off-by: bve-odoo <bve@odoo.com>
2023-08-28 15:15:19 +00:00
Sébastien Theys cc9e2c147c [REF] web, mail, *: tests: remove legacy file utils
* = mrp

closes odoo/odoo#136141

Related: odoo/enterprise#47716
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-09-22 11:55:58 +00:00
Gorash ba1a5509fa [IMP] base: Remove context dependencies from get_views method
In this viewtiverse, the heroes remove the context dependencies for
`get_views`, from the views and python fields (such as domain). To reduce
inconsistencies and the number of rpc.

Current issues:
* There may be inconsistencies in views at the JavaScript level. Some
overrides modify the behavior of get_views or domains on fields via
context keys, therefore by changing the action, the rendering may be
different. However, these views are cached. However, the cache key
(Javascript) does not reflect the entire context, and requires additional
post-processing from the server.
* Multiple rpc for the same rendering. get_views being dependent on the
context, as soon as it changes, a new rpc is performed. In most cases,
when JavaScript needs the same view, there is no change depending on the
context, the rpc is useless.
* Inconsistency when rendering subviews, some views could be different
depending on the context, this context can be modified in the view itself
via the context attributes. However, the JavaScript client does not redo
an rpc for each change of these sub-contexts. Therefore the result may be
inconsistent.

Solution:
Limit as much as possible the number of context keys provided when calling
get_views, and use the context provided as a cache key. The authorized
keys are 'lang' and '*_view_ref'. For the cache key, options are added in
the get_views method.
Instead of using the context, it is inserted into python expressions.
This will be evaluated by JavaScript and thus avoids inconsistencies.

task-3414108
task-3414068

closes odoo/odoo#135145

Related: odoo/enterprise#47584
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-09-21 16:52:10 +00:00
Martin Trigaux bf81596aa7 [IMP] base: use es_419 and not es_MX as reference
And load only two languages, not three.
Faster to load and avoids ambiguity when a Mexican sees es_ES content

closes odoo/odoo#134785

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2023-09-18 22:17:02 +00:00
Chong Wang (cwg) 007d2bde2a [REF] translation: better get_po_paths
make the tool function get_po_paths to reduce duplicated code

Part-of: odoo/odoo#134785
2023-09-18 22:17:02 +00:00
Ivan Rasputin 1711e91257 [IMP] core: test exporting of translation files
Static qweb files are not tested for syntax errors.
This commits adds a hacky way to do this job: we test exporting of translation files.

Inspired by the following PRs, that were made as a response for errors caught by sentry

* https://github.com/odoo/enterprise/pull/43975
* https://github.com/odoo/odoo/pull/128221

closes odoo/odoo#128445

Related: odoo/enterprise#44074
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-09-15 09:22:04 +00:00
Chong Wang (cwg) f0efebee4d [FIX] core: fix typo for TranslationImporter
fix typo to log correct error message when the imported file is badly formatted

X-original-commit: 75606b0f92a26b64ee281792dfa32d47f135f46d
Part-of: odoo/odoo#135277
2023-09-13 12:19:10 +00:00
Chong Wang (cwg) 506d0cc4ec [FIX] core: fix cached translations
before this commit:
translations updated by `update_field_translation` api cannot be detected by
t-cache and some cached data whose model overrides `write` with an extra
'clear_caches()'

Step to reproduce:
- Create a mega menu, select any template, `Odoo Menu` for the example
- Install another language on the website
- Go to the translated version of your website and enter translate mode
- Change "Camera" in the mega menu to something else
- Save

The change won't be replicated, looking like it did nothing.
From there, removing or adding `edit_translations=1` in the URL will
use different cache version of the page's views and you will see the
outdated value on one and the correct on the other one.

after this commit:
`update_field_translation` will call `write`
it does the following 4 important things
1. mark field as modified
2. execute logics in the override `write` method
3. update write_date if needed to support t-cache

opw-3305117

X-original-commit: 2beb466668e4eb80d7c3ca3947445fb1cb141cff
Part-of: odoo/odoo#135277
2023-09-13 12:19:10 +00:00
Nishit Thakkar ce169a38ed [FIX] tools : Save translation for record with no model data record
According to standard flow when a record is created by user we do not make
a model data entry and if he does any changes in standard record we change the
noupdate to true on conditional bases to keep the data same while upgrading
but in the case of user created record where there is no model data entry the
engine should consider it as noupdate true but without the model data entry
select query gets null resulting into engine considering it false and the update
case are designed to consider true or else  so for null case it falls under else
part hence creating issue in product_template name and cowed website menu
So,we have updated the case accordingly.

closes odoo/odoo#135218

X-original-commit: 880538db4ac4833322e57adb3b4d8239eb382547
Signed-off-by: Raphael Collet <rco@odoo.com>
2023-09-13 04:37:06 +00:00
Jinal Patel 6cb30f599e [FIX] tools: Avoid to delete translation for website
- If default language of website is not en_US then it's
  translation will be lose after upgrade as till now we are
  considering en_US as a default language for all the records.

- In this commit, we have added translation for website which
  is having different default language.

Opw: 3186741, 3418725
X-original-commit: 2575dff9362ba6dd2a97db8911ac8b867b126e08
Part-of: odoo/odoo#135218
2023-09-13 04:37:06 +00:00
Thibault Delavallée 64aae8bce1 [FIX] tools, base, mail: add a fallback when parsing wrongly-formatted emails
With input 'name email@domain.com' (missing chevrons allowing to clearly spot
the email part) 'getaddresses' returns ('', 'name email@domain.com) i.e. the
whole input is considered as being the email.

To improve the heuristic we can add a fallback by recalling 'getadresses'
on the input with spaces replaced by commas when it found only an email and
no name. The new email will be split into sub pairs allowing to find the real
email and various name parts, allowing to make a new name / email pair.

Emails should not contain spaces thus this is coherent with email formation.
This fallback actually comes from a specific code done in '_parse_partner_name'
of Partner model. Supporting it directly at tools level make the behavior
coherent for all models.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@18c71edf59
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée e0207d1551 [IMP] tools, base, mail: better support non-ascii / IDNA when normalizing
PURPOSE

Be defensive when dealing with email fields, notably when having multi-emails
or email field containing an already-formatted email.

SPECIFICATIONS

As of rfc5322 section 3.4.1 local-part is case-sensitive. However most main
providers do consider the local-part as case insensitive. With the introduction
of smtp-utf8 within odoo, this assumption is certain to fall short for
international emails. We now consider that

  * if local part is ascii: normalize still 'lower' ;
  * else: use as it, SMTP-UF8 is made for non-ascii local parts;

Concerning domain part of the address, as of v14 international domain (IDNA)
are handled fine. The domain is always lowercase, lowering it is fine as it
is probably an error. With the introduction of IDNA, there is an encoding
that allow non-ascii characters to be encoded to ascii ones, using 'idna.encode'.

Also remove usage of 'email_re' in mailing email check. It is too restrictive
compared to real formatting we support (or try to). Valid outgoing emails
were directly canceled, notably when containing unicode.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@3ce5fb3072
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 881c5ba5b4 [IMP] mail: simplify usage of '_parse_partner_name'
As it already normalizes returned emails some manual calls to 'email_normalize'
are not necessary. Some variable names are updated to be clearer about the
email being normalized.

Parsing contact name and email is also moved into a tool function to avoid
using a partner environment just for a tool parsing method.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@f7add44c28
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 075f073006 [IMP] tools, base, mail: use first found email in 'email_normalized'
PURPOSE

Be defensive when dealing with email fields, notably when having multi-emails
or email field containing an already-formatted email.

SPECIFICATIONS

When having multi-emails input in an email field, 'email_normalized' field is
currently 'False', as they expect the field to contain a single email. This
has several drawbacks

  * searching partners or fetching information based on emails does not work as
    most tool methods use 'email_normalized' which is False (see e.g.
    '_message_partner_info_from_emails', '_mail_find_partner_from_emails'
    or 'find_or_create');
  * blacklist is not available as it is based on 'email_normalized';
  * mass_mailing wrongly considers those emails as invalid and cancel their
    mail and related trace, as it tries to skip sending emails to invalid
    emails;

Be more defensive and use first found email in case of multi-emails field.
Other emails are ignored. It is already an improvement that does not break
flows in stable and allow more emails to be sent.

  before
  -> email: '"Raoul" <raoul1@raoul.fr>, raoul2@raoul.fr'
  -> email_normalized: False
  after
  -> email: '"Raoul" <raoul1@raoul.fr>, raoul2@raoul.fr'
  -> email_normalized: raoul1@raoul.fr

A side effect is that it helps finding back some partners, as indicated in
tests where less phantom partners are created. It also helps suggested
partners / emails flow in discuss.

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@90218186c5
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
Thibault Delavallée 3191aa8207 [IMP] base: avoid double formatting in partner 'email_formatted' field
PURPOSE

Be defensive when dealing with email fields, notably when having multi-emails
or email field containing an already-formatted email.

SPECIFICATIONS

Main fix in this commit: fix multiple nested formatting in 'email_formatted'
computation for <res.partner>. Other use cases are mainly left untouched as
we let users deal with their input. In summary :

  * double format: if email already holds a formatted email, we should not use
    it to compute email_formatted, like

      name: Name / email: 'Format' <email@domain.com>
      -> before '"Name" <"Name" <email@domain.com>>"
      -> after '"Name" <email@domain.com>''

  * multi emails: sometimes this field is used to hold several addresses
    like email1@domain.com, email2@domain.com. We currently let this value
    globally untouched by extracting emails and joining them, as we do not
    expect email_formatted to be a list of emails. Extractin emails allows
    to filter out extra text stored in email field, like

      name: Name / email: text, email1@domain.com, email2@domain.com
      -> before: "Name" <text, email1@domain.com, email2@domain.com>
      -> after: "Name" <email1@domain.com,email2@domain.com>

  * invalid email: if something is wrong, better keep it in email_formatted
    than harcoding "False". Indeed this eases management and understanding
    of failures at mail.mail, mail.notification and mailing.trace level. This
    behavior does not change as it was already implemented like that even if
    not sure it was intended;

Task-2612945 (Mail: Defensive email formatting)

X-original-commit: odoo/odoo@9175bbd8e2
Part-of: odoo/odoo#134934
2023-09-11 15:22:09 +00:00
std-odoo 15353f06d7 [IMP] base, web: allow to group by properties
Purpose
=======
Allow to group records by their property values,
like we can do with normal fields.

Technical
=========
Because there's no foreign key, when we group by a relational property
we need to check the existence of the ids in the query (and same for
selection and tags, because we might have value of a deleted
option / tag in database).

Task-3032464

Part-of: odoo/odoo#103510
2023-09-08 09:46:56 +00:00
Karnav Sojitra b0b4f7b3ad [FIX] base, tools: raise logger warning while invalid attribute added to a field
This error occurs when a user tries to add an Invalid attribute
(ex-help, searchable) to an element field.

Steps to produce:
- Install Studio.
- Open any tree view.
- Activate studio > Go to views > Click on XML.
- Add an attribute help inside any field.

So, this commit handles the case by changing the logger error to logger warning.

sentry-4377111502

closes odoo/odoo#131164

X-original-commit: 10f45eacdfd4c6fe5d86659276d145a563f60c6c
Signed-off-by: Fabien Pinckaers (fp) <fp@odoo.com>
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
2023-08-28 16:42:01 +00:00
Saurabh Choraria ea9d6649ee [FIX] base: handle error when editing comment in view's architecture
Currently, When the user is adding a double hyphen or space or anything within a
comment in a view's architecture and tries to save the view, then an error
occurs.

To reproduce the issue:
1. Go to Settings > Technical > Views > open a view.
2. In View Architecture comment out a line.
3. Add a double hyphen or space or anything within the comment.
4. Then save manually, the error will occur.

To solve this issue the error has been handled using a try-except block in
'parse_html' method.

sentry-4306359331

closes odoo/odoo#132267

X-original-commit: ba6f90fac142ae53995f4fce4b75799e61b95b6c
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Saurabh Choraria (sauc) <sauc@odoo.com>
2023-08-19 10:05:45 +02:00
Gorash cdaa761ced [REF] base: Update modifier syntax (invisible, required, readonly)
Goal:
* Simplified modifiers to only have one way to define modifiers;
* Remove states attributes on python field;
* Use python expression in view `required`, `readonly`, `invisible`;
* More accurate validation of xml views.

This commit change the syntax to python expression. The next commit
will update/convert all xml views.

Before this commit:
* the `required`, `readonly` and `invisible` attributes can only have
values of `True`, `False`, 1, 0 or a python expression to use the
context;
* the `attrs` attribute define a dict. The key of this dict was
`required`, `readonly` and `invisible` and the values are the domain or
a string representing a domain to be evaluate as python expression.
This python expressions was evaluate by the javascript with view fields
and other contextual values as: context, uid, parent, active_id,
active_ids, active_model, allowed_company_ids, current_company_id.
* the `states` attribute in the view was a comma separated list of the
state. This list was combined with the `invisible` attribute;
* the `invisible` attribute on python field is used as default value;
* the `states` attribute on python field was dictionnary with state as
key and list of tuple. This structure was combined with `readonly` view
attribute.
* After combining, the resulting domains of the different attributes
`required`, `readonly` and `invisible` are evaluated with the values of
the fields. The `invisible` attributes is splitted into two use:
`invisible` and `column_invisible`.

After this commit:
* The attributes `required`, `readonly`, `invisible` and
`column_invisible` define python expression. This python expressions
are evaluate by the javascript with view fields and other contextual
values as: context, uid, parent, active_id, active_ids, active_model,
allowed_company_ids, current_company_id.

The domains can contains contextual value and will be evaluate by the
javascript.

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'readonly': [('field_b', '!=', False), ('field_c', '=', parent.c)]}"/>
    <field name="field_b" states="draft"/>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a') or field_b and field_c == parent.c"/>
    <field name="field_b" invisible="state != 'draft'"/>
```

Some inherited views will be modified differently in order to maintain
the previous behavior:

```xml
    <field name="field_a" readonly="not context.get('show_a')" attrs="{'invisible': [('field_b', '!=', False)]}">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="attrs">{'readonly': [('field_c', '=', False)], 'invisible': [('field_d', '!=', '3')]}<attribute>
    </field>
```
will be replaced by
```xml
    <field name="field_a" readonly="not context.get('show_a')" invisible="field_b">
```
```xml
    <field name="field_a" position="attributes">
        <attribute name="readonly" add="(not field_c)" separator=" or "/>
        <attribute name="invisible">field_d != 3<attribute>
    </field>
```

Validation:
A stricter control is made on the level of the attributes (modifiers)
and the fields necessary for these. The use of the previous attributes
'attr' and 'states' triggers an error (these no longer exist after the
application of the migration script)

task-2495504

Part-of: odoo/odoo#104741
2023-08-18 09:49:08 +02:00
Antoine (ande) 0a0cbe9041 [FIX] tools: nbsp html character
Current behaviour:
When sending an email from Odoo,
&nbsp; can be seen in plaintext.

Steps to reproduce:
1. Install sale_management
2. Head over to Sales > Quotations
3. Create a new quotation
4. Enter a partner
5. Click on Send by email
6. [...] S00021 amounting in $&nbsp;12.00 [...]

Fix:
When parsing to plaintext, replacing
html character by unicode character

opw-3389602

closes odoo/odoo#132203

X-original-commit: 3e3f1e67dd5894a41c830344ed41c91a5e44159e
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Antoine Demany (ande) <ande@odoo.com>
2023-08-17 18:43:28 +02:00
Martin Trigaux f4d5752724 [IMP] tools: load also es_MX
The translations on Spanish (Mexico) are more active than on Spanish
Moreover, most other countries speaking a variant of Spanish are
located in Latin America and are closer to es_MX than es.
To solve this, when installing for instance es_AR, the translations
will be loaded in the following order:
1 es
2 es_MX
3 es_AR

In case a term is translated in both es and es_MX (and not es_AR), the
later will be used

closes odoo/odoo#121415

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2023-07-28 17:53:53 +02:00
Benoit Socias 567e5b58d5 [IMP] base, tools, web_editor, *: use original image if size increases
*: web_tour, website

When no transformation is applied on an image, changing the quality
sometimes increases its storage size.

This commit makes sure that the original image remains used if only the
image quality is modified and if this makes its storage size bigger.

Fixes #61619
task-2835144

closes odoo/odoo#103398

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
2023-07-19 13:12:51 +02:00