Commit Graph

188 Commits

Author SHA1 Message Date
Raphael Collet 068d4c487e [IMP] models: name_search() should call _name_search()
This avoids code duplication between methods, and keeps backward compatibility
with existing code overriding _name_search().
2014-08-06 15:21:58 +02:00
Mohammed Shekha e106ef91ef [FIX] Exporting of res.partner works again
Singleton object was required while access model properties, but search returns multiple results and hence caused traceback while accessing record.property
2014-08-06 14:10:00 +02:00
Raphael Collet 4c18c5fb6e [FIX] fields: convert_to_cache() on *2many fields must take record's current value
The existing code was buggy when writing on *2many fields with a list of
commands: the value was converted for the cache, but taking an empty recordset
as the current value of the field.
2014-08-06 09:07:57 +02:00
Raphael Collet 54b901effd [IMP] models: turn _patch_method() and _revert_method() into class methods
This makes the patching mechanism more flexible, and enables patching BaseModel,
for instance. This should fix #1501.
2014-08-05 15:20:14 +02:00
Samus CTO 5f6fc4735a [IMP] Do not create FK when destination model is _auto=False
It is not useful to try to create foreign keys when the destination model is
a PostgreSQL view for example.
We already do this kind of verifications but ir.actions and transient models
but did not for _auto.
2014-08-05 15:02:23 +02:00
Raphael Collet a1d0394ff4 [FIX] models: default_get() shall not return a dict as a many2one value
When a new record is returned as the value for a many2one on a new record, the
method Many2one.convert_to_write() now returns a NewID, and default_get() then
discards that value from its result. This makes it consistent with its former
behavior.

Manual rebase of #1547
2014-08-04 15:50:04 +02:00
Raphael Collet 2d2274aeed [FIX] module loading: manual x2x fields can now refer to manual models
The fix consists in this: when setting up models, ignore manual fields that
refer to unknown models if all models have not been loaded yet.
2014-08-04 15:10:12 +02:00
Olivier Dony d706adba11 [MERGE] Forward-port saas-5 up to 37ba23d 2014-08-04 01:44:30 +02:00
Olivier Dony 494ecc620f [MERGE] Foward-port saas-5 up to ee4df1e 2014-08-01 14:24:07 +02:00
Raphael Collet fa38c0f6a6 [FIX] models: fixes #1017; do not update list in place in the construction of _depends on models 2014-07-30 13:59:14 +02:00
Olivier Dony 77769ce74d [IMP] BaseModel: new `_translate` attribute to disable translations
Can be defined to False in any model to completely
disable translations for this model, when they are
irrelevant. This is useful e.g. for test classes
that use attributes that would normally be translatable.
2014-07-30 13:24:39 +02:00
Martin Trigaux f138aa2608 [FIX] models: display_name and name_get mismatch
- display_name uses name_get and not the other way around:
name_get should not call _compute_display_name, _compute_display_name should call name_get.
The previous behaviour was not backward-compatible with the old api.
All the models redefining name_get would have 2 different behaviors between name_get and display_name.

- Do not set an inverse function to display_name:
In most cases, writing on display_name writes on _rec_name (if any, not mandatory).
If the display_name computation is redefined, we need to redefine as well the inverse method to avoid unexpected behaviour
This required to also modify tests in base_import as readonly fields are avoided.

