Commit Graph

188 Commits

Author SHA1 Message Date
Raphael Collet 0c1b95d824 Merge pull request #5439 from guewen/test-inherits-3-levels
Reload fields of parent inherits, fixes #5398
2015-02-26 10:06:31 +01:00
Guewen Baconnier 608e58cce1 Reload fields of parent inherits, fixes #5398 2015-02-24 10:34:09 +01:00
Christophe Simonis a6a1764b2c [FIX] models: initialize `_fields` attribute.
Custom fields can point to custom models that have not been initialized
yet (`_setup_base` not called). Ensure every models in the registry
have a `_fields` attribute.
Use a `frozendict` as a defensive check to ensure it wont be modified
before calling `_setup_base`.
2015-02-23 18:33:26 +01:00
Raphael Collet 121b8e6800 [FIX] models: in onchange, false changes where detected in many2many fields
This was due to secondary fields loaded from database in 'onchange' mode.  In
that mode, the secondary fields were marked 'dirty', and therefore returned by
the method `onchange`.  The fix consists in loading those secondary fields in
cache before processing the onchanges.

This incidentally fixes a test on method `onchange`: in a one2many field, some
dirty fields were unexpectedly returned in the result.  This was due to those
fields being loaded while processing onchanges.
2015-02-21 11:29:13 +01:00
Raphael Collet 9333c622e9 [FIX] fields: allow overriding of a old-api function field
When overriding a field defined as a function field, the field must either
create a corresponding column that is not a fields.function (if stored), or
have no corresponding column (if not stored).
2015-02-19 15:33:27 +01:00
Raphael Collet bf99f434c8 [IMP] models: speed up loading by computing `_constraint_methods` and `_onchange_methods` lazily 2015-02-18 16:43:20 +01:00
Raphael Collet 45a37b22fd [IMP] models: speedup loading of registry (-20%)
Idea: look up for the model's fields in method `_setup_base()` instead of
method `__init__()`.  This does not make a significant difference when
installing or upgrading modules, but when simply loading a registry, the
(expensive) field lookup is done once per model instead of once per class.
2015-02-18 16:43:20 +01:00
Denis Ledoux c9154e08aa [FIX] api: environment recomputation
In a workflow context (for instance, in the invoice workflow),
context is not passed.

Therefore, relying on the 'recompute' key being the context
in order to not recompute the fields does not work with Workflows.

It leads to huge performance issues,
as fields are recomputed recursively (instead of sequentially)
when several records are implied.
For instance, when reconciling several invoices with one payment
(100 invoices with 1 payment for instance),
records of each invoice are recomputed uselessly in each workflow call
(for each "confirm_paid" method done for each invoice).

With a significant number of invoices (100, for instance),
it even leads to a "Maximum recursion depth reached" errror.

closes #4905
2015-02-12 14:57:31 +01:00
Raphael Collet 75ca4f8b71 [FIX] models: in onchange(), do not assign field 'id' on record 2015-02-11 12:45:18 +01:00
Raphael Collet 3a44d84b0f [FIX] models: inherited fields must be copied iff their original field is copied
This fixes a bug introduced by commit f650522bbf
(related fields should not be copied by default).  Inherited fields are a
particular case, and given the implementation of copy(), they must be copied if
their original field is copied.

The test on copy() in test_orm has been modified to show the bug.
2015-02-11 12:23:11 +01:00
Raphael Collet ac0eec6c99 [IMP] models: in recompute(), only save stored fields to database 2015-02-11 10:49:17 +01:00
Raphael Collet 6cf7bc8838 [FIX] models: invoke old-api onchange methods with context
This helps fixing old-api onchange methods with a record id as a parameter.
Browsing this record id may be problematic, since it reads the record in an
environment with an empty context.  This is really problematic when the record
is a new record, because such a record only exists in a given environment.
2015-02-11 09:29:51 +01:00
Raphael Collet 2067a206ec [FIX] models: process onchange methods on new records in the order of the view
The onchange() on new records processes fields in non-predictable order.  This
is problematic when onchange methods are designed to be applied after each
other.  The expected order is presumed to be the one of the fields in the view.

In order to implement this behavior, the JS client invokes method onchange()
with the list of fields (in view order) instead of False.  The server then uses
that order for evaluating the onchange methods.

