Commit Graph

109 Commits

Author SHA1 Message Date
Raphael Collet a9c43bba82 [FIX] fields: fix assignment of related field on several records 2015-10-02 17:05:35 +02:00
Raphael Collet 1c4c64fe01 [FIX] fields: add support for date/datetime null values in field methods 2015-09-07 10:27:34 +02:00
Nicolas Martinelli 282fc4a850 [FIX] openerp: export empty string instead of None
xmlrpc 1.0 does not support None/null, so commit f3e4d0a will break xmlrpc api.
Therefore, we export an empty string if the field is empty, instead of False or
None. For integers and floats, zero is exported.

opw-643966
2015-08-03 08:16:23 +02:00
Nicolas Martinelli f3e4d0a2e8 [FIX] openerp: export None instead of False in raw_data mode
If we export False or an empty string, the Excel export will consider the field
similarly to a boolean, and en empty value will be converted into "=False()" in
Excel. To prevent this, we return "None" in the following cases:

- String
- Date
- Datetime
- Selection
- Reference
- Many2one
- RelationalMulti

Introduced by 6243d18

opw-643966
2015-07-09 11:49:04 +02:00
Xavier Morel 95e56a109d [ADD] doc: new theme
Pretty much completely rewritten theme with custom HTML translator and a
few parts of the old theme extracted to their own extensions.

Banner images thought not to be that huge after all, and not worth the
hassle of them living in a different repository.

co-authored with @stefanorigano
2015-07-07 11:22:50 +02:00
Raphael Collet 0939738479 [IMP] fields: speedup of `convert_to_cache` for x2many fields
The algorithm's complexity changed from O(n²) to O(n).
2015-07-01 13:49:14 +02:00
Martin Trigaux 6bb3be5ba3 [FIX] doc: api.multi/one confusion
As the methods are using @api.multi, it should be accessed with rec, not self
2015-06-17 09:41:09 +02:00
Christophe Simonis 1cf5723835 Revert "Revert "[FIX] fields: `digits()` computation""
Thamks to parent commit, `request.env` doesn't raise `AttributeError`
anymore for requests without session bound to a database.

This exception was bubbling up to `digits` property (and `__getattr__`)

This reverts commit 49cb46fb78.
This reinstate commit eeedd2d9f5.
2015-05-21 13:13:23 +02:00
Denis Ledoux 49cb46fb78 Revert "[FIX] fields: `digits()` computation"
This reverts commit eeedd2d9f5.

This revision introduces an issue more serious than the ones
it fixes. This is no longer possible to receive an email
aimed a sale.order thread with catchall.

To reproduce the issue:
 - Create a new sale order
 - Send a message in the thread to the customer
 - Reply to the mail received in the customer mailbox
 - Traceback, AttributeError: digits

 opw-640370
2015-05-20 19:13:04 +02:00
Christophe Simonis eeedd2d9f5 [FIX] fields: `digits()` computation
Ensure we always have an valid cursor when determining `digits()`.

fixes #6605, fixes #6650
2015-05-19 19:59:10 +02:00
Raphael Collet 5efac22043 [FIX] fields: when determining `digits()`, make sure to use a valid cursor 2015-05-07 16:56:26 +02:00
Raphael Collet 071152216f [FIX] fields: when computing digits, use an existing cursor instead of a new one
The computation of property `digits` was creating a new cursor to call the
function that determines digits.  This technique is fragile because the current
cursor may have pending updates that the new cursor will not see.

The issue was discovered by Cécile Tonglet (cto).  She observed an infinite
loop during a database migration, and a traceback inside the loop showed the
presence of the `digits` property.  This change fixes the infinite loop issue.
2015-05-05 17:33:16 +02:00
Ravi Gohil 3557fe124a [FIX] fields: timezone aware context_timezone
context_timestamp should always return a timezone aware timestamp, even when
no timezone is set on the user.
7f88681 fixed the bug in old api fields (openerp/osv/fields.py) but it was not
applied to new api fields (openerp/fields.py). opw 616612
2015-04-17 17:59:47 +02:00
Raphael Collet 524bb0a520 [IMP] fields: simplify the definition of `__slots__` via the `Field` metaclass 2015-03-23 14:36:15 +01:00
Raphael Collet 1df3467888 [IMP] fields: remove unnecessary code
In `__getattr__`, remove the test on accessing `_attrs`.  This situation should
never happen, since the attribute `_attrs` is set in method `__init__()`.
2015-03-23 14:36:15 +01:00
Raphael Collet e7928e1265 [IMP] fields: add `__slots__` on all fields
Introduce slots on all field classes for common attributes; slots take much
less memory than a `__dict__`.  The other attributes are stored in a dictionary
`_attrs`; all fields with an empty value for `_attrs` (common case) share the
same empty dictionary.  This saves quite some memory (around 4.5Mb per
registry), given the number of field instances created for a registry.

