Commit Graph

255 Commits

Author SHA1 Message Date
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 0f9b452c33 [IMP] models: convert deprecated model._all_columns into a dynamic property
The mappings model._all_columns takes quite some memory (around 2MB per
registry) because of the numerous dictionaries (one per model) and inefficient
memory storage of column_info.  Since it is deprecated and almost no longer
used, it can be computed on demand.
2015-03-23 14:36:14 +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 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
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
Denis Ledoux 00762bbae0 [MERGE] forward port of branch saas-3 up to 643bbcb 2015-01-05 14:25:34 +01:00
Denis Ledoux 643bbcb00b [MERGE] forward port of branch 7.0 up to 27d8cb8 2015-01-05 13:48:01 +01:00
Denis Ledoux 27d8cb843b [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.
2015-01-05 12:48:38 +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 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 7b1ef7085a [IMP] fields: reduce the number of attributes on _column instances
This is a memory optimization: instead of setting all attributes on all
instances, set them with their default value on the class, and only set
specific ones on instances.  This reduces the memory footprint of around 14Mb
per registry with modules crm, sale, purchase and stock installed.
2014-10-27 14:36:09 +01: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
Raphael Collet 10142d7dc7 [FIX] openerp/osv/fields: fix method to_field() to pass some falsy parameters.
For instance, the attribute copy=False was not passed when converting the
_column to a Field.  Simply make sure those parameter are always passed.
2014-10-08 16:39:59 +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 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 f2f1f3465d [IMP] models: prefetch fields with groups (those to which user has access) 2014-09-02 14:11:11 +02:00
Martin Trigaux 4a10295823 [FIX] fields: avoid prefetching of one2many fields
When reading a one2many field, the inverse mapping of the lines (matching m2o -> lines of corresponding record) was instantiating each line and then triggering the prefect of fields.
To improve the performances, the inverse mapping is done in sql to avoid triggering the prefetching.
2014-09-02 13:34:57 +02:00
Raphael Collet 2c6ee89080 [FIX] osv/fields.py: enable argument 'obj' in property fields
Fixes #1719
2014-08-22 12:10:46 +02:00
Raphael Collet 20b302cc8c [FIX] osv/fields.py: fix the fix at rev 43756a24. 2014-08-22 11:14:08 +02:00
Raphael Collet 43756a24ca [FIX] osv/fields.py: fix sum in rev 48dfd70 2014-08-22 10:56:07 +02:00
Raphael Collet 48dfd70b4a [IMP] osv/fields.py: improve code change of rev eea07e27 2014-08-22 09:23:42 +02:00
Christophe Simonis eea07e27c0 [FIX] osv/fields.py: correct reading name_get of m2o property 2014-08-21 21:23:22 +02:00
Raphael Collet 618e397df1 [FIX] fields: in many2one property fields, name_get() the value as superuser 2014-08-21 17:29:56 +02:00
Raphael Collet dce5228da7 [FIX] fields: add missing option 'sanitize' on Html fields 2014-08-21 13:27:30 +02:00
Christophe Simonis 5dff035878 [MERGE] forward port of branch saas-5 up to 39bee35 2014-08-20 20:33:17 +02:00
Christophe Simonis ddef2dd10a [MERGE] forward port of branch saas-3 up to 8f13e83 2014-08-20 17:51:20 +02:00
Christophe Simonis 8f13e8320e [MERGE] forward port of branch 7.0 up to d0a0b7d 2014-08-20 17:45:05 +02:00
Martin Ambroz 106cb1ec2b [FIX] base: python 2.6 incompatibility for dictionary comprehension 2014-08-20 10:28:37 +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
Olivier Dony e11eddf753 [MERGE] Forward-port of saas-5 up to 20cc18d 2014-08-13 20:46:47 +02:00
Olivier Dony 2694ed1472 [MERGE] Forward-port saas-3 up to b9275da 2014-08-13 17:33:12 +02:00
Olivier Dony b9275da8a5 [MERGE] Forward-port 7.0 up to 23cffab 2014-08-13 17:30:06 +02:00
Samus CTO 7f88681186 [FIX] context_timestamp MUST return a "timezone aware" timestamp 2014-08-13 14:58:55 +02:00
Olivier Dony a2943a4432 [IMP] fields.boolean: simplify symbol_set, cast to bool
In combination with f28be81, this should help speed up
initialization of new boolean columns. psycopg2 handles
bool parameters values just fine inside cr.mogrify()
2014-08-11 12:37:52 +02:00
Christophe Simonis 407c1be1e8 [FIX] fields.py: correct copy/paste error, use the right attribute 2014-08-07 13:50:27 +02:00
Christophe Simonis 5bd3c02bec [FIX] fields.py: handle "change_default" and "deprecated" attributes in new fields 2014-08-07 13:04:26 +02:00
Christophe Simonis 50a67c8e9b [FIX] fields.py: fix old field to new field convertion 2014-08-07 13:01:03 +02:00
Raphael Collet 2d2274aeed [FIX] module loading: manual x2x fields can now refer to manual models
The fix consists in this: when setting up models, ignore manual fields that
refer to unknown models if all models have not been loaded yet.
2014-08-04 15:10:12 +02:00
Raphael Collet cbe2dbb672 [MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.

- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
2014-07-06 17:05:41 +02:00
Christophe Simonis 1eaa69d342 [MERGE] forward port of branch saas-5 up to 9e8e365 2014-06-25 12:44:13 +02:00
Christophe Simonis f68c83545a [MERGE] forward port of branch saas-3 up to a66f3dd 2014-06-25 12:33:17 +02:00
Christophe Simonis a1b3e22a17 [MERGE] forward port of branch 7.0 up to 4bfcbb2 2014-06-25 11:35:11 +02:00
Alexandre Fayolle 4bfcbb2a48 [FIX] fields property: do not create empty properties
fixes #595
In the case where a property for the company exists but has no related record (e.g. in case of type m2o with no defined value), not setting a value to this field for a new record would create a new property (as browse_null is not an instance of browse_record)
2014-06-25 10:57:10 +02:00
Christophe Simonis eef6330c55 [MERGE] forward port of branch saas-5 up to adf07a9 2014-06-19 16:23:32 +02:00
Christophe Simonis 5087612d1d [MERGE] forward port of branch saas-3 up to bf53aed 2014-06-19 15:44:07 +02:00
Xavier Morel 56009e8804 [FIX] website: missing timezone conversion back to UTC
In t-field, datetime fields (formatted and not formatted versions) are
converted to the context/user's timezone (through
fields.datetime.context_timestamp) when displayed, but were saved without
converting back so the next display would go forward (or back) of the user's
tzoffset.

Fix that by applying context_timestamp's conversion backwards, from the
context/user's timezone back to UTC, before saving the field's value.
2014-06-18 16:09:02 +02:00
Denis Ledoux 3c0292645f [MERGE] Forward-port of 7.0 bugfixes up to 63ea0df73f 2014-06-16 17:37:10 +02:00
Martin Trigaux 86acc1a62f [FIX] orm: avoir errors reading twice a field
_read_flat: remove duplicated fields in read call
get many2one: as False is instance of int, check the value of x first to avoid calling a name_get with a list of False

When we were reading twice a m2o field where at least one result is null, the first call to name_get would set the value to False instead of None and then accepted by the filter 'isinstance(x, (int,long))'
2014-06-12 16:14:41 +02:00