This fixes #4897.
2015-02-10 13:12:40 +01:00
Christophe Simonis 7ab70cab74 [IMP] models.py: do not log handled "bad query" 2015-02-04 14:45:50 +01:00
Csaba Tóth ac845819ee [FIX] models: allow empty selection list
If a selection field is created with an empty list of choices (e.g. added by
submodules), initialise the field as a varchar column (most common).
Check if the list exists to avoid crashing while checking the type of the first
key.
Fixes #3810
2015-02-02 10:54:04 +01:00
Olivier Laurent c49d20c61a [FIX] base: _auto_init change column type fix
When changing the type of a column (if size differs for example),
'selection' field should be considered like a 'char' field (since they
are internaly the same column type)

This will fix some migration issues where 'char' fields were correctly
changed but not 'selection,' field.

Use case:
* create a 6.0 db with 'stock' module installed
* 'state' field in 'stock.move' model is of type 'character varying(16)'
* migrate it to 8.0
* 'state' field is still 'character varying(16)' but should normally be
  'character varying'
2015-01-29 14:16:21 +01:00
Denis Ledoux dcfd94cbf5 [FIX] orm: Revert 332154444d && acd7d84da4
These revs. introduced an API change in the _name_search method.

Indeed, the 'operator' attribute used to have 'ilike' as default value.
This cannot be changed, as every modules overriding this method
overrided it using the signature with operator='ilike'

For instance, _name_search method of addons/base/ir/ir_model.py
expects having 'ilike' as operator.
As it was not anymore the case,
it leaded to a crash when performing a name_search call on the model ir.model,
like when adding a new custom field to a model, from the web client.

opw-626161
2015-01-21 18:33:36 +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 54c655cb71 [FIX] models: do not introduce a one2many manual field if its inverse is not on its comodel 2015-01-21 11:26:23 +01:00
Raphael Collet cf26f7ed80 [IMP] models, registry: let the registry retrieve manual fields from database 2015-01-21 11:26:23 +01:00
Raphael Collet 6c29af3fa5 [FIX] models: init function fields once columns are known and not before 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 2f06adde9c [IMP] models: speedup registry loading (35% less time)
The field setup on models is improved: only fields are determined when building
the model's class; the final _columns is computed from the fields once they are
set up.
2015-01-21 11:26:23 +01:00
Samus CTO acd7d84da4 [IMP] make name_search() use '=' if col _rec_name is an integer
When looking for an issue number, it's more useful to match the word in
the whole string instead of just a part of it.
2015-01-20 09:52:55 +01:00
Denis Ledoux 87dd06c941 [MERGE] forward port of branch saas-3 up to 8c150c6 2015-01-15 14:43:32 +01:00
Raphael Collet ec25207b8f [IMP] models: force recomputation of all fields on a newly created record 2015-01-13 16:03:58 +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
Martin Trigaux 33c8aae8e4 [FIX] orm: do not aggregate non-stored columns
Columns defined in the new api as interger, computed and non-stored should not be aggregated in read_group.
Fallback on False if column is None
Fixes #3972, opw 619536
2015-01-05 11:30:26 +01:00
Raphael Collet 8f38a7806a [IMP] enable loading custom models/fields and views from module data files
Loading views for custom models from module data files was not possible because
custom models and fields were introduced into the registry after all modules
were loaded.  As a consequence, the view architecture did not pass the checks.

