Commit Graph

81 Commits

Author SHA1 Message Date
Raphael Collet 13b36ac677 [IMP] fields: in selection fields, 'selection_add' only adds options not in selection yet 2015-02-11 13:31:17 +01:00
Raphael Collet a11100adb8 [FIX] fields: new-api many2many fields always determine their table and columns
The mechanism to determine the table and column names of new-api many2many
fields only worked for many2many fields created from old-api many2many columns!

This fixes #4851.
2015-02-10 09:21:12 +01:00
Raphael Collet 4fd8e40ff7 [FIX] fields: add a flag "compute_sudo" to recompute fields as user admin
This reverts commit 8cd2cc8910.

It turned out that forcing recomputing fields as user admin breaks some
existing behavior.  Instead, we make the recomputation as user admin explicit
by adding compute_sudo=True in the field's definition.
2015-02-09 09:57:34 +01:00
Raphael Collet f650522bbf [FIX] fields: related fields should not be copied by default 2015-01-29 14:43:50 +01:00
Olivier Dony 8ea6ebede1 [IMP] fields: reduce verbosity of debug log for registry loading
This log line is only useful when debugging registry
loading, a limited use case now that Odoo 8 is stable.
It makes the debug log more difficult to read and causes
a small performance penalty when debug[_rpc] is on.
(+0.2s i.e. 10% extra time for loading a registry with 47
modules on a core i5-4200U machine)
2015-01-21 12:53:26 +01:00
Raphael Collet 431f8de815 [IMP] models: prepare the setup of fields at one place only 2015-01-21 11:26:23 +01:00
Raphael Collet 5fee95ca63 [FIX] models, fields: reorganize model setup to retrieve all inherited fields
The model setup sometimes misses entries in _inherit_fields and _all_columns.
This is because those dictionaries are computed from parent models which are
not guaranteed to be completely set up: sometimes a parent field is only
partially set up, and columns are missing (they are generated from fields after
their setup).

To avoid this bug, the setup has been split in three phases:
(1) determine all inherited and custom fields on models;
(2) setup fields, except for recomputation triggers, and generate columns;
(3) add recomputation triggers and complete the setup of the model.

Making these three phases explicit brings good invariants:
- when setting up a field, all models know all their fields;
- when adding recomputation triggers, you know that fields have been set up.
2015-01-21 11:26:23 +01:00
Raphael Collet 698981eccb [FIX] fields: do not set the inverse function on a readonly related field
This fixes #4681: prevent method copy() to write on the field.
2015-01-15 13:40:15 +01:00
Ajay javiya 5abcff8512 [FIX] fields: add minimal support for serialized fields in new API
This is necessary for supporting old-api sparse and serialized fields.  Without
this, old-api serialized fields are broken because they cannot be converted to
new-api fields.

This closes #4571
2015-01-07 16:34:50 +01:00
Denis Ledoux be5717434e [FIX] fields: apply user timezone in display name for models using a datetime as name
For models using a datetime field as name (hr.attendance for instance), the user timezone wasn't applied in the display name.
Therefore, in the breadcrumb, the datetime was different than in the form if the user had another timezone than UTC.

This rev. is related to 27d8cb843b, but is for the 8.0 api

We are aware we introduce a tiny change of API (method signature change), which we normally prohibit, but considering the really low level of the method, the fact it is probably not ovveriden by any other modules and the fact there is no cleaner way to correct this, we are making an exception.
2015-01-05 15:48:37 +01:00
Raphael Collet 058eaf01df [FIX] fields: make sure fields are set up before using them
Non-setup fields could cause problems in two places:
- when traversing the chain of fields in related fields;
- when adding recomputation triggers on inverse fields

Both issues are fixed by this patch.
2014-12-11 10:12:46 +01:00
Samus CTO 55fa50891d [FIX] Use _unknown model for missing models in relation fields
During a migration of database, it is possible that some custom field
("x_", state is 'manual') are relational to model from a module that is
not provided.

Note: this used to work in Odoo 7.0 but crashed in 8.0.

Closes #3877
2014-12-04 20:58:46 +01:00
Raphael Collet 591e329bb0 [FIX] fields: inherited fields get their attribute 'state' from their base field 2014-12-02 14:58:17 +01:00
Christophe Simonis de27e19794 [FIX] fields.py: in many2one convert_to_cache, value can be int but long as well 2014-11-27 17:06:48 +01:00
Christophe Simonis 9b670049b6 [FIX] fields.py: Many2one fields only put valid values in cache 2014-11-27 17:06:48 +01:00
Raphael Collet cd2a432362 Merge pull request #3645 from odoo-dev/8.0-fix2manyupdateonchanges-chs
[FIX] api: avoid to return all fields *2many in onchanges
2014-11-25 12:42:36 +01:00
Raphael Collet ebdbd9f8b7 [FIX] fields: in *2many convert_to_write(), return all fields for new records and dirty fields for existing records 2014-11-25 11:25:50 +01:00
Raphael Collet bc8c7596a5 [IMP] models: rework the API that deals with dirty fields on records 2014-11-24 15:31:18 +01:00
Xavier Morel ec7736a051 [ADD] ws doc: introspection, reports and workflows
* use static imports in java examples to make them terser
* inline ``domain`` in java and php example to make examples more
  self-contained
