Commit Graph

188 Commits

Author SHA1 Message Date
xmo-odoo 7c0e734785 [FIX] strip group name before calling has_group
user_has_groups is used to check for groups in e.g. view attributes (`@groups`).
When trying to format lists of groups in views, it would break down as it would 
pass e.g. `\n        some.group` to `res.users.has_group`, which would look for 
an xid with the module `\n        some` and (oddly enough) not find it.

Theoretically could also handle that inside res.users.has_group but it seems
ever-so-slightly more risky, and has_group is only used programmatically and 
should thus already be called correctly.

fixes #9797
2015-12-21 10:30:37 +01:00
Martin Trigaux 27d439901c [FIX] base: create translations of a duplicated record
When creating translations (click on blue flag) of a duplicated record, it used
to have the module information of the duplicated record.
It is also not useful to check the module when trying to find if a translation
exists on this record as the res_id is present in the query.

Fixes #9480
2015-12-02 10:57:46 +01:00
Raphael Collet 8e1a5add38 [FIX] api: improve decorator `returns` to handle special cases, like method `search`
Add the possibility in the decorator to specify the `upgrade` and `downgrade`
functions that convert values between APIs.  Both function have the same API:

    upgrade(self, value, *args, **kwargs)
    downgrade(self, value, *args, **kwargs)

The arguments ``self``, ``*args`` and ``**kwargs`` are the ones passed to the
method, following its new-API signature.

Fixes #4944, #7830.
2015-11-25 09:59:35 +01:00
Lionel Sausin 6188bc6e9d [DOC] Add words of caution about `sudo`
Closes #9655
2015-11-20 13:52:36 +01:00
Goffin Simon b00f0185a2 [FIX] models: read_group on many2one fields
When making on model A a read_group with groupby equal to a many2one field F1 to a model B
which is ordered by a inherited not stored field F2, the group containing all the
records from A with F1 not set was not returned.