This patch takes a different approach: custom models and fields are loaded
early on in the registry, so that views can be validated.  The trick is to take
special care of relational custom fields: we skip them if their comodel does
not appear in the registry.  This allows to install and upgrade modules that
create/modify custom models, fields and views for them.
2014-12-19 13:57:08 +01:00
Kit Sunde 1263278b74 [FIX] models: typos
closes #4169
closes #4170
2014-12-11 12:43:47 +01:00
Kit Sunde 107ba240de [FIX] models: docstring typo.
closes #4163
2014-12-11 09:34:03 +01:00
Christophe Simonis a59cf39f06 [IMP] models.py: increase logging level for columns that can't be casted automatically when upgrading a module. 2014-12-09 15:39:12 +01:00
Raphael Collet 894a898e9e [FIX] models: exists() should not consider record with id 0 as existing 2014-12-03 13:59:27 +01:00
Raphael Collet d82aa69ccc [IMP] models: add check for common conversion error in field definitions 2014-12-03 09:55:17 +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 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
Raphael Collet 2052c16d21 [FIX] ir_model: on a custom model, _rec_name should be 'x_name' if it exists 2014-11-17 12:05:37 +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 552dab0dc8 [FIX] models: simplify conditions that seem to lead to missing fields 2014-11-13 14:54:04 +01:00
Raphael Collet fc2975a9af [IMP] models: in _init_manual_fields(), create fields instead of columns
Note that serialized fields are ignored; they are no longer supported, anyway.
2014-11-13 14:54:04 +01:00
Raphael Collet b573077be6 [FIX] models: do not copy translations of fields that are not copied
Fixes #3272.
2014-11-06 16:42:41 +01:00
Raphael Collet 3dc2fcd363 [IMP] models: improve _mapped_func(), and add parameter 'reverse' in sorted() 2014-11-05 11:35:33 +01:00
Raphael Collet 29da331f92 [IMP] models: improve query generation for _write() and _store_set_values() 2014-11-04 17:32:04 +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
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
Xavier Morel 4d2b24adcb [ADD] Stripe-style APIDoc: content 2014-10-27 17:23:16 +01:00
Christophe Simonis 562272d9a0 [MERGE] forward port of branch saas-3 up to c89d1a0 2014-10-23 13:08:44 +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 94e7dc6050 [FIX] models: do not look up the registry class when building cls._fields 2014-10-14 16:17:23 +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
Olivier Dony c0644a5474 [FIX] read_group: date format: use natural year along with month names, do not mix with ISO week-year
The ISO week-year notation can produce confusing values
when the first week of the year is so short that it
becomes week 0 and is considered the last week of the
previous year, depending on the locale.

For instance, using ISO notation:
  'W53 2015' == dates.format_date(
      date(2015,1,1), format="'W'w YYYY", locale='en_GB')
  'W53 2005' == dates.format_date(
      date(2006,1,1), format="'W'w YYYY", locale='de_DE')

This is surprising but actually valid.

However it definitely yields wrong output when combined with
months formats:
  'January 2014' == dates.format_date(
      date(2015,1,1), format="MMMM YYYY", locale='en_GB')

As a result we must always use `y` to denote the year in
any date format, *except* when it is combined with the
week number `w`, in which case we must use `Y`.

See the documentation at:
   http://babel.pocoo.org/docs/dates/#date-fields
2014-10-13 19:15:37 +02:00
Raphael Collet 41b55082ba [FIX] models: on update, call inverse function on field even when it is stored
The inverse function of a stored computed field was not called when creating or
writing on a record with such a field.
2014-10-13 13:45:52 +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 044ed06fec [FIX] models: do not prefetch fields to recompute, and recompute once only
The method _prefetch_field() was accidentally prefetching fields to recompute;
which was skipping the actual recomputation, since a value was put in cache.
But sometimes the field's value was fixed by an extra recomputation of the
field.  Here we remove the extra recomputation and fix the cache corruption.
2014-10-13 12:38:59 +02:00
Raphael Collet ab8bd8066a [FIX] models: in _create() and _write(), mark fields to recompute earlier
An issue occurs when a constraint is checked before computed fields are marked
for recomputation: the constraint will read the field's current value, which
may be wrong.  If the field is marked soon enough, the constraint will trigger
the recomputation and use a correct value.
2014-10-09 17:14:34 +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 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 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 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
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 330a3ff6ea [IMP] models: when checking for data in a table, do not use column 'id'
Replace the query "SELECT min(id) FROM xxx" by "SELECT 1 FROM xxx LIMIT 1".
Both requests are as efficient, and the second one does not crash if column
'id' is missing.
2014-09-25 10:37:28 +02:00
Raphael Collet 24f26c0eeb [FIX] ir_models: fix registry when we add/remove/modify a custom model/field 2014-09-24 15:30:37 +02:00
Christophe Simonis c6290988ce [FIX] models: only check existance of inverse_field for one2many fields 2014-09-22 17:05:07 +02:00
Christophe Simonis dcca9b52c7 [FIX] models: correct lazy loading of manual fields 2014-09-19 16:51:29 +02:00
Olivier Dony e5bff82aff [MERGE] Forward-port saas-5 up to f9bcd67 2014-09-17 16:39:06 +02:00
Raphael Collet f2299749fe [FIX] models: make field inheritance work when source field is defined in old api 2014-09-16 16:03:16 +02:00
Raphael Collet 8fc7cf74fc [FIX] models: improve implementation of _compute_display_name()
The method was expecting that name_get() returns complete and in-order values.
Because of this, some records in the recordset could end up without a value.
2014-09-16 09:36:58 +02:00
Christophe Simonis 780dd9891f [MERGE] forward port of branch saas-5 up to 7eab880 2014-09-15 14:00:02 +02:00
Raphael Collet 85533e1841 [FIX] models: in onchange(), do not send a field value if it has not changed
The method onchange() executes onchange methods in cascade.  Suppose onchange()
is called and a field F=1 in the form.  If an onchange method set F=2, that
value is put in the result variable.  If another onchange method set it back to
F=1, the binding F=2 must be removed from the result variable.

