Commit Graph

1165 Commits

Author SHA1 Message Date
Sandy 3b7e00d718 [FIX] orm: prevent pgerrors from raising `UnicodeDecodeError`
Use `tools.ustr` for error conversion to prevent `UnicodeDecodeError` when
converting errors which can be unicode in depending on data.

Example:
```python
from openerp.osv.orm import convert_pgerror_23505
from psycopg2 import IntegrityError

e = IntegrityError(
    'duplicate key value violates unique constraint '
    '"hr_job_name_company_uniq"\nDETAIL:  '
    'Key (name, company_id)=(Directrice comptabilit\xc3\xa9, 1) '
    'already exists.\n'
)

convert_pgerror_23505(None, [], None, e)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 129: ordinal not in range(128)
```
2015-01-12 15:35:23 +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
Denis Ledoux 276d0e76b2 [MERGE] forward port of branch 7.0 up to 284ca73 2014-12-08 14:57:21 +01:00
Sandy Carter aa10972d13 Raise error on read of a browse object with bad id
Check if id is valid by searching record columns when a key error is raised
If the record has the column, the key error is actually an error on a
missing or inaccessible id.

Signed-off-by: Sandy Carter <sandy.carter@savoirfairelinux.com>

Closes #3658
2014-12-04 13:24:26 +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
Denis Ledoux 0e4216361b [MERGE] forward port of branch 7.0 up to 3a0af6a 2014-10-22 19:26:27 +02:00
Raphael Collet 8e6d5beb35 [IMP] fields: reuse column objects when possible, instead of recreating them
This is a memory optimization: it reduces the memory footprint of each
registry.  We have observed a reduction of 10Mb on a database with modules crm,
sale, purchase, stock.
2014-10-22 16:22:39 +02:00
Cedric Snauwaert fa2f7b86bf [FIX] product: remove digits_precision from uom factor fields
Remove the hardcoded precision of 12 on factor and factor_inv,
to use the complete natural precision of NUMERIC types,
preserving all significant digits.

e.g. a UoM with a factor_inv of 6.0 used to be computed as:
factor_inv: 6.0 -> factor: 0.166666666667 (1.0/6.0, rounded to 12 digits) -> factor_inv: 5.999999999988 (1.0/factor)
which could lead to errors such 12*0.166666666667 = 2.000000000004 instead of 2.0

Slightly changed the way the ORM handles float fields to allow setting `digits=0`
as a way to explicitly require a NUMERIC value but without enforcing/rounding
the values at the ORM level, i.e. a truly full-precision field.

NUMERIC type has unlimited precision but is less efficient so should not be
used as the default behaviour, which is why we keep float8 as an alternative.

Modified the view to display the product UOM factor with a 5 digits value by default.
This value is for usability purpose only, the field still accepts bigger precision, by
setting the `digits` option on the field in the form view.

This change is safe in a stable series, the `digits=0` alternative is
treated the same as the default `digits=None` everywhere in the framework,
except when creating the database field.
2014-10-22 14:28:34 +02:00
Raphael Collet e9587bf130 [IMP] expression.py: add a check to forbid records in domains
Records in domains cause a "maximum recursion depth exceeded" error when
converted to SQL. Simply add a test to show a better error message.
2014-10-16 10:22:23 +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
Denis Ledoux b6e6b57326 [FIX] orm: typo during forward port 60a82133cc 2014-09-17 16:24:40 +02:00
Denis Ledoux 60a82133cc [MERGE] forward port of branch 7.0 up to f5f7609 2014-09-17 13:39:13 +02:00
Denis Ledoux f5f76094a7 [FIX] orm write: do not try to store computed & stored fields for relational records deleted by *2many fields
opw-613772
2014-09-17 13:32:30 +02:00
Martin Trigaux 32f5168974 [FIX] orm: do not drop foreign keys of transient models
During the update of a module, the existing foreign keys are dropped if they have a different ondelete_rule than the one specified on the field.
The foreign keys for many2one transiant -> non-transiant are created with cascade rule by default (see `m2o_add_foreign_key_checked` method) so the check needs to be realised in the same conditions.
2014-09-15 15:24:53 +02:00
Christophe Simonis fdc62713a5 [MERGE] forward port of branch 7.0 up to 9b1cdea 2014-09-12 17:28:55 +02:00
Denis Ledoux 2459cd5dd1 [FIX] ir_attachment: attachements removed on record unlink 2014-09-10 12:18:14 +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
Denis Ledoux b1f4a61705 [MERGE] forward port of branch 7.0 up to 8dff247 2014-09-09 18:23:32 +02:00
Denis Ledoux 8dff247096 [FIX] orm, read_group: read_group_fill_results handle no_leaf 2014-09-09 16:47:40 +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 c3131317d7 [MERGE] forward port of branch saas-4 up to ddef2dd 2014-08-20 17:57:22 +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 2a94d1d811 [MERGE] Forward-port saas-4 up to 2694ed1 2014-08-13 17:34:27 +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 7aa0376f3e [FIX] gamification: prohibitive record rule processing with many users/goals
Due to the multi-company record rule on gamification.goal,
each access to the Goals menu and each opening of the
Messaging menu (thus calling get_serialised_gamification_summary())
is extremely slow (with several thousands goals/users).