Example:
model A= "hr.applicant"
model B= "res.users" (_order = "name,login")
inherited model= "res.partner"
field F1= "user_id"(to "res.users)
field F2= "name"(inherited from "res.partner")

In this example, the query generated by the function "read_group" was:

SELECT min(hr_applicant.id) AS id, count(hr_applicant.id) AS user_id_count , "hr_applicant"."user_id" as "user_id"
FROM "hr_applicant" LEFT JOIN "res_users" as "hr_applicant__user_id" ON ("hr_applicant"."user_id" = "hr_applicant__user_id"."id"),"res_partner" as "hr_applicant__user_id__partner_id"
WHERE ("hr_applicant"."active" = true) AND ("hr_applicant__user_id"."partner_id" = "hr_applicant__user_id__partner_id"."id")
GROUP BY "hr_applicant"."user_id","hr_applicant__user_id__partner_id"."name","hr_applicant__user_id"."login"
ORDER BY  "hr_applicant__user_id__partner_id"."name" ,"hr_applicant__user_id"."login"

which always returned "hr.applicant" groups of records with a "user_id" set due to the inner join maked on res_partners.

This inner join on "res_partner" is coming from function "add_join" calling by "_inherits_join_add"
in _generate_order_by_inner.

Introduced by dac52e344c

opw:651949
2015-10-16 12:11:31 +02:00
Raphael Collet e410d7d7e7 [FIX] orm: always save boolean function fields, even when they are false
Fixes #4292: searching for records when a related boolean field is `False`
always returns nothing.
2015-10-12 17:26:40 +02:00
Raphael Collet 25ea23eb31 [FIX] models: when accessing function fields in multi, read them all at once 2015-10-06 10:04:59 +02:00
Denis Ledoux 9671ae2a2d [FIX] models: onchange warnings concatenation
This revision is related 420e198aa5.

onchanges can return "False" as warning value.
In such a case, prevent the concatenation with previous results.
2015-09-28 14:45:29 +02:00
Denis Ledoux 420e198aa5 [FIX] models: multiple warnings in onchanges
If multiple warnings were returned by a cascading onchange
call, only the last warning was displayed.

This revision concatenates the warnings in such a case.

opw-649275
2015-09-28 12:06:29 +02:00
Raphael Collet 1a47ac3921 [FIX] models: fix write() on inherited field that is not a column of parent 2015-09-11 17:35:24 +02:00
Raphael Collet 1d314962fe [FIX] models: handle the case of `_constraints` with empty list of field names 2015-09-07 09:12:14 +02:00
Raphael Collet fa427f15b7 [FIX] models: performance of `mapped` is now in O(n) instead of O(n²) 2015-09-04 17:11:57 +02:00
Denis Ledoux 50f915f3ac [FIX] models: oversight introduced in 1658bee8d4 2015-09-04 13:27:29 +02:00
Denis Ledoux 1658bee8d4 [FIX] models: copy_data call in new API.
Context are frozendict in the new API.
Therefore, they cannot be altered.
Any attempt to alter a frozendict
will lead to a crash.

Fixes #7362
2015-09-04 13:17:34 +02:00
Olivier LAURENT 017688cc29 [FIX] models: old api, prevent infinite recursion in stored function fields
The risk was introduced by b7f1b9c.
IF _store_set_values() recall another _create() or _write(),
the recomputation mechanism enter in an infinite recursion
trying to reevaluate for each call exactly the same fields
for the same records than the previous one

This revision replaces the loop of _store_set_values()
by 2 nested loops:

 - that not breaks the entire consumption
   of recompute_old queue
   (Tested thanks to revision a922d39),
 - that allows to clear the queue
   before each recomputations bundle fixing thereby the recursion

Closes #7558
2015-08-31 17:45:21 +02:00
Christophe Simonis 7349e23837 [FIX] models: correct ORDER BY onm many2one fields
Now the we follow many2one when generating ORDER BY, we need to keep
track of visited relations to avoid loops.

Closes #8114
2015-08-20 11:44:04 +02:00
Christophe Simonis 856cb6fcb0 [FIX] models: distribute ORDER BY direction 2015-08-14 15:42:37 +02:00
Christophe Simonis dac52e344c [FIX] models: "ORDER BY" on many2one fields
When ordering results on a many2one fields, results are ordered by
order of the target model. The code was wrongly assuming that this
`_order` attribute only contains `_classic_read` fields (that can be
directly read from the table in database). Now correctly generate the
"ORDER BY" clause using the current table alias.

`res.users` can now be sorted by name.
2015-08-14 15:42:37 +02:00
Olivier Dony c96174da5f [MERGE] Forward-port of latest bugfixes from saas-3 up to 733cb3e76f 2015-08-04 15:22:49 +02:00
Olivier Dony df002518ee [FIX] models: access error due to prefetch of indirectly referenced records
Complements commit af9393d505
in light of commit 62b0d99cfe,
to really have the correct effect.

When the prefetching failed due to the presence of
extra records in the cache (for which the access is denied),
the `read` operation was indeed retried. However the
result was not stored in the cache because the cache
already held a FailedValue (automatically added when the
prefetch failed).
2015-08-04 00:00:31 +02:00
Christophe Simonis af9393d505 [FIX] orm: access error due to prefetch of indirectly referenced records.
The new-api record prefetching algorithm attempts
to load data for all known records from the requested
model (i.e. all IDs present in the environment cache),
regardless of how indirectly/remotely they were
referenced. An indirect parent record may therefore
be prefetched along with its directly browsed children,
possibly crossing company boundaries involuntarily.

This patch implements a fallback mechanism when
the prefetching failed due to what looks like an
ACL restriction.

The implementation of `_read_from_database` handle
ACL directly and set an `AccessError` as cache value
for restricted records.

If a model (like `mail.message`) overwrites `read` to
implements its own ACL checks and raises an `AccessError`
before calling `super()` (which will then call
`_read_from_database`), the cache will be not fill,
leading to an unexpected exception.

If this commit messae looks familiar to you, that's
simply because this is the new-api counterpart of
b7865502e4
2015-07-24 14:01:09 +02:00
andreparames 067fd2f342 [FIX] models: don't assume ids are ints in sorted()
Some models (e.g. calendar.event), use "virtual" ids which are not represented
as integers. It was not possible to use sorted method on those models as calling
int() is failing.

This commit fixes the method, making it agnostic to the type of the
'id' member variable.

Fixes #7454
2015-07-08 15:00:32 +02:00
Xavier Morel 95e56a109d [ADD] doc: new theme
Pretty much completely rewritten theme with custom HTML translator and a
few parts of the old theme extracted to their own extensions.

Banner images thought not to be that huge after all, and not worth the
hassle of them living in a different repository.

co-authored with @stefanorigano
2015-07-07 11:22:50 +02:00
Leonardo Donelli 207cf92a0c [DOC] openerp: add missing parameter for search method
The `search` method of models has an additional keyword parameter, `count`.

It not being specified in the docs could lead people to inherit `search`
without defining it, which would result in a `TypeError` when called with
`count=`.

Closes #7451
2015-07-06 14:26:46 +02:00
Martin Trigaux 2758aaa6f8 [IMP] models: sanitize error messages in import
Revert 83282f2d for a cleaner sanitizing earlier in the generation of the error
message.

If the import is failing, the error message contains the value that is
problematic. Escape this value in case it contains '%'
2015-07-01 17:04:48 +02:00
Mohammad Alhashash 83282f2dea [FIX] models: Escape `%` characters from error messages of a failed import
To prevent susbtituion exception when creating use error message
e.g. No matching record found for external id 'fo%o' in field 'Bar'
Fixes #5933
2015-06-29 16:50:33 +02:00
Raphael Collet 4a5e2fe99e Merge pull request #5618 from acsone/8.0-fix-5616-ir_model_fields-from-fields
[FIX] model: use self._fields instead of self._columns to populate ir.model.fields
2015-06-09 09:51:49 +02:00
Raphael Collet 78a20a3dba [FIX] model: wrong alias used in read query for multi-inherited field
In commit 04ba0e99, we introduced an optimization for reading inherited fields
in a single query.  There is an issue when you have more than one level of
`_inherits`.  The query looks like:

    SELECT ...
    FROM table0, table1 AS alias1, table2 AS alias2
    WHERE table0.link0 = alias1.id AND table1.link1 = alias2.id AND ...
                                       ^^^^^^
                             should be alias1

This fixes the issue, and adds a test to reproduce it.  The fix is based on
@emiprotechnologies's own proposal, but is cleaner and does not break APIs.
2015-05-12 13:42:27 +02:00
Denis Ledoux b7f1b9c01e [FIX] models: recompute nested old-style computed field
The `set` method of the one2many class returns a list
of the fields that require recomputation,
the computing of the function fields being delayed
for performances reasons.

Nevertheless, if the `set` method was called
through another `set` method, in other words,
nested `set` calls, the fields to recompute returned
by the second, nested, call to set were never recomputed,
the result list were simply lost.

e.g.:
```
create/write
│set
└─── create/write with recs.env.recompute set to False
    │set
        └─── create
             with recs.env.recompute set to False
```

To overcome this problem, the list of old api style
compute fields to recompute is stored
within the environment, and this list is cleared
each time the store_set_value has done its job of
recomputing all old api style compute fields.

opw-629650
opw-632624
closes #6053
2015-05-06 17:25:44 +02:00
Raphael Collet 1a535b9d87 [IMP] models: in recompute, do not store fields that should not be recomputed
Consider a new field that uses the same compute method as another existing
field.  When the field is introduced in database, its value must be computed on
existing records.  In such a case, the existing field should not be written, as
its value is not supposed to have changed.  Not writing on the existing field
can avoid useless recomputations in cascade, which is the reason we introduce
this patch.
2015-05-06 15:24:39 +02:00
Raphael Collet 0c665edb66 [FIX] models: make sure an environment is available when we access field.digits
Accessing `field.digits` can crash if no environment is available at that
point.  This happens in function `get_pg_type()`, which is called from method
`_auto_init()`.  An environment is simply created in the method's scope to be
available for `field.digits`.
2015-05-05 17:33:16 +02:00
Anthony Muschang 2925bb5c9a [FIX] models: Always use MissingError when a document is missing
As done in write and already in next version (see 0fd773a), accessing a deleted
record (through read or check access rights) should always return a MissingError
instead of the generic except_orm.
This will allow code ignoring deleted record (e.g. 'recompute' method) to safely
process the other records.
Fixes #6105
2015-05-04 13:39:21 +02:00
Sylvain Calador fa18530210 [REF] Add a hook for import fake fields
Used during records extraction phase of import (CSV)

closes #6188
2015-04-29 10:42:56 +02:00
Christophe Simonis 14fd77c132 [FIX] core: ormcache is now per regisry.
A cross-registry cache was introduced by e2ea691ce.
The initial idea was praiseworthy but sub-optimal for servers with a
lot of registries.
When there is lot of registry loaded, the cache size was huge and
clearing some entries took a lot of CPU time, increasing the chances
of timeout.

Also, the cache was not cleaned when a registry is removed from
registry LRU (this operation would also consume time).
2015-04-03 16:11:57 +02:00
Raphael Collet 9a365e83e7 [FIX] models: do not prefetch fields while the model schema is created
The following case has shown the issue: extend the model `res.company` by
adding at least two fields F and G, where F has a default value defined as:

    lambda self: self.env.user.company_id.name

If the column F is created before G in the database, the existing records will
be filled with the default value of F.  When the default value is computed, the
field `name` from a `res.company` is read, and other fields are prefetched,
including G.  This operation fails, because G does not exist in database yet!
2015-04-02 16:54:39 +02:00
Raphael Collet 93c341a52c [IMP] models: avoid using `map` instead of a `for` loop (thanks chs@odoo.com) 2015-03-23 14:36:15 +01:00
Raphael Collet f93a14e3b2 [IMP] fields: remove comments about `_all_columns`, and improve its docstring 2015-03-23 14:36:15 +01:00
Raphael Collet ffa7f28d34 [IMP] fields: reduce memory footprint of list/set field attributes
The optimization consists in using tuples for attributes `inverse_fields`,
`computed_fields` and `_triggers`, and to let them share their value when it is
empty, which is common.  This saves around 1.8Mb per registry.
2015-03-23 14:36:15 +01:00
Raphael Collet 9aad3d873b [IMP] fields: turn field.digits and column.digits into dynamic properties
The computed value of parameter digits is no longer stored into fields and
columns; instead the value is recomputed everytime it is needed.  Note that
performance is not an issue, since the method `get_precision` of model
'decimal.precision' is cached by the orm.  This simplifies the management of
digits on fields and saves about 300Kb per registry.
2015-03-23 14:36:15 +01:00
Raphael Collet bf703fd9a3 [FIX] models: reorder the base classes of models following an equivalent class hierarchy
Sometimes, the expected mro of the model is not the same as the one built with
a binary class hierarchy.  So we reorder the base classes in order to match the
equivalent binary class hierarchy.  This also fixes the cases where duplicates
appear in base classes.
2015-03-23 14:36:14 +01:00
Raphael Collet 9bce04de79 [IMP] models: build a flat hierarchy of classes for models
Instead of composing classes in a binary tree hierarchy, we make one class that
inherits from all its base classes.  This avoids keeping intermediate data
structures for columns, inherits, constraints, etc.  This saves about 600Kb per
registry.
2015-03-23 14:36:14 +01:00
Raphael Collet 0f9b452c33 [IMP] models: convert deprecated model._all_columns into a dynamic property
The mappings model._all_columns takes quite some memory (around 2MB per
registry) because of the numerous dictionaries (one per model) and inefficient
memory storage of column_info.  Since it is deprecated and almost no longer
used, it can be computed on demand.
2015-03-23 14:36:14 +01:00
Raphael Collet e2ea691cef [IMP] ormcache: turn it into a global LRU cache shared among registries
The ormcache is now shared among registries.  The cached methods use keys like
(DBNAME, MODELNAME, METHOD, args...).  This allows registries with high load to
use more cache than other registries.
2015-03-23 14:36:14 +01:00
Raphael Collet 6aa28a89bb [FIX] models: compute many2many field on existing records when field is introduced by an update 2015-03-18 09:43:45 +01:00
Thomas Groutars 3923f4051d [FIX] models: propagate context in action returned by get_formview_action
When opening a record from a many2one,
the context is not propagated to fields_view_get.
This is a problem if you set "form_view_ref" in the context for example.

opw-629628
2015-03-12 15:13:44 +01:00
Julien Laloux a20545a936 [IMP] web: add no update info on metadata view (debug mode) 2015-03-11 11:10:42 +01:00
Laurent Mignon 6915ded51b [FIX] fixes #5616: use informations from self_fields to populate the ir.model.fields
Fields declared with the new API are converted to column only if they are storable. Use the informations from the field definitions to fill the ir.model.fields table since columns only contains stored field
2015-03-05 22:08:51 +01:00
Raphael Collet 04ba0e99a4 [IMP] models: in _read_from_database(), fetch inherited fields when possible
This should improve the performance of method read() on models with inherited
fields, like product.product.  The inherited fields that are stored as columns
in parent tables (except for translated fields) are read in the same query as
the fields of the model.  Those fields will be directly stored in cache under
the main model, so that no copying will take place in cache for accessing them
(this is the default implementation of inherited fields).
2015-03-03 13:18:04 +01:00
Raphael Collet 2c261a2987 [IMP] models: in _read_from_database(), use the Query object to build the query
This makes the query construction more robust, as it handles joins for
conditions and ORDER BY clauses.  It also makes it easier to read() from
several tables (like inherited fields).
2015-03-03 13:18:04 +01:00
Christophe Simonis e6396deb4e [IMP] models: log source when "Comparing apples and oranges" 2015-02-27 15:57:13 +01:00