Fixes #2309
2014-09-11 11:45:23 +02:00
Raphael Collet ad14acab32 [FIX] models: in method onchange(), check for record dirtiness only on *2many fiels
Cascading onchanges can be caused by a related field computed in cache.  This
causes a bug in sale order lines, were setting the uom field forces reading
product fields, which are inherited from product templates.  The inherited
fields are computed as related fields, which marks the product record as dirty.
This subsequently triggers an onchange on the product field, which resets the
uom field!
2014-09-10 14:26:12 +02:00
Raphael Collet 7428464004 [FIX] openerp/osv/fields: disable prefetching when reading inverse of one2many fields
This fixes issue #2146.  The inverse of a one2many field can be an inherited
field (_inherits).  In that case, we cannot read its value with a simple
database query.  Instead, we let the related field read it, but for performance
considerations we disable the prefetching of other fields.
2014-09-10 09:41:36 +02:00
Raphael Collet 68777c5860 [IMP] models: inherited fields are related fields read as the current user
Add an attribute 'related_sudo' (True by default) for related fields.
A related field is computed as superuser if related_sudo is True.

Add explicit related fields 'name' and 'email' on 'res.users', as these should
be readable by the public user with module website_forum.
2014-09-04 16:10:48 +02:00
Raphael Collet d6f375df61 [IMP] models: "X in self" is now equivalent to any(X == rec for rec in self)
Fix modules with code like "record.id in other.stuff_ids".
2014-09-04 15:31:04 +02:00
Raphael Collet 4ce06c238b [FIX] openerp.api.Environment: move recomputation todos into a shared object
This fixes a bug which is usually triggered in module account_followup, but
does not occur deterministically.  Some recomputations of computed fields are
apparently missing.  Environment objects containing recomputations todos and
kept alive by a WeakSet, are removed by the Python garbage collector before
recomputation takes place.  We fix the bug by moving the recomputation todos in
a non-weakref'ed object.
2014-09-04 10:18:55 +02:00
Raphael Collet f2f1f3465d [IMP] models: prefetch fields with groups (those to which user has access) 2014-09-02 14:11:11 +02:00
Raphael Collet 4f11ff379a [IMP] models: do not prefetch too many records at once 2014-09-02 14:11:11 +02:00
Samus CTO c6df857533 [FIX] Missing part of the revision 5f6fc473 2014-08-25 18:01:38 +02:00
Samus CTO aad19c7360 [FIX] model: prevent exporting column ID of non ordinary tables
This makes no sense and can generate errors if you try to purge
ir.model.data of not existing records.
2014-08-25 14:38:20 +02:00
Raphael Collet 2ad092b5e5 [ADD] doc: new documentation, with training tutorials, and new scaffolding 2014-08-22 17:51:20 +02:00
Raphael Collet 97256fa1fb [IMP] models: move prefetching of records back to method _prefetch_field
The selection of records in cache for prefetching was moved to method
_read_from_database() by xmo at rev 785018cc in order to fix an access right
bug.  But this introduced an issue: to explicitly avoid prefetching, you should
use read() instead of browsing records.  We revert the change by xmo, without
reintroducing the bug (which apparently was fixed by another way).
2014-08-22 14:42:20 +02:00
Christophe Simonis 5bcb3a676e [FIX] models: onchange return all subfields in cache when no subfields presents 2014-08-19 20:04:26 +02:00
Raphael Collet 052f9ed5d7 [FIX] models: improve rationale for the management of flag 'recompute' in context
When the context contains 'recompute': False, the recomputation was not even
prepared. Now both create() and write() prepare the recomputation by invoking
method modified(). The flag only controls whether method recompute() is invoked.
In addintion, the former flag 'no_store_function' was converted to the flag
'recompute', so that both create() and write() use the same flag.

