Commit Graph
569 Commits
Author SHA1 Message Date
Raphael Collet ea3e39506a [IMP] models: use slots for BaseModel
This restricts the attributes of a BaseModel instance to `env`, `_ids`
and `_prefetch_ids`.  This way, one can only assign fields on a record;
other assignments are programming errors.

This also reduces the memory footprint of records from 168 to 64 bytes
(-62%), and makes their instanciation faster.

closes odoo/odoo#51075

Related: odoo/enterprise#10529
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-18 09:51:43 +00:00
Julien Castiaux d6d0e8d6d2 [FIX] models.py: remove leftover import crm like compatibility
Historically, it was possible to import addons via a naked import. It is
no more possible since 9e1f13bac, since that commit, the only possible
way to import odoo addons is via the `import odoo.addons' prefix.

closes odoo/odoo#46995

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-14 14:40:02 +00:00
Martin Trigaux 56a8c9e431 [FIX] *: add sudo when accessing views
The method fields_view_get should be the only way to retrieve the view
content. This method is executed in a super-user context.

To avoid retrieving views for a model a user does not have access to
(as it may reveal some informations like name of fields), add a
verification of 'read' rights before retrieving the view content.

Execute _postprocess_access_rights with sudo(False) as this method is
used to evaluate which buttons should be displayed.
Remove the su flag to avoid misleading the user and displaying a
button they won't be able to use.

Retrieving the database id from an view key is not considered as a
sensitive information and get_view_id and viewref can be left as a
public methods.

Add missing sudo when needed

Change _handle_visibility in website to avoid increasing the query
count: Checking the visibility (to fail most of the time) to retry in
sudo was making unecessary queries.
2020-05-14 13:59:10 +02:00
Victor Feyens d2652e971a [IMP] doc: add information on the new populate feature.
* Cmdline interface: how to trigger database population
* Testing: how to implement database population on a given model.
  * autodocumentation of the population methods

+ improve population methods docstrings.

closes odoo/odoo#50596

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-05-13 15:47:04 +00:00
Martin Trigaux d8bc0e4811 [FIX] base: remove leftover of transient ACL
Access rights were added on transient models at odoo/odoo#43306
The _filter_access_rules method was still using the old logic of
transient, bypassing access rules

closes odoo/odoo#50828

X-original-commit: 7e0d6f7e0d725a2addb2821c16fce77aed54ca03
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-05-07 09:49:11 +00:00
Raphael Collet 1b1b2142f1 [IMP] fields: add validation of parameter names 2020-04-07 09:25:08 +00:00
Julien Castiaux ab4000fb3c [REF] base: Remove deprecated exceptions and osv
TL;DR: remember `osv` and `except_orm` ? You can forget about them.

* Deprecated `except_orm` dropped.
* `UserError` elevated as super type of all user-related
  errors.
* Unused `DeferredException` dropped.
* Unused `QWebException` dropped (real one is in `qweb.py`).
* `MailDeliveryException` made a python exception.
* `name` legacy exception attribute made an alias of the python standard
  `args[0]` attribute and deprecated.
* `value` legacy exception attribute dropped.
* `exception_type` RPC error response key dropped.
* Deprecated `osv` module dropped.
* `--osv-memory-age-limit` cli option made an alias of
  `--transient-age-limit` and deprecated.

The `odoo.exceptions.Warning` have long been a deprecated alias to
`UserError`. It is going to be removed in a future version but first we
explicitly deprecate it with a warning.

The `odoo.exceptions.DeferredException` was a very old internal
exception, it has been removed without deprecation notice as it is never
raised.

The `odoo.exceptions.except_orm` has been a deprecated exception type
with deprecation warning for 5 years, it has been removed in favor of
UserError which becomes the super class of all user-related errors.

The `odoo.base.models.ir_mail_server.MailDeliveryException` was
inheriting `except_orm`. As it is not related to a user error but is
more of a problem an admin much take care of, the exception has been
made a Python error.

The `exception_type` JSON key in RPC error responses was holding an
hardcoded value derived from the exception type. Its usage has been
dropped in favor of the `name` JSON key that holds the precise exception
name. Again as it was hardly used in the source code (beside the crash
manager) it has been dropped without deprecation warning.

Since we are here trying to clean odoo custom exceptions, we are also
deprecating the `name` exception attribute in favor of the more standard
`args[0]` attribute.

The `name` (along with `value`) were two attributes used to raise
`except_orm` exceptions before the introduction of `UserError`,
`AccessError` and related exceptions. The `name` attribute, at the time,
was holding the exception type/title. Nowadays it contains the error
message. The `value` attribute, at the time, was holding the error
message. Nowadays it is no more used.

The `osv` module contains very old deprecated aliases. There is no
simple way to log a deprecation warning for osv, osv_memory and
osv_abstract but as they have not been in use for ages, they have been
removed too. To be consistent, the `--osv-memory-age-limit` cli option
has been made a deprecated alias to the `--transient-age-limit`.

closes odoo/odoo#45723

Task: 2187728
Related: odoo/enterprise#9162
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-08 08:41:17 +00:00
Raphael Collet 9afce4805f [IMP] core: reflect models, fields and selections in batch
This saves 4.5% of the total installation time.

X-original-commit: 8519064dce975af542ccd30dc14c56b9bb36d07b
2020-04-03 11:40:29 +00:00
Raphael Collet 3ecb6fdcb0 [IMP] core: optimize model._auto_init() on a new model
Create the table with all the columns from scratch, with the NOT NULL
constraint when required.  Also do not call `_check_removed_columns()`
on a new table.

This saves 0.5% of the total installation time.

X-original-commit: 0727cacf5194a143b15ab4cb9893f3035a67be1f
2020-04-03 11:40:28 +00:00
Raphael Collet 892e3df701 [IMP] core: compute field_computed lazily
This is a simple refactoring.

X-original-commit: 634775bff6d9eba9d4548cc801071a942895a719
2020-04-03 11:40:28 +00:00
Raphael Collet 0551e7ad54 [IMP] core: compute field triggers lazily on registry
This saves 2% of the total installation time.

X-original-commit: 6a0028f91944b1d9e4eac026e86ca249ef5bc7ee
2020-04-03 11:40:28 +00:00
Raphael Collet f3932ea716 [IMP] core: remove Field._slots
This optimization is no longer necessary.  Thanks to Python 3.6's new
implementation of dicts, the memory footprint difference between slots
and dicts is now around 5%, which is no longer worth the complexity and
performance cost.

This saves 2% of the total installation time.

X-original-commit: c7f17770803744cbbb741fc11265ee914641aed7
2020-04-03 11:40:27 +00:00
Raphael Collet f694caac41 [IMP] core: optimize model._setup_base()
Simplify the code to retrieve fields on a class.
Simplify the class attribute that lists the class' proper fields.
Optimize `model._add_inherited_fields()`.
Optimize `resolve_mro` by using classes instead of recordsets.

This saves 3.5% of the total installation time.

X-original-commit: 89ab71905cb6c5d3beda5eac357f8592e31aaef8
2020-04-03 11:40:27 +00:00
Raphael Collet 46b7fb5984 [FIX] core: do not register classes when _module is falsy
The goal is to avoid a class from being added in the dictionary
`MetaModel.module_to_models`.

We use this feature in tests to prevent classes extending models from
triggering bugs when reloading the registry (for whatever reason).

X-original-commit: 12db61b787b2035bf0c1f2a68a24449d484744c8
2020-04-02 23:54:32 +00:00
Mitali Patel c248594ee5 [IMP] base: allow restricting / removing exports right
Add a new group allowing administrators to remove the ability for
users to bulk-export data from the database. It's pretty minor as
technically the user can still access the underlying object through
the basic methods but it's still a bit of a roadblock.

Users can export by default.

Task 2170900

closes odoo/odoo#45400

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-04-01 13:07:50 +00:00
Xavier-Do f545fd274d [IMP] core, base: add tooling to populate database
Some use case like testing performance or upgrade scripts required a database
with prefilled data, covering basic corner cases. A solution can be to
create data a procedural way.

This commit proposes an API to easily populate a model, usually by giving a
list of possible values for each field or by giving a compute method that will
be based on raw values of other fields.

The basic way to define how to populate a new field is to override `_populate_factories`,
a method that returns a sequence of pairs `(field_name, factory)`.

The definition of a field is a "factory", a function that returns a neverending iterator
combining its value(s) with the values of the iterator given in parameter.
Some factory helpers are given in `tools.populate.py`:
- `iterate(vals, weighs)` ensures that one record is created for each value
by iterating on them, then resumes as `random.choice` on those vals following weights
once the first iteration is finished.
- `cartesian(vals, weights)` makes a cartesian product of its own values with the values
of its input iterator, then resumes as a randomized generator.
- `compute(function)` calls the given function with the current values dict and a random object,
and assigns the current field to the returned value.
- ...

Each iterator yields dictionaries of field values, and the factory should add a
value for the current field(s).  The yielded dictionaries also contain a pseudo_field
`"__complete"`, that indicates whether this step is some randomized data
to reach the expected count of records.  A falsy value indicates that the iterator
is still covering mandatory cases.  This indicates whether a cartesian product is
finished, or an `iterate` has consumed all its values.

The order of the factories is quite important, since some computed fields may need
other fields to be defined, and `cartesian` factories should always be at the beginning
to avoid having too many combination.  That is why the factories are given as a list of
pairs instead of a dictionary; this makes it easier to insert elements at any place.

Example:
field A: cartesian([T, F])
field B: cartesian([0, 1])
field C: iterate([a, b, c, d, e])
field D: compute(1-B)

_c is shortcut for __complete
_ is a random value, or result of a random value

```
iter | root  | field A  | field B | field C     | field D   | result
0     {_c:F}  {... A:T}  {... B:0} {...C:a}      {...D:1}    T,0,a,1 complete:False
                         {... B:1} {...C:b}      {...D:0}    T,1,b,0 complete:False
              {... A:F}  {... B:0} {...C:c}      {...D:1}    F,0,c,1 complete:False
                         {... B:1} {...C:d}      {...D:0}    F,1,d,0 complete:False