- Remove search method on display_name:
For the same reason as for the first point, it could be good that searching on display_name use name_search (and not the other way around).
However doing this would be very inefficiant (need to do the search, without limit, extract the ids of the name_get result just to generate
a subdomain ('id', 'in', [...]). As in most cases it would anyway mean to search on the _rec_name it's better to directly do so.

- Changing label to avoid mismatch:
In view displaying the list of fields or when a match is made on the label of a field (e.g. when importing csv file,
matching is made on both label and technical name), the fact that display_name field has '
Calling it 'Display Name' will avoid most errors.

- remove display_name definition from website_forum_doc,ir_model:
These fields are doing the same thing as the display_name of the new api, we can remove them.
We need to keep the one for res.partner as it's a stored field.
2014-07-25 13:58:59 +02:00
Olivier Dony 6d2fb3e3ae [FIX] models: check harder that default value is not NULL before setting it
When computing defaults we may end up with
a falsy value that is not None (e.g. '' or False)
That value will be cast to None when being
saved in the database, depending on the column type
(e.g. saving False on a many2one actually stores NULL).

Improve the test to consider the value being written
*after* that conversion, to *really* avoid nonsensical
and expensive queries such as:

    UPDATE table set col = NULL WHERE col IS NULL;
2014-07-24 15:47:34 +02:00
Olivier Dony 8974e928fa [FIX] fields: do not revalidate field values unless they are being modified
In the previous implementation of the new API fields,
both fields.Selection and fields.Reference were performing
early validation of their `value` as soon as it entered
the cache, either by being read, written, or computed.
This is a source of trouble and performance problems,
and is unnecessary, as we should consider that the database
always contains valid values. If that is not the case it
means it was modified externally and is an exception that
should be handled externally as well.

Revalidating selection/reference values can be expensive
when the domain of values is dynamic and requires extra
database queries, with extra access rights control, etc.

This patch adds a `validate` parameter to `convert_to_cache`,
allowing to turn off the re-validation on demand. The ORM
will turn off validation whenever the value being converted
is supposed to be already validated, such as when reading it
from the database.
The parameter is currently ignored by all other fields,
and defaults to True so validation is performed in all other
caes.
2014-07-23 12:30:24 +02:00
Christophe Matthieu 6e6f12144d [IMP] model: when the orm create/update a table check if they are at least one row of the table to load column default values 2014-07-17 18:46:10 +02:00
Christophe Matthieu 82a1ea0935 [FIX] model: The user install / update / test is different from the normal mode (no prefetch in test mode) some errors are hidden. 2014-07-17 18:46:09 +02:00
Xavier Morel b1f1596aef [FIX] "prefetching" removing even the records specifically asked for
16d6744 turns out to not be great, because it filters out the todos for
prefetched fields (rather than those just for the field being asked) there are
situations where it ends up not fetching the records it was originally asked
for and breaks a bunch of stuff e.g. unreconcile line in bank statements

Force the ids explicitly asked for back in the fetched set, so that the
prefetch is at most a noop, rco will have to take an actual look at it.
2014-07-16 16:29:24 +02:00
xmo-odoo 16d67445da Merge pull request #1076 from xmo-odoo/8.0-shop-fix-xmo
Fix access rights issues in new API for the shop home page
2014-07-16 10:28:51 +02:00
Christophe Simonis a5419ca800 [MERGE] forward port of branch saas-5 up to e0759c1 2014-07-15 11:21:59 +02:00
Xavier Morel 3491b7de34 [REM] cache setting in _prefetch_field 2014-07-14 10:45:34 +02:00
Xavier Morel 269a6ee128 [FIX] filtering out of records which shouldn't be fetched/prefetched
A todo would only filter out records selectioned by the same field's caching,
it should filter out on the whole prefetching selection or an other field
could/would just add it back to the set of records to fetch (and lead to Bad
Things).

Note: this probably deserves a test somehow, but I'm not quite sure how the
todos thing works so...
2014-07-11 14:07:05 +02:00
Xavier Morel 785018cc9c [FIX] only prefetch other cached records with read field uncached during _read_from_database
If expansion of the recordset is done during _prefetch_field, if one of the
prefetches (not the base record(s) but one of those selected by
BaseModel._in_cache_without) can't be read by the current user (due to an
access rule or for field reading reasons, or whatever) the whole read is
failed, even if the record which was specifically asked for could be read on
its own.

By only expanding the read set in _read_from_database, the cache is correctly
set but read() and _prefetch_field() only check the records explicitly asked
for for AccessDenied, prefetched records will only be asked if they are ever
accessed.