Fixes #1456
2014-08-19 11:50:42 +02:00
Raphael Collet 62b0d99cfe [FIX] models: unexpected missing value when checking for a field in cache
At the end of _prefetch_field(), a check is made to ensure that the cache
contains something for the field to prefetch. The check was incorrect because
the cache was checked for a regular value only.
2014-08-19 11:50:42 +02:00
Denis Ledoux b7c911980b Merge branch '8.0' of github.com:odoo/odoo into 8.0 2014-08-18 17:48:09 +02:00
Raphael Collet 01e647b57d [IMP] models: improve code of _convert_to_write(), make it easier to read 2014-08-18 14:20:41 +02:00
Christophe Simonis 25e11113b5 [FIX] models: `_convert_to_write()` shall not return `NewId`
The result of _convert_to_write() is intended to be pass directly to
`write()` or returned to the client (`onchange()` and `default_get()`.
`NewId` is as special value that must not be stored into the database
or exposed to the client.
2014-08-14 21:43:16 +02:00
Denis Ledoux d0a2b6b3da [FIX] models: stored func fields computation on one2many write
On one2many fields writing in an existing record (not when creating new record), the computed stored fields of the one2many were not re-computed correctly
Computed stored fields were marked as modified only if no_store_function was not set to True in the context. no_store_function is set when writing one2many records on an existing record.
Now, these computed stored fields are marked as to be recomputed, but are recomputed later, at the end of the existing record write
2014-08-14 18:19:48 +02:00
Christophe Simonis d68537022f [FIX] models: onchange on new records do not nullify fields from _inherits records 2014-08-14 17:55:20 +02:00
Olivier Dony e11eddf753 [MERGE] Forward-port of saas-5 up to 20cc18d 2014-08-13 20:46:47 +02:00
Christophe Simonis 1644708fe8 [IMP] models.py: _auto_init: accelerate row existance check
Using `COUNT(1)` on big table can be slow. Use `min(id)` which use
pkey index to have a quicker response
2014-08-12 18:38:55 +02:00
Olivier Dony 3f91f85f60 [IMP] ORM: Coalesce NULL boolean values to false when generating ORDER BY
After commit f28be81, boolean columns may have more
NULL entries than before. In the (rare) cases where
a boolean column was used for an ORDER clause
(e.g. in the /shop page of website_sale), this
causes a change of the resulting ordering.

By coalescing NULL values to false in SQL,
we make the ordering consistent with what the
framework does for domain expressions with booleans,
and when reading boolean values, that is, NULL is
the same as False.
2014-08-12 12:32:35 +02:00
Olivier Dony f28be81bc7 [IMP] models._auto_init: avoid writing `False` default for boolean fields
Boolean fields always default to False in 8.0,
even when they do not have explicit default values.
This causes extra queries in the form:
  UPDATE <table> SET <bool_field> = false
      WHERE <bool_field> IS NULL;

Those are not necessary as the ORM automatically
folds NULL booleans to False, and can be very
expensive on tables with several million rows,
as the whole table may sometimes need to be
rewritten (can take dozens of minutes)
2014-08-11 11:34:12 +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
Raphael Collet 0199e6025a [FIX] models: default_get() used to miss values
The default values are computed by evaluating fields on a new record. The fix
retrieves values from the cache earlier, because in some cases, the evaluation
of a field invalidates a formerly evaluated field.
2014-08-08 14:12:06 +02:00
Richard Mathot fed0ea5392 [FIX] read_group cannot aggregate non-stored field 2014-08-08 10:53:39 +02:00
Thibault Delavallée 2e5412fc1d [FIX] mail, BaseModel, portal_sale: fixes and improvements in the URL
management to access documents in notification emails, as well as for the
'view quotation' link in portal_sale module.

models: added a get_access_action method: basically, returns the action to
access a document. It uses the get_formview_action by default (form view
of the document). However for some documents we want to directly go to the
website, leading to an act_url action for some documents. This method allows
this behavior.

portal_sale: get_signup_url now uses the mail.action_mail_redirect method
instead of directly redirecting towards a portal menu. This allows to fall
back on a standard behavior.

portal_sale: get_formview_action updated, to match actions tailored for
portal users.

website_quote: get_access_action of sale order updated. If the sale order
has a template defined, the returned action is an act_url (website view
of the quotation), not the form action anymore.

mail: fixed signature + company signature in notification emails. Even without
user signature, the company signature + access link should be correct.

portal: signup url in notification emali was not using the mail redirection
as action. It is now the case.
2014-08-07 16:47:59 +02:00