Another mechanism is used for the default values of attributes, since slots
cannot be assigned on classes.
2015-03-23 14:36:15 +01:00
Raphael Collet 915af86a91 [IMP] fields: simplify definition of ID field 2015-03-23 14:36:15 +01:00
Raphael Collet ffa7f28d34 [IMP] fields: reduce memory footprint of list/set field attributes
The optimization consists in using tuples for attributes `inverse_fields`,
`computed_fields` and `_triggers`, and to let them share their value when it is
empty, which is common.  This saves around 1.8Mb per registry.
2015-03-23 14:36:15 +01:00
Raphael Collet 3df7754087 [IMP] fields: reduce memory footprint of `field._attrs` and `column._args`
The optimization consists in sharing the dictionary when it is empty, which is
the common case.  This saves around 1.5Mb per registry.
2015-03-23 14:36:15 +01:00
Raphael Collet 4d232969a3 [IMP] fields: remove attribute `_free_attrs` and use `_attrs` instead
This saves about 400Kb per registry by not allocating those lists, which are in
most cases empty.  The removal of the attribute will also simplify a bit the
management of free attributes.
2015-03-23 14:36:15 +01:00
Raphael Collet 9aad3d873b [IMP] fields: turn field.digits and column.digits into dynamic properties
The computed value of parameter digits is no longer stored into fields and
columns; instead the value is recomputed everytime it is needed.  Note that
performance is not an issue, since the method `get_precision` of model
'decimal.precision' is cached by the orm.  This simplifies the management of
digits on fields and saves about 300Kb per registry.
2015-03-23 14:36:15 +01:00
Raphael Collet 7ac4639a24 [FIX] fields: fix determination of `field.selection` for custom fields
In the case of custom fields, `field.selection` is set directly instead of
being set in overridden fields.
2015-03-16 15:34:16 +01:00
Olivier Dony 13476c844d [FIX] fields.html, forum: opt-in stripping of @style attrs
For public-facing HTML content provided by the user,
`<style>` tags and `style` attributes should be stripped
automatically, as they can easily be abused to deface
pages for abusive users and spammers.
<style> tags were already stripped, the optional `strip_style`
for fields.html enables the automatic stripping of style
attributes.

This is opt-in because custom style attributes are still
desirable in trusted HTML fields.
2015-03-09 14:41:14 +01:00
Raphael Collet 983dcf193c [FIX] fields: make base_field recursive in case a field is inherits'ed across several models 2015-03-03 13:18:04 +01:00
Raphael Collet 021c1a26c5 [IMP] fields: improve performance when reading many2one fields on records
Improve the performance of `name_get()` on many2one field values by making sure
that the records on which `name_get` is invoked are prefetched in cache.  This
is not automatic, because `name_get` is invoked on records in another
environment (sudo mode): the prefetching in the original environment should be
reproduced in the other environment.
2015-03-03 09:38:36 +01:00
Raphael Collet 5ec8596f67 [FIX] fields: fix `_column.new()` by relying on `to_field_args()`
The implementation was based on the ill-defined method `same_parameters()` that
compares arguments based on a heuristic.  Instead, we now create a new column
and check whether it is equivalent to `self` by comparing the arguments
returned by `to_field_args()`.  If that is the case, `self` is reused instead
of the new column.

The code refactoring also fixes the column reuse which was broken by the
introduction of the parameter `compute` in commit 9333c62.  Indeed, with that
parameter, `same_parameters()` always returned False, since old-api columns do
not have that parameter by default.  The parameter has been renamed to
`_computed_field`, and is no longer passed for creating columns.
2015-02-23 15:50:09 +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 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
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