Adding auto_join to the user_id FK on goals makes it much
faster. However it causes crashes when reading the table
because the _order of gamification.goal uses `create_date`,
which becomes ambiguous after the auto_join with res_users.

Solving this can be done by re-implementing _read_flat()
in the ORM using the internal Query object, as in search(),
which takes care of fully-qualifying all column names.

Until this is fixed, a simple workaround is to use
start_date in the _order instead of collision-prone `create_date`.
2014-08-13 13:47:50 +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
Olivier Dony b7814943c3 [MERGE] Forward-port saas-3 up to 7273474 2014-08-01 23:14:59 +02:00
Olivier Dony 7273474d65 [MERGE] Forward-port saas-3 up to fc92027 2014-08-01 23:10:29 +02:00
Olivier Dony 5a0a500994 [MERGE] Forward-port 7.0 up to 9411a2da 2014-08-01 23:01:57 +02:00
Olivier Dony 9411a2da03 [FIX] Model.load(): extra error checking while importing data
If any missing or partially incorrect values cause
an exception other than a psycopg2 error, we should
still catch it, rollback that record and report
the error, rather than letting bubble and fail
without any feedback to the user.

Fixes #1485
2014-08-01 22:42:01 +02:00
dhr-odoo eb775fc2ea [FIX] orm: set default before removing magic fields
When a record is created, the magic fields (id, create_date,...) are first removed from the vals as the user should not set a value for these.
However if a value for this is given in default value (e.g. defined in an ir.value), the creation would crash (sql error : column specified more than once) as the magic column would be added again.
2014-08-01 15:37:01 +02:00
Olivier Dony ee4df1e397 [MERGE] Forward-port saas-4 up to 8b15482 2014-08-01 13:06:49 +02:00
Olivier Dony 8b15482e00 [MERGE] Forward-port saas-3 up to e79a367 2014-08-01 12:54:30 +02:00
Olivier Dony e79a3675d1 [FIX] orm.search_count: ignore `limit`, `offset` and most importantly `order`
These parameters are (or should be) irrelevant for
a search_count(), and they could actually break the
result or make it significantly slower (e.g applying
`order` on large tables).
This fixes a performance regression introduced by
0f43032b.

We could also raise an error offset/limit are
passed in combination with count, but that seems
unnecessary.

Also switched to "SELECT count(1)" for the count
query, as it is simpler and just as fast.
We'd get the same perf with * or any constant value,
as in "SELECT count('me in')", but let's keep it
simple ;-)
2014-08-01 12:34:45 +02:00
Olivier Dony 924e4b1a08 [MERGE] Fwd-port saas-4 up to e31fd6a 2014-07-11 12:00:42 +02:00
Olivier Dony e31fd6a1e1 [MERGE] Fwd-port saas-3 up to a9d2b65 2014-07-11 11:53:07 +02:00
Olivier Dony a9d2b65da5 [MERGE] Fwd-port 7.0 up to 783b9e1 2014-07-11 11:51:06 +02:00
Martin Trigaux 437116f3c4 [FIX] orm: custom m2m with different label
At rev 84e9a67cdf a check to avoid the creation of ir.model.relation for custom modules was added. The condition is not correct as based on the string instead of the field name. We do not have access to column name at this level but the the m2m relation table do start with x_ for custom fields (see __init__ method).
2014-07-11 11:39:32 +02:00
Christophe Simonis 73d39a0c8c [MERGE] forward port of branch saas-4 up to a361947 2014-07-10 22:12:16 +02:00
Christophe Simonis a361947143 [MERGE] forward port of branch saas-3 up to a35aec2 2014-07-10 22:02:58 +02:00
Christophe Simonis a35aec2a0b [MERGE] forward port of branch 7.0 up to 6e96ffd 2014-07-10 22:02:01 +02:00
Martin Trigaux 84e9a67cdf [FIX] orm: better removal of custom m2m fields
orm: do not try to create ir.model.relation for custom m2m as self._module is either empty (for custom models), either the one of the last inheriting module (which is wrong). The field should be removed manually and should not be impacted by the uninstallation of modules. The removal of the relation table can be done when removing manually the custom field (see rev 6af3193).