1     {_c:T}  {... A:_}  {... B:_} {...C:e,_c:F} {...D:_}    _,_,e,_ complete:False
2     {_c:T}  {... A:_}  {... B:_} {...C:_}      {...D:_}    _,_,_,_ complete:True
```

X-original-commit: 4c0182dafa584853ed83a166096f45c33c06a245
2020-03-30 21:30:13 +00:00
Adrian Torres 32fcc1b883 [REM] base: deprecate resolve_2many_commands
With the introduction of `new`, the use of `resolve_2many_commands` is
redundant, as it accomplishes the same function with the added benefit
of returning a record-like object whose API is more familiar than
`resolve_2many_commands` API.

closes odoo/odoo#37290

Related: odoo/enterprise#9409
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-03-23 15:14:11 +00:00
Xavier Morel d418bff698 [FIX] core: make accessing fields from __str__ possible
Because CacheMiss calls str() on the record it's given, it's not
possible to override __str__ and get field values: on the first cache
miss (= the first field access) we're going to blow the stack:

* any random field is accessed
* and faults
* which creates a CacheMiss
* which stringifies the record
* which accesses a field
* which faults
* which creates a CacheMiss
* etc...

Fix:

* move the basic Model's stringification to repr(), which is
  implicitly called on str() if no __str__ is specified, for historical
  reasons we were doing the opposite
* use repr() when initialising CacheMiss

closes odoo/odoo#42966

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-03-23 10:53:34 +00:00
Raphael Collet fd50ba9fb8 [IMP] core: do not recompute stored field on new record
The use case is a cache miss of a stored field with compute on a new
record with origin.  The field should be computed only when explicitly
triggered, i.e., when a dependency has been modified.  Otherwise it
should be fetched from the origin record.

closes odoo/odoo#47353

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-03-23 09:04:59 +00:00
Xavier Morel 012678bf27 [IMP] core: cutoff imports after some number of errors
Importing 100 records and getting 100 errors (often the same every
time because a required field was not mapped) is not super useful and
spams the logs a lot.

Cutting off at one point seems useful.

Note: integrates warnings-related fix from #47972 reported by Grzegorz
Marczyński in #47936.

closes odoo/odoo#48095

X-original-commit: 6b05f1d13c862dd66e89f35607d072315be80995
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-03-20 10:29:33 +00:00
Xavier Morel fe376d50d0 [FIX] core, base: leftover deprecation warnings
* from collections import <ABC> is deprecated, unclear why the
  deprecation warning didn't appear before (possibly only appears in
  3.7/3.8?) either way `collections.abc` should be 3.3+ so switch
  everything to it.
* add some more ignores on third-party packages deprecation
  warnings (meh)
* while at it, mitigate generation of non-breaking space on some
  versions of Babel (in the french locale used by our tests anyway)

closes odoo/odoo#47581

Related: odoo/enterprise#9214
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-03-19 09:32:21 +00:00
Raphael Collet 5771772b61 [FIX] core: do not force recomputation of fields on new records
The method `recompute()` should not recompute fields on new records.
This is both a speedup (those recomputations are not necessary), and
fixes an error following an `onchange()` (a field recomputed in an
environment with the wrong context.)

OPW 2184998

closes odoo/odoo#47545

X-original-commit: fa852ba1c5707b71469c410063f338eef261ab2b
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-03-12 17:46:06 +00:00
Xavier-DoandRaphael Collet 03708af20e [IMP] core: make exists determinist
When testing odoo, errors can occur an undeterministic way, wich can
lead to strange and unreproductible behaviour.  This also means that the
performance can change from one execution to another, making it quite
difficult to track performance variation on a global scope.

This commit makes the result of `exists()` deterministic in terms of
order.  The side effect is to keep record ids in the same order as the
original recordset, which may be useful.

closes odoo/odoo#47282

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2020-03-12 09:37:04 +00:00
Sébastien Theys e3afe4d067 [IMP] models, (test_)mail, portal(_rating): remove message_tree
from `message_format` and from `_message_read_dict_postprocess`.

The reading and initial formatting is done by `_message_read_dict_postprocess`,
which has been renamed more simply to `_message_format` due to its new goal.

This makes the methods easier to follow and does not increase the query count.

It actually reduces it when the data were already in the cache, by not always
reading them again.

Part of task-2180311
PR: #43841
2020-03-06 16:15:44 +00:00
Toufik Ben Jaa ac32c3ea6c [FIX] models: crash on one2many fields without inverse
- In some cases One2many fields defined as computed without
    inverse field defined could cause crashes if it is used
    in a search.

    This should not be done, but shouldn't crash either.
    With this fix, trying to search on one of this fields
    would just print a warning.

closes odoo/odoo#46742

X-original-commit: 4b4f1623590f2e872c565e8e56002bc3f5bf9efe
Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
2020-03-03 12:19:10 +00:00
Victor Feyens f4bcf2c3f9 [IMP] base: batch records (un)archiving
This allows detailed reporting in write overrides.

Expl:

When (un)archiving multiple records together (from a view list, or in batch call),
you will only see one record at a time in `write` overrides.  This means you
won't be able to return meaningful and complete messages to the end user.

Before:
1) Archive A & B
2) "You cannot archive A"
3) Archive B
4) "You cannot archive B"

After:
1) Archive A & B
2) "You cannot archive A & B"

closes odoo/odoo#46358

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
2020-02-26 14:31:31 +00:00
Sébastien TheysandRaphael Collet 5d62e4954f [FIX] core: fix _flush_search() when _order depends on m2o
closes odoo/odoo#46365

X-original-commit: 604b6a22db8eddfb37f9be31d3826394e25bd86c
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Sébastien Theys <seb@odoo.com>
2020-02-26 17:56:32 +00:00
Raphael Collet 229075205f [FIX] core: compute fields in batch on new records
Remove a leftover special case of the ORM from a former version.
This fixes a performance issue, where an onchange recomputes a field on
one2many lines one by one.

X-original-commit: 16a75d85741db8a1f87c1d26503a9bb75197cf83
2020-02-26 12:57:05 +00:00
Sébastien Theys 6bb0963b6a [IMP] core: optimize read() by avoiding useless query
When the `select` returns nothing more than ids that are already known, there is
no need to make it at all.

This removes one query from `_read` every time it has to fetch only fields that
are stored in a different table (o2m, ...), which happens all the time when
reading a stored field first (triggering prefetch) and then reading a o2m.

The query that is now removed was used to check access rules, but the trick is
to use `check_access_rule` to verify the rules in python instead.

Part of task-2061122

closes odoo/odoo#36263

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2020-02-25 13:46:10 +00:00
574d7f0d4c [IMP] core: import-compatible export of m2m fields
When performing an import-compatible export, m2m values would be
exported as a record per cell unless the `id` subfield was the first
to be exported. Which is not the case when using the export UI (as it
always adds the field itself before any subfield). This would make the
m2m not actually export-compatible in most cases.

* export m2m "display name" in an import compatible format as well
* re-prioritise exporting xids when there are multiple m2m exports in
  import-compatible mode
* never fall back on the o2m / non-import-compatible m2m path for m2ms
  in import-compatible mode

Note: if multiple m2m fields are specified only one of them gets filled.

Task 2065428

closes odoo/odoo#37407

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Co-authored-by: Ravi Singh <ras@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
Co-authored-by: Xavier Morel <xmo@odoo.com>
2020-02-21 12:12:19 +00:00
Raphael Collet fd30d29d3c [FIX] core: log import traceback in debug mode
This is a followup of 1d553eea7b.

Systematically logging import tracebacks can fill up log files, and
waste disk space.  We therefore log those tracebacks in DEBUG mode, so
that they can be activated only when needed.

closes odoo/odoo#45075

X-original-commit: 017e3d798c55b1bdac221aea76d3d944f045ee65
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-02-11 11:39:25 +00:00
Thibault Francois 4673a04c94 [FIX] base: don't swith back with su=False in _name_search
When you have su == True in your env and you call _name_search
    the _name_search was switching back to su = False
    when you call with_user with the same user or with None

    To reproduce the issue, take a model where a user has
    no access.control.list allowing to read the model
    call name_search with sudo.

X-original-commit: 8755269f9877e039663adaec8500b530b6d67c68
2020-02-08 18:55:15 +00:00
Adrian Torres f61262eb08 [FIX] core: delay constraint application in case of upgrade
closes odoo/odoo#44800

Co-authored-with: Xavier Dollé <xdo@odoo.com>
X-original-commit: bc2bb5e03c2b32d4ee1b0597ea5889c17d2b0e0e
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2020-02-06 18:28:29 +00:00
Victor Feyens 59a7738be2 [IMP] doc: orm page missing information + UI
* Some fields types were missing
* Add information on multi-record field access
* UI finetuning
2020-02-05 14:00:15 +00:00
Martin Trigaux 6d8688bb12 [IMP] base: use ir.model.access on transient models
Before this commit models with the `_transient` flag were ignored in
ir.model.access verifications. Only an implicit ir.rule with the
domain (create_uid=user.id) was applied to avoid most side effects.

The problem is that, often, the security does not lie in side-effects
of abusing of somebody else's wizard record but in the fact that the
wizard methods blindly trust only the right users are creating these
records. Too often, too many sudo were used and creating wizard with
chosen values could lead to an abuse scenario.

Instead, explicitly require the developer to declare security rules
the same way as on any other model.
2020-02-04 17:53:48 +01:00
Xavier Morel eae19fc2cd [FIX] core: int() deprecation warning
__int__ should always return an integer, not a bool and not a
completely unrelated type either.
2020-02-04 12:42:35 +00:00
Damien BouvyandRaphaël Collet 00205aae2a [IMP] base: support group_expand for custom fields
Allow a naive `group_expand` for manual fields where having the
attribute set to True causes the ORM to include all records from the
relation model of the m2o field in the read_group.

This is particularly useful for custom m2o fields which represent
stages - a grouped list view or a kanban view should include all
possible stage, not only the currently used values.

Co-Authored-By: Raphaël Collet <rco@odoo.com>
2020-01-31 12:07:29 +00:00
Martin Trigaux a74a648030 [IMP] *: use ast.literal_eval
When simply need to parse a domain, it is easier

Add .strip() on ir.ui.view as ast.literal_eval produces an syntax
error if the node starts with spaces (as done in the xpath of
hr_attendance.view_employee_form_inherit_hr_attendance)

closes odoo/odoo#43831

Related: odoo/enterprise#7894
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-01-28 13:58:05 +00:00
Adrian Torres 1d13928764 [IMP] core: improve mapped and filtered performance
Previously, mapped was following a very naive approach, which was simply
calling the field name passed as input for every record in a recordset,
sequentially.

The problem with this approach is that we will potentially recompute the
same fields multiple times for differents records, when this could be
done once per field for ALL records, and store this value in cache for
further access.

Another potential problem is that we don't take advantage of the ORM's
prefetching to fetch all the records that are not in cache at once,
instead of doing the same query for every record in the recordset.

Yet another problem is the conversion of each cache value to a record
format and then combining all of the individual records into a single
recordset, which, depending on the size of the recordset, can take an
unbelievable amount of CPU time.

With this new implementation of `mapped()` we take care of all of these
problems:

This is done by first delegating `mapped()` from the model to the field,
this mapped takes a recordset as input and it will try to batch compute
and prefetch as much as possible for the entire recordset, but it will
not keep these values for the actual output, it just stores everything
in cache and then at the end, retrieves everything from the cache to
guarantee the same order.

After the mapped, the conversion from cache format to record format is
delegated to the new `convert_to_record_multi` which will fetch all the
ids and then perform a single browse to encapsulate all of the records
into a single recordset with the least amount of overhead possible.

Part of Task 2170344

closes odoo/odoo#42611

Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-01-21 14:06:50 +00:00
51b36c3dbb [IMP] base: add default image for users + placeholder if unassigned
1/ When the new database is created without demo data, the admin has a
   'silhouette' as a default picture. When a new user is created without
   picture given by the current user, the new user will have a 'silhouette'
   as a default profile picture.

2/ web: image for fa-user-slash. This image will be used when a record is
   unassigned.

3/ web, *: Change placeholder by default when record is unassigned.
   We want to have a fa-user-slash icon when a record is unassigned instead
   of 'placeholder.png'. A method is created in the BaseModel to have a
   generic method to change easily the placeholder for other models.

4/ Adapt kanban test to keep the same behaviour. Attention the behaviour is
   a bit different. Because, now the default image is given by the server to
   change easily the default image when a record doesn't have an image.
   Thus, we don't say if it's the default placeholder, but we can say it's
   not the same image of the record (in this test, the record, it's the
   partner).

5/ misc: display 'Unassigned' in the hover on kanban cards if record is unassigned

closes odoo/odoo#41356

Taskid: 2060206
Related: odoo/enterprise#7758
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Co-authored-by: jdoutreloux <jud@odoo.com>
Co-authored-by: Yannick Tivisse <yti@odoo.com>
2020-01-21 09:22:46 +00:00
Raphael Collet cdc4547168 [FIX] models: duplicates in records to prefetch
Fix the prefetching mechanism to never consider a recordset with
duplicates.

closes odoo/odoo#43426

X-original-commit: c312e1e5e5e23d1d8dc172aa6e5f8f07f5638792
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-01-16 15:11:58 +00:00
Christopher Ormaza 51de5eb041 [FIX] core: disable wait_callback during copy_from
Apparently some solutions (e.g. bitnami) deploy odoo using async
workers, and not all pg/psycopg2 features are supported in that mode,
notably COPY FROM (bulk-copying data from a stream to postgres). Work
around this issue by disabling "async mode" as we do the copy (by
resetting the wait callback) then re-enabling it.

While this is not an officially supported run mode, it should Do No
Harm™ for normal operations and could help users and clients.

Of important note: while this fixes an error running in async mode, it
will also prevent the worker from yielding while copy_from is
executing. Hopefully that doesn't take too long (as the entire point
of the copy_from is to be fast) but there you are.

Fixes odoo/odoo#24145

closes odoo/odoo#43481

X-original-commit: c4583cf89c2b24085a2eeafea5ef76f474c5ff84
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-01-17 12:20:03 +00:00
Yannick Tivisse 472ac63f1f [FIX] models.py: Fix check_company mechanism
Purpose
=======

If check company is set on a field and if the user has no access
right to the field value (example: address_id on an expense sheet
could be set to a private res.partner, on an onchange method when
setting the employee), then the check_company mechanism will
raise an AccessError when trying the validate the companies on
the different records.

Specification
=============

As we only wish to validate the new record values and not the
access rights, the validation could be done as a superuser to
avoid unecessary errors.

closes odoo/odoo#43240

Taskid: 2170006
X-original-commit: 37a9b6c63dcbc268013fbe1a890cf9390eb8e223
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-01-14 08:26:05 +00:00
Xavier Morel a2a1e294d7 [IMP] core: deprecate returning domains from onchanges
* add a runtime warning when an onchange method contains the string
  'domain'
* add a lint test to forbid the string 'domain' in onchange methods,
  this is easy to defeat (e.g. `dict(domain=...)`) and can have false
  positives (literal `'domain'` strings for reasons other than an
  onchange result) but overall it seems to work nicely
* implemented as a non-pylint test as pylint takes ages to run. While
  at it, remove the long-disabled and long-useless
  PEP3110TokenChecker (checks for `except Exception, a` which is a
  syntax error in P3)

Task 2115472

closes odoo/odoo#41918

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-01-06 10:35:52 +00:00
tanghulu0608 28b2995a41 [FIX] doc: correct the doc string of the read_group
The orderby specification is a string, not a list
Using a list as a orderby clause produces an error in the construction
of the group by query

closes odoo/odoo#42451

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-01-02 07:58:32 +00:00
Nicolas Vannieuwerburghandbeledouxdenis 75f91ca8e9 [FIX] Base: Don't crash on manual_field issue
closes odoo/odoo#42248

X-original-commit: abdc08d8d252647f388730ff84833249b5ef83a6
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: beledouxdenis
2019-12-20 11:13:31 +00:00
Raphael Collet 2448ff2c8c [FIX] models: avoid neverending recomputation on missing records
Assume F and G are computed by the same method on a missing record R.
During recomputation of F on R, the compute method is called but fails
because R is missing.  Both fields are re-marked to compute (because
computation failed), then F is discarded (because R is missing).  Then
comes G's turn: G is accessed on R and the computation fails.  Both
fields are re-marked to compute (because computation failed), then G is
discarded (because R is missing).  Now F is marked again to compute: the
process never ends.

To avoid this situation, discard all fields to recompute on missing
records.

closes odoo/odoo#42234

X-original-commit: 78bf4dbaa1c4adfa1dac68a4d79b87800003ac05
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-12-20 09:21:38 +00:00
Damien BouvyandRaphael Collet 220eb4db39 [IMP] base, web: support x_active for archiving
While x_name has long been automatically supported as an equivalent
of name, x_active was not.

This commit adds this behaviour OoB, both in the ORM and the web client.

On the ORM-side, a new `_active_name` attribute is supported on models.
This attribute specifies the field that should behave as an active marker
for records of the model. It is supported the same way `active` has been
until now (filtering by the `active_test` context key and toggled by the
`action_archive`, `action_unarchive` and `toggle_active` methods).
Although no check has been added on the field's type, it is assumed to
be a boolean field (the same way no check is present on the `(x_)name`
field).

On the client-side, the list view and form view now both support
detecting the presence of either `active` or `x_active` on records,
automatically adding an '(Un)Archive' button in the Action menu if such
a field is detected.

Note that the ORM implementation does actually need the field to be named
in any specific way, but since the web client has no mechanism to load
information regarding a model (the lifecycle of an action loading
includes loading the action, view and record(s) but no generic
information about the model itself besides what is included in the
views), we restrict the field's name to `(x_)active` to avoid confusion
as any other name would work at the ORM-level but not in the client.

In the future, the client might be able to more elegantly get
information about models, but this was not the scope of this change and
this solution should cover most cases.

Note that the `active` field will always takes precedence over the
`x_active` field to avoid confusing the polarity, even if both fields
are present on the model.

In the case of a custom field, it might be slightly annoying that the
default value of a Boolean field is `False`, which means that upon
adding the column, all existing records are automatically archived. This
can easily be worked around using an `ir.default` record for that
particular field and an update of existing records (e.g. through the
list view). The goal of this change was not to make it easy to add
support for custom active fields, but to make it possible - we have
therefore kept this implementation which introduces few changes while
adding enough flexibility for developers.
See https://twitter.com/zubair_shafiq/status/1202587553871880192?s=20
for more info regarding supporting any `_active_name` in the web client.

Co-authored-by: Raphael Collet <rco@odoo.com>
2019-12-20 11:16:01 +00:00
Raphael Collet 51d020e5fa [FIX] models: query blowup when unlinking many records
The method `unlink` checks whether any of the records to delete is used
as the default value of a company-dependent field.  The query simply
blows up when deleting several millions of records.  The fix consists in
performing the check in batches.

closes odoo/odoo#41331

X-original-commit: 30e8b8f2554e5d16b19f16ea90e3503098dc98a0
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-12-04 08:46:08 +00:00
Nans Lefebvre 5ea09c2ed8 [FIX] base: translate error messages at failed import
Forward-port of ffee5bdbd12b0080349da515d01981943355d0cd;
because of 1a315e87b05fcbdefcb3db6d8d4837f6cc3e835c by the same author,
only the following are left:
- we need to translate the untranslated message
- give the temporary cursor a name different from cursor or cr
  so that _'s _get_cr method does not get the closed cursor

closes odoo/odoo#41140

X-original-commit: 926873031d479ec96ca122fe8c3a481b31f2a32b
Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
2019-11-29 13:21:18 +00:00