Commit Graph
102 Commits
Author SHA1 Message Date
Raphael Collet 7f27992998 [FIX] fields: convert selection value to int
When a string value is assigned to a selection field expecting integers, the
value simply rejected.  In such a case, convert the value to an integer before
validating it.
2018-05-14 12:08:59 +02:00
Nicolas Lempereur 96ce375c61 [FIX] models: more than one prefetch in onchange
When a record fields are prefetched, the currently accessed record is
prefetched as well as PREFETCH_MAX (=1000) minus currenly accessed
records.

Since 439fa826 the id field was thought as "prefetched" but was not,
which caused that in an onchange, we would have a prefetching as follow
for 1200 records:

- get records 1-1000
- get record 1001 (1001-1200 INTERSECTION 1-999 (id) + 1001 (current))
- get record 1002 (1002-1200 INTERSECTION 1-999 (id) + 1002 (current))
- get record 1003 (1003-1200 INTERSECTION 1-999 (id) + 1003 (current))
- ...
- get record 1200 (1200 INTERSECTION 1-999 (id) + 1200 (current))

So we would do 201 queries instead of 2 when prefetching the records.

The added test without this change failed the query count with:

 "AssertionError: 284 not less than or equal to 5 : admin"

opw-1837548
opw-1837552
closes #24326
2018-04-20 10:54:29 +02:00
Raphael Collet c9caf55177 [FIX] models: bad setup of inherited custom fields
Assume a custom field F is defined on model 'res.partner'.  The setup of F may
silently fail because of missing stuff.  In that situation, setting up the
field inherited from F on model 'res.users' should also silently fail.

To reproduce the bug, install Invoicing, create a related custom field F on
'res.partner' with 'property_account_position_id.active', and install another
module.  Setting up F after loading module 'base' will fail because the field
'property_account_position_id' does not exist yet.  The error is not caught by
the inheritance of F on model 'res.users', and the installation crashes.
2018-04-19 10:00:49 +02:00
Christophe Simonis c921d94236 [MERGE] forward port branch saas-15 up to 3730a0d2df 2018-03-13 12:05:36 +01:00
Christophe Simonis 3730a0d2df [MERGE] forward port branch saas-14 up to 0e898eae35 2018-03-12 18:48:15 +01:00
Christophe Simonis 0e898eae35 [MERGE] forward port branch 10.0 up to 0440e25380 2018-03-12 18:16:02 +01:00
Nicolas Martinelli 2021f44c0e [FIX] fields: empty date or datetime
When the `create` or `write` method receives an empty string for a date
or a datetime field, PostgreSQL will fail since this is not an accepted
value for this field type.

We fallback on `None` for falsy values.

opw-1819336