ir.model: when removing a model, drop the table with the CASCADE instruction. This will remove left constraints from remaining m2m tables.
This means that dropping a table (either manually removing a custom model or uninstalling a module) will not drop the relation table for a custom m2m field. This is not ideal but better than the previous behaviour (which was to fail the DROP TABLE instruction and keep the table with a few columns and unconsistent data).
2014-07-08 15:56:24 +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 9e8e3653f2 [MERGE] forward port of branch saas-4 up to f68c835 2014-06-25 12:43:41 +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
Laurent Mignon (aka lmi) ea00789e35 [IMP] take into account the context parameter 'defer_parent_store_computation' also on write operations 2014-06-24 14:22:41 +02:00
Mohammed Shekha 0b593ada11 Server Translation: Fixed the issue search on translated field do not return true result, search on tranlsated field fails due to expression parsing which fetches ids from ir_translation as well as working table and UNION of this makes search fruitless, also search fails for in language other then english when you enter part of a string for the field to search. 2014-06-24 17:42:48 +05:30
kevin wang 59c27970b5 [FIX] orm: allow unicode in inherit views with attribute
When extending a view with position='attributes', prevent crash if view contains unicode char
Fixes #706
2014-06-23 12:48:27 +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 adf07a9490 [MERGE] forward port of branch saas-4 up to 5087612 2014-06-19 16:13:35 +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
Xavier Morel 63a6ba92e2 [IMP] no need to compute *all* has_group calls if the first one fails 2014-06-17 12:00:50 +02:00
Denis Ledoux 3c0292645f [MERGE] Forward-port of 7.0 bugfixes up to 63ea0df73f 2014-06-16 17:37:10 +02:00
Fabien Meghazi f213b7ea65 [FIX] new style for default form views 2014-06-16 13:39:48 +02:00
Olivier Dony f15cbd6520 [MERGE] Forward-port saas-4 bugfixes up to ad4c6ca 2014-06-12 18:54:36 +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
Christophe Simonis 7bee9447c4 [MERGE] forward port of branch saas-3 up to 3c7a54a 2014-06-11 11:06:04 +02:00
Christophe Simonis 3c7a54a76c [MERGE] forward port of branch 7.0 up to 100eba8 2014-06-11 10:58:43 +02:00
Jeremy Kersten 100eba8eaf [FIX] fields.py - avoid dict comprehension inside a dict comprehension 2014-06-11 10:30:00 +02:00
Christophe Simonis a7c2125735 [MERGE] forward port of branch saas-4 up to 6b8e972 2014-06-10 13:15:46 +02:00
Christophe Simonis 6b8e9727e5 [MERGE] forward port of branch saas-3 up to 4601d85 2014-06-10 12:29:47 +02:00
Christophe Simonis 4601d85944 [MERGE] forward port of branch 7.0 up to 6fdb783 2014-06-10 11:49:14 +02:00
Christophe Simonis 517162ce14 [FIX] orm: do not recompute m2o stored function field at read.
The get() method of m2o function fields is used for 2 different things:
 - call the function defining the m2o
 - get the name_get representation of the value

Until this pathc, only the first case was handled, resulting to a useless
recomputation of the field when reading it.
2014-06-06 10:53:42 +02:00
Oliver Laurent 306d5c89a0 [FIX] orm: do not resize unlimited char fields 2014-06-05 19:05:36 +02:00
Christophe Simonis b1c0bc0b46 [MERGE] forward port of branch saas-4 up to 65f68c1 2014-06-03 19:45:19 +02:00
Martin Trigaux 3cb551bf50 [FIX] read_group: do not change the return format of the read group in case of no groupby_fields and keep the same return format as with groupby fields (a list of dict) 2014-06-03 10:20:55 +02:00
Xavier Morel d9ce012d29 [IMP] simplify handling of callable _constraint message 2014-05-27 11:57:00 +02:00
Xavier Morel d8377a931e [REM] idiotic _invalids attribute, as well as get_invalid_fields 2014-05-27 11:56:59 +02:00
Christophe Simonis a756b82372 [MERGE] forward port of branch saas-4 up to revid bb26dea 2014-05-20 20:19:55 +02:00
Christophe Simonis bb26dea60b [MERGE] forward port of branch saas-3 up to revid 38abc8a 2014-05-20 19:00:50 +02:00
Christophe Simonis 38abc8a006 [MERGE] forward port of branch 7.0 up to revid b09b6a0 2014-05-20 18:57:04 +02:00