Commit Graph

160 Commits

Author SHA1 Message Date
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
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