fixes #1013
2014-07-11 13:54:01 +02:00
Christophe Simonis f654a7719b [MERGE] forward port of branch saas-5 up to 73d39a0 2014-07-10 22:49:53 +02:00
Raphael Collet 836245564a [IMP] models: iterating over record._cache also returns log_access fields 2014-07-09 15:34:51 +02:00
Raphael Collet 643be98fcf [FIX] models: store FailedValue in cache on log_access fields, too
This should fix an issue discovered by tde when reading all fields on a record
on which you don't have access right:
 - _read_from_database() fetches result and store it in cache
 - read() retrieves values from cache, starting with field 'create_date'...
 - ... which is not in cache, so prefetch that field, read it, which goes into
   an infinite loop

The problem is that _read_from_database() finds out that you don't have access
on the record, and stores a FailedValue in cache on all fields... except magic
fields. Fix the problem by storing the FailedValue on all fields but 'id'.
2014-07-09 15:23:15 +02:00
Raphael Collet ca1be04d7a [FIX] models: wrong var used in _compute_display_name(), fixes issue #1002 2014-07-09 10:26:01 +02:00
Raphael Collet 34dac62d32 [IMP] models: add an extension mechanism for attribute _depends on models 2014-07-08 14:52:23 +02:00
Raphael Collet a6b025d6d9 [FIX] models, fields: add model dependencies for models backed up by sql views 2014-07-08 10:16:16 +02:00
Raphael Collet e9fae40faf Merge pull request #976 from odoo-dev/8.0-fix-model-init-rco
[FIX] models: reorganize model instantiation
2014-07-07 20:37:11 +02:00
xmo-odoo 957c0cca1c Merge pull request #970 from xmo-odoo/8.0-remove-unnecessary-listifications-xmo
Remove redundant calls to list()
2014-07-07 16:15:23 +02:00
xmo-odoo 48c16e4b26 Merge pull request #969 from xmo-odoo/8.0-fix-weakset-listification-xmo
Unsafe listification of weakref in Python < 2.7.4
2014-07-07 16:15:02 +02:00
Raphael Collet 09f094ff7f [FIX] models: reorganize model instantiation, which was broken when adding custom fields 2014-07-07 15:47:27 +02:00
Raphael Collet 130f890215 Merge pull request #964 from odoo-dev/8.0-remove-getattr-rco
[REM] models: remove the magic methods signal_XXX()
2014-07-07 14:49:49 +02:00
Xavier Morel efe910569a [REM] unecessary calls to list()
* Either further operations don't really care (e.g. ``str.join`` takes any
  iterable)
* Or they do their own seq (``browse`` calls ``tuple()`` on iterable params)
2014-07-07 14:01:07 +02:00
Xavier Morel ac282e0294 [FIX] unsafe listification of weakref in Python < 2.7.4
Fixes #966

* As a preallocation optimization, ``list()`` calls ``__len__`` on its
  parameter if it's available
* Before Python 2.7.4, WeakSet has a bug[0] where ``len()`` is unsafe: it is
  done by iteration and weakrefs may be removed from the underlying set during
  the iteration

As a result, the safety feature of listifying a WeakSet to ensure we have
strong refs on all items during iteration may blow up.

Wrapping the weakset in a ``iter()`` makes ``__len__()`` invisible and ensures
we're within the IterationGuard[1].

Which now that I think about it means we *should* be able to safely iterate
weaksets in the first place and may not have needed to listify them...

[0] http://bugs.python.org/issue14159
[1] http://hg.python.org/cpython/file/b6acfbe2bdbe/Lib/_weakrefset.py#l58
2014-07-07 13:51:53 +02:00
Raphael Collet 33eb3dffb2 [REM] models: remove the magic methods signal_XXX() 2014-07-07 11:50:30 +02:00
Xavier Morel 798ce97df4 [IMP] raise exception when a DB request fetches ids it was not asked for
Likely caused by a type incoherence e.g. providing an id as string when the
table uses integer ids. Postgres performs an implicit conversion from string
to integer[0], this wasn't much of an issue in the old API, whatever cache was
there would simply not be used, but because the new API's cache is part of its
behavior it has a semantic impact and can lead to infinite recursion.

[0] more precisely from quoted value, which is untyped
2014-07-07 09:59:05 +02:00
Raphael Collet cbe2dbb672 [MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.

- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
2014-07-06 17:05:41 +02:00