* try to extend/improve Model.write's docstring
* add convenience kwarg to fields_get, mostly for user-driven
  introspection

Closes #3689
2014-11-24 08:54:55 +01:00
Denis Ledoux 999ed04c40 [FIX] api: avoid to return all fields *2many in onchanges
When an onchange returns a change in a 2many field line (a '1' tuple, update), avoid to return all fields of the *2many field but only the altered field.

Otherwise, the web client regard all the fields of the 2many as dirty, and try to write on all fields (even if the value is the same, thus)

opw-615062
2014-11-14 14:24:11 +01:00
Raphael Collet e038fec696 [IMP] models: improve performance of _setup_fields()
There was an issue in _setup_fields(): the method invokes _inherits_reload(),
which recomputes inherited fields, and invokes itself recursively on children
models.  This may be problematic if the children models have already been set
up.

This optimization avoids recursive calls of method _inherits_reload().  In
_setup_fields(), first all parent models are set up, then their fields are
inspected to determine inherited fields, and their setup is done.  This scheme
guarantees that inherited fields are computed once per model.
2014-11-13 14:54:04 +01:00
Raphael Collet 54140331f3 [FIX] fields: fix the translations of the labels of inherited fields 2014-11-06 16:42:41 +01:00
Raphael Collet 5cc863245b [IMP] fields: improve _determine_default() and add test for inherited fields 2014-11-06 12:20:39 +01:00
Raphael Collet f2e4a10e1a [IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns.  This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...

This commit contains the following changes:

 - adapt several methods of BaseModel to use fields instead of columns and
   _all_columns

 - copy all semantic-free attributes of related fields from their source

 - add attribute 'group_operator' on integer and float fields

 - base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
   payment_acquirer, share, website, website_crm, website_mail: simply use
   _fields instead of _all_columns

 - base, decimal_precision, website: adapt qweb rendering methods to use fields
   instead of columns
2014-11-04 13:47:57 +01:00
Richard Mathot ef862084c9 [DOC] fields.py: oldname key 2014-11-03 18:09:16 +05:30
Raphael Collet 5eb6e58156 [FIX] fields: make field.store=False on old-style function fields
Clarify the semantics of field attributes:
 - field.store is True when the field is actually stored in the database;
 - field.column is the column corresponding to field or None.

The various field definitions correspond to:
 - new-style stored field: field.store and field.column
 - new-style non-stored field: not field.store and not field.column
 - old-style regular field: field.store and field.column
 - old-style function field: not field.store and field.column
2014-10-30 13:29:21 +01:00
Raphael Collet 8db5b84fc1 [FIX] fields: inherited fields should get 'string' from their parent field
Because some parameters of a field may be determined during its setup, we have
to update the corresponding column after the setup, and recompute _all_columns
to make it consistent.
2014-10-28 09:12:31 +01:00
Raphael Collet 4a65b61f2f [IMP] fields: remove unused imports 2014-10-23 10:35:27 +02:00
Raphael Collet ba1369fbef [IMP] fields: infer required=True on related fields
One can infer related=True on a non-stored related field if all fields on the
path are related.  This cannot be done if the related field is stored: when you
create a record, the database row is created first, and the related field is
computed and stored afterwards.  Making the field required in that case would
trigger a non-null constraint violation.
2014-10-23 10:28:13 +02:00
Raphael Collet 0873613767 [IMP] fields: initialized computed fields to a null value instead of a failed one
This should ease compute methods that assign a list to "update" a
one2many/many2many field.  With a failed value, the update crashes.
2014-10-23 10:14:24 +02:00
Raphael Collet 8e6d5beb35 [IMP] fields: reuse column objects when possible, instead of recreating them
This is a memory optimization: it reduces the memory footprint of each
registry.  We have observed a reduction of 10Mb on a database with modules crm,
sale, purchase, stock.
2014-10-22 16:22:39 +02:00
Denis Ledoux 0a82397da3 [FIX] fields: selection, do not try to translate label if label is empty
- translate with no source returns first translation for this field, whatever the source
 - performance
2014-10-22 11:54:22 +02:00
Raphael Collet 89031f5de6 [FIX] models: simplify partial setup of fields, let it crash silently
The setup of relational fields may be problematic, as they may refer to unknown
models via custom relational fields.  In a partial setup, do not try to skip
the field setup, but let it go and silently catch any exception if it crashes.
2014-10-15 11:39:12 +02:00
Raphael Collet 43abcb02ba [FIX] models: in _add_field(), set the field as an attr before setting it up
In the case of custom fields, the field's parameters were set up without the
field being present in the class hierarchy.  Because of this, the parameter
inheritance mechanism was missing the field itself.  As a consequence, custom
selection fields ended up without selection, for instance :-/
2014-10-14 11:56:59 +02:00
Raphael Collet 5db84cb07e [IMP] models: do not use compute methods to determine default values anymore
Compute methods could give results that should not be considered as default
values.  For instance, a related field usually defaults to a null value, which
is then set to the field with its inverse method by create().  This may violate
a non-null constraint if the original field is required.  Therefore, compute
methods are no longer used to determine default values.
2014-10-13 13:44:07 +02:00
Raphael Collet 8a9027edd1 [IMP] fields: do not force required=True on related fields
This may cause issues if the field is stored: non-null constraint will prevent
saving records when no value is provided.
2014-10-09 17:18:28 +02:00
Raphael Collet 1c9ed9f534 [IMP] fields: rename attribute 'copyable' into 'copy' 2014-10-09 15:05:15 +02:00
Raphael Collet 8ddf145559 [IMP] fields: do not copy field objects anymore, but make new instances instead
Because of the parameter overriding mechanism implemented by fields, it is no
longer necessary to copy field objects.  It is even better to no copy them in
the case of related fields.
2014-10-09 15:05:15 +02:00
Raphael Collet be894166ef [IMP] fields: add assertions to check parameters (comodel_name, size, digits) 2014-10-09 10:50:40 +02:00
Raphael Collet 36174fcc6e [IMP] fields: set the default value to the closest field.default or _defaults
This solves a subtle issue: in the following case, the class Bar should
override the default value set by Foo.  But in practice it was not working,
because _defaults is looked up before field.default.

    class Foo(models.Model):
        _name = 'foo'
        _columns = {
            'foo': fields.char('Foo'),
        }
        _defaults = {
            'foo': "Foo",
        }

    class Bar(models.Model):
        _inherit = 'foo'
        foo = fields.Char(default="Bar")

The change makes field.default and the model's _defaults consistent with each
other.
2014-10-09 09:18:02 +02:00
Raphael Collet 3f31081bc2 [IMP] fields: make attribute 'default' callable 2014-10-09 09:18:02 +02:00
Raphael Collet 619a844428 [FIX] fields: in to_column(), returning self.column is generally not correct
Consider the following example:

    class Foo(models.Model):
        _name = 'foo'
        _columns = {
            'state': fields.selection([('a', 'A')]),
        }

    class Bar(models.Model):
        _inherit = 'foo'
        state = fields.Selection(selection_add=[('b', 'B')])

The attribute 'column' of the field does not have the full selection list,
therefore the column object cannot not be reused, even a copy of it.  The
solution is to systematically recreate the column from the field's final
specification, except for function fields that have no sensible way for being
recreated.
2014-10-08 16:39:59 +02:00
Raphael Collet afb91fde81 [FIX] models: fields_get() shall not return info about fields not set up yet
When processing data files during a module installation/upgrade, not all fields
are set up yet, in particular relational custom fields.  Make fields_get()
ignore those fields, so that views can be created/updated and validated,
provided they do not refer to those fields...
2014-10-06 11:56:03 +02:00
Raphael Collet 53ff84493f [IMP] fields: allow sorting on inherited field in list views 2014-10-01 16:00:44 +02:00
Raphael Collet a69996b50c [IMP] fields: split multi-purpose '_origin' into 'column' and 'inherited'
This makes it easier to determine when a field interfaces a column, and when it
implements an inherited field (with _inherits).
2014-10-01 16:00:44 +02:00
Raphael Collet 34ba5154e2 [IMP] fields: split the default value from the compute function
This separation allows to set a default value on a related field, for instance.
2014-10-01 09:24:09 +02:00
Denis Ledoux 30a0814159 [FIX] fields: copy origin to avoid sharing field objects between registries
Fix a bug introduced in revision f229974, where shared columns objects are
systematically reintroduced in registries.
2014-09-30 14:32:35 +02:00
Raphael Collet 1f15055de3 [FIX] fields: a function field with fnct_search should be searchable 2014-09-24 18:41:20 +02:00
Raphael Collet 764c5acd81 [IMP] fields: reset decimal precision on new-style fields
When a decimal_precision record is created/modified, the float fields of the
models in the registry must be reset.  This was done on old-API columns only.
It is now handled by the new-API fields.
2014-09-18 11:11:19 +02:00
Raphael Collet 6e0c73d2ad [FIX] fields: make convert_to_cache() more robust with inverse one2many
When a one2many field uses an integer field as inverse, the onchange method on
the second model may receive a dictionary for the value of the integer field.
This is because the client expects that field to be a many2one.
2014-09-17 16:01:02 +02:00