@KangOl : watch out when forward-porting, the signature of
`convert_to_column` has changed in saas-14.
2018-03-12 12:01:42 +01:00
David Arnold 231cae2e7f [FIX] fields: copy_cache with failed values onto sudo env (#23122)
Do not copy failed values, as they usually reveal access error that should
not occur in the sudoed env.

Closes #23121
2018-03-12 10:14:01 +01:00
Raphael Collet b53c017052 [FIX] fields: use copy_cache during onchanges only
This fixes the bug introduced in rev 34c52e9938
that optimizes method `copy_cache`.
2018-03-05 11:25:37 +01:00
Raphael Collet 34c52e9938 [FIX] fields: performance of onchange on related fields
Optimize the copy of the cache being made by related fields to compute
themselves.  Instead of traversing records data in cache, follow the cache
structure itself and copy everything!

OPW 816125
2018-02-13 17:08:49 +01:00
Raphael Collet 309b6b8e5a [FIX] api: optimize odoo.api.Cache.get_records()
Assuming that `field.cache_key(record)` is independent from `record.id`,
compute the cache key once for all records, and avoid using `browse` on all
record ids.  This makes `get_records` about 20 times faster.

This has a good performance impact on `field.modified_draft()`, which is used
during onchanges for invalidating fields.
2018-01-11 13:52:16 +01:00
Christophe Simonis b37cc1f9b7 [MERGE] forward port branch saas-16 up to a2ea4ba095 2017-12-12 18:39:43 +01:00
Christophe Simonis a2ea4ba095 [MERGE] forward port branch saas-15 up to 5701010d0d 2017-12-12 16:15:04 +01:00
Christophe Simonis 5701010d0d [MERGE] forward port branch saas-14 up to 744c2934b3 2017-12-12 15:35:11 +01:00
Christophe Simonis 744c2934b3 [MERGE] forward port branch 10.0 up to 219c93252f 2017-12-12 14:49:29 +01:00
Christophe Simonis 219c93252f [MERGE] forward port branch 9.0 up to 7a24a2f45f 2017-12-12 14:15:15 +01:00
Raphael Collet 6da1c3ac4c [FIX] fields: performance of convert_to_onchange on x2many fields
Suppose we convert a x2many field `foo_ids` with a many2one sub-field `bar_id`.
The conversion of the values of `bar_id` generates pairs `(id, name)`.  Before
this patch, the method `name_get` is invoked on every value, one by one.
Rewrite the code to ensure that `name_get()` is invoked on all values at once.
2017-12-06 15:56:25 +01:00
Christophe Simonis b8540eefe3 [MERGE] forward port branch saas-15 up to 970be94f37 2017-12-05 16:46:14 +01:00
Christophe Simonis 970be94f37 [MERGE] forward port branch saas-14 up to e9c2dcd28d 2017-12-05 14:52:16 +01:00
Lucas Perais (lpe) 2a86e9245c [FIX][BACKPORT] Always round monetary values in database
backport of afef71d6b9

Original commit message:

Let `create` and `write` round monetary field values before sending them to the
database. Pass the values to be written to `field.convert_to_column`, so that
the currency can be retrieved from the values, and the value be rounded.
2017-12-05 13:46:06 +01:00
Christophe Simonis 1da064a1d3 [MERGE] forward port branch saas-16 up to 8ee9024a4c 2017-10-13 13:13:11 +02:00
Christophe Simonis aeae519a65 [MERGE] forward port branch saas-15 up to 945dd32eb0 2017-10-12 21:44:28 +02:00
Christophe Simonis 945dd32eb0 [MERGE] forward port branch saas-14 up to 91e2264b28 2017-10-12 18:43:14 +02:00
Christophe Simonis 91e2264b28 [MERGE] forward port branch 10.0 up to ba519bde84 2017-10-12 17:30:01 +02:00
Raphael Collet 10412d351c [FIX] fields: prefetching of related fields (#20017)
Prefetching is underused when all fields are traversed one record at a time.
So instead, traverse all records one field at a time.  This guarantees batch
prefetching/computation on every field being accessed.
2017-10-11 13:39:02 +02:00
Raphael Collet 0af8d4ffd2 [FIX] fields: performance optimization
Add a shortcut in `copy_cache`, to avoid iterating on all fields.
2017-10-11 11:55:02 +02:00
Christophe Simonis e1104ac344 [FIX] core: revert cb1cfadda2
Due to Cache reimplementation, this commit can't be applied as-it in
version 11.0 and need to be adapted correctly.

Undo PR #19963
2017-10-10 18:36:34 +02:00
Christophe Simonis 6c2ab192ea [MERGE] forward port branch saas-16 up to 88a9980b0c 2017-10-10 16:49:59 +02:00
Christophe Simonis 88a9980b0c [MERGE] forward port branch saas-15 up to 66945d3427 2017-10-10 14:15:24 +02:00
Christophe Simonis 66945d3427 [MERGE] forward port branch saas-14 up to 68d1ad5b7a 2017-10-10 13:27:29 +02:00
Christophe Simonis daa2194677 [MERGE] forward port branch 10.0 up to 0e28db88d1 2017-10-10 12:32:50 +02:00
Raphael Collet fcf6ef476c [FIX] fields: writing on a one2many with a domain should not remove all lines
Specifically, the command `(6, 0, ids)` should only unlink/detach the lines
that satisfy to the field's domain.

Test from #18440

opw-756983
2017-10-10 11:21:15 +02:00
Christophe Simonis 446ff1baf8 [MERGE] forward port branch saas-15 up to b60a41ce14 2017-10-09 17:54:36 +02:00
Christophe Simonis 6b0828b3bf [MERGE] forward port branch saas-14 up to 85c8000738 2017-10-09 13:24:17 +02:00
Christophe Simonis 85c8000738 [MERGE] forward port branch 10.0 up to cb1cfadda2 2017-10-09 12:44:22 +02:00
Raphael Collet cb1cfadda2 [FIX] fields: performance issue in copy_cache (#19963)
That function is called when computing related fields in onchange mode.
The new implementation makes a direct access to the cache's implementation.

opw-772303
2017-10-09 11:53:18 +02:00
Raphael Collet e671679183 [FIX] fields: do not use int() to retrieve record id
When reading a one2many field, the inverse field of the retrieved lines may
already be assigned in cache to a new record.  This can happen during an
onchange.  In that case, the algorithm crashes.  Let's clean it up!
2017-09-26 11:43:37 +02:00
Raphael Collet c6b184bb23 [FIX] fields: optimize many2many command (6, 0, ids) on new records
The command does not need to remove existing relations, as there is no relation
yet on new records.  This saves one query per many2many field with that command
in a `create`.
2017-09-21 16:10:13 +02:00
Raphael Collet 49f6a1b544 [FIX] fields: improve performance of many2many fields
An update by a list of commands is now guaranteed to have at most three SQL
queries to update the relation, whatever the number of commands and records.
2017-09-20 13:30:56 +02:00
Raphael Collet 886003af93 [FIX] models: in onchange, consider all levels of subfields 2017-09-13 10:12:16 +02:00
Raphael Collet d7190a3fd0 [IMP] api: reindex the record cache to improve cache hit
The record cache is indexed by `(field, record_id, key)`, where `key` depends
on the environment.  The key is either `(cr, uid, context)` or `(cr, uid)`,
depending on whether the field's value is context-dependent.  As most fields
are not context-dependent, this should avoid some cache prefetching when
swiching context.
2017-09-08 13:21:00 +02:00
Raphael Collet 32a58c0db3 [REF] api: wrap the record cache implementation into a class
This makes the rest of the ORM independent from the cache's implementation, and
rely on a well-defined API instead.
2017-09-08 13:21:00 +02:00
Raphael Collet 64e945aa44 [REF] models: make the API of RecordCache more consistent
Make `RecordCache` work on a single record only, and implement a mapping from
field names (only) to values.

Also add explicit methods on `RecordCache` to wrap special behavior in cache,
and simplify all special values as a wrapper for a getter function.

The record cache may contain regular and special values.  Modify `RecordCache`
so that only methods ending with `_value` check for regular values.  The
dictionary methods considers both regular and special values as equivalent.

    name in record._cache               # test if cache has a value
    iter(record._cache)                 # iterate on values
    record._cache[name]                 # get value
    record._cache.get(name)             # get value or default

    record._cache.has_value(name)       # test if cache has a regular value
    record._cache.get_value(name)       # get regular value or default
2017-09-08 13:21:00 +02:00
Raphael Collet 6cf98c4c87 [IMP] models: in onchange, keep track of virtual ids of new records
The x2many "create" command is now like: `(0, ref, vals)`, where `ref` is an
arbitrary reference that may be used to identify a new line in the relation.
The reference is returned in a similar command by the method `onchange`.
`onchange` now supports self-modifying x2many fields.
2017-08-30 14:38:29 +02:00
Olivier Dony 695716efb0 [FIX] P3: remove pycompat.{keys,items,values} helpers
Now that we're closer to switching to P3 for good, these helpers have
outlived their usefulness, and mostly add noise.

All remaining dict.iter*() or dict.view*() must be converted to the
normal keys(), values() or items() calls.

Whenever the result is likely to be used for more than the scope of a
loop, or when the dict needs to be modified during iteration, the calls
must be wrapped in a ``list()``, to protect the new P3 semantics.
Those cases are very exceptional.

Also removed some dead code or improved the API to remove unnecessary
conversions.
2017-08-20 23:25:54 +02:00
Xavier Morel 364becdab1 [FIX] P3: text/binary handling
* unichr -> pycompat (builtin removed from Python 3, ``chr`` has
  become unicode-aware)
* Psycopg2 bytea values (binary fields) are returned as memoryviews in
  P3 but buffers in P2
* Both bytes and (text) strings are conventionally iterable in
  P3 (they have a __iter__ method), so fix up the exclusion pattern
  for flatten
2017-08-20 23:25:54 +02:00
Xavier Morel 7dd062f835 [FIX] P3: text model types
* remove references to basestring & unicode (use relevant pycompat
  helpers)
* remove some str calls (either entirely or replaced by relevant
  helper, either text or native)
* use better API to avoid unnecessary conversions
* remove some XML declarations in views
2017-08-20 23:25:54 +02:00
Xavier Morel 3824b5dcc1 [FIX] P3: fix base64 and StringIO uses
* StringIO removed from stdlib, replace with io
* try to correctly handle BytesIO/StringIO (one is for bytes the other
  is for text)
* fix base64: Python 3 removed bytes-encoding and bytes-bytes
  codecs (via #encode) so replace all calls to str.encode('base64'),
  also b64encode is a bytes->bytes conversion so attempt to properly
  handle that

issue #8530
2017-08-20 23:25:54 +02:00
Christophe Simonis 48b2ce60ed [MERGE] forward port branch saas-16 up to 85571bb78c 2017-08-10 17:01:05 +02:00
Christophe Simonis 85571bb78c [MERGE] forward port branch saas-15 up to dde62073ba 2017-08-10 16:22:36 +02:00