Commit Graph

22 Commits

Author SHA1 Message Date
Olivier Dony bd3df7bfa1 [FIX] orm field (new api): preserve empty values instead of folding to False
The new API introduced a small behavior change where empty
string values written or stored in a char/text field were
replaced by False (i.e. as if they were NULL).
This was done to mimic the web client behavior, but introduces
a very surprising effect: a.name = ""; assert a.name == "";
would fail. It would also require many more tests in the
code when reading existing required values from the database,
as they could still be False when an empty string value
had previously been stored, for some reason.
2014-08-13 10:44:05 +02:00
Raphael Collet 9363dfe1ef [FIX] fields: generalize inverse_field to a list of inverse fields
Some many2one fields happen to have several corresponding one2many fields,
typically with different domains. It is also the case for the field 'res_id' of
mail.message, where each model inheriting from mail.thread defines a one2many
based on that field. The fix ensures that when a relational field is updated,
all its inverse fields are invalidated.
2014-08-08 14:57:00 +02:00
Olivier Dony 4c8c722401 [IMP] fields.Date[Time]: convert_to_cache: avoid costly parsing when not validating
The extra parsing check is not necessary when we're
not validating inputs, because in that case the
values come from the database and are valid.
The validation is quite expensive due to calls
to strptime() + strftime().
2014-08-07 18:24:29 +02:00
Olivier Dony 935c476664 [IMP] orm.Field: doc for @copy attribute 2014-08-07 18:03:08 +02:00
Christophe Simonis 5bd3c02bec [FIX] fields.py: handle "change_default" and "deprecated" attributes in new fields 2014-08-07 13:04:26 +02:00
Olivier Dony f062eec639 [FIX] orm: _compute_related: ensure prefetch is done in batch
Due to the use of a sudo env, the records
were being added to the sudo cache one by
one instead of all at once. This meant the
prefetching was not able to load all
records at once, leading to prohibitive
times when processing thousands of
records.
2014-08-06 18:48:35 +02:00
Raphael Collet e95fc488db [IMP] fields: add mechanism to extend a selection field
If a selection field is defined by a list as selection, such as:

    state = fields.Selection([('a', 'A'), ('b', 'B')])

one can extend it by inheritance by redefining the field, as:

    state = fields.Selection(selection_add=[('c', 'C')])

The result is that the selection field will have the list
[('a', 'A'), ('b', 'B'), ('c', 'C')] as selection.
2014-08-06 15:20:07 +02:00
Christophe Simonis dc9bcf479d [FIX] Allow search on `_inherits` fields.
As `_inherits` fields are now handled via `related`
fields (not stored, obviously), a new descriptor
`searchable` has been added to `fields_get()` result
to indicated if the field is searchable or not.
2014-08-06 15:01:01 +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
Olivier Dony c5b517696d [IMP] base: improved doc for `states` attribute of fields
See #1527
2014-08-04 18:20:13 +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
Raphael Collet 35d50f0390 Merge pull request #1284 from sebalix/8.0-fix-xmlrpc-marshall-none
[FIX] read() method returns None values instead of False, incompatible with XML-RPC
2014-07-30 15:05:03 +02:00
Olivier Dony 57f79f9fa1 [REM] fields: remove fields.Any, temporary artifact for ill-typed fields
This was added in master-apiculture at f1f16a8 to
permit special function fields that return
structured JSON-like data.
This is unnecessary and caused typing problems, for
example for the type field of ir.model.fields, or
when you decide to store them.

It is simpler to explicitly declare these fields
as fields.Char and have them serialize their results
to JSON strings, or to declate them as fields.Binary
and return any opaque data they want.
2014-07-30 13:24:39 +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
sebalix 3f59135dce [FIX] read() method returns None values incompatible with XML-RPC 2014-07-20 16:06:50 +02:00
Raphael Collet 9ccdbcaca3 Merge pull request #989 from odoo-dev/8.0-sql-models-rco
[FIX] models, fields: add model dependencies for models backed up by sql views
2014-07-08 16:27:01 +02:00
Raphael Collet 603bde1b1b [IMP] fields: improve code in former commit 2014-07-08 15:52:02 +02:00
Raphael Collet b05cf32b8f [IMP] fields: add missing case for invalidating fields, when path is None 2014-07-08 15:47:44 +02:00
Raphael Collet 3fdc232352 [FIX] fields: add a type to field Id; this fixes #990 2014-07-08 13:29:45 +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 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