Commit Graph

548 Commits

Author SHA1 Message Date
Raphael Collet 8ea17a8cc9 [FIX] orm: always save boolean function fields, even when they are false
Fixes #4292: searching for records when a related boolean field is `False`
always returns nothing.
2015-10-12 16:38:17 +02:00
Daniel Reis 8b3d69a0d7 [FIX] orm: performance of regex to check search `order` spec
This regex is used for a quick sanity check of
the order_spec in `search(order=<order_spec>)`.
Because it was build on the repetition of a
group ending with a series of optional patterns,
it could cause expensive backtracking when the
order spec did not actually match the regex
(the regex engine was trying all possible ways
to split the groups)

Forcing the repeating group to either end
with a comma or the end of the string prevents
prohibitive backtracking, while being even
more restrictive with regard to the syntax of
the order spec.

Closes #7755
2015-08-04 11:45:01 +02:00
Ravi Gohil ffacce7140 [FIX] orm: export on empty one2many
When exporting the content of a one2many, if the first row got an empty value,
it was filled with the name_get of all lines and skipped the next lines.
The guessed reason of this was for the representation of the m2m lines but was
left after a proper export of m2m has been implemented (91cafbe).
This code was problematic as it prevented to properly export records with
an empty value on the first line (e.g. credit amount on account.move.line).
Fixes #4218, opw 620178
2015-04-07 15:54:01 +02:00
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
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
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
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
Denis Ledoux 2459cd5dd1 [FIX] ir_attachment: attachements removed on record unlink 2014-09-10 12:18:14 +02:00
Denis Ledoux 8dff247096 [FIX] orm, read_group: read_group_fill_results handle no_leaf 2014-09-09 16:47:40 +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
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
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
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
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
Oliver Laurent 306d5c89a0 [FIX] orm: do not resize unlimited char fields 2014-06-05 19:05:36 +02:00
Thibault Delavallée 066fb14326 [FIX] orm: unlink: when unlinking a record, trigger the computing of
function fields for other records in the same model. Previously all function fields in the
current model were not computed for some reason not provided by the history.

We therefore compute effective store_ids on which the various trigerred
function fields will be computed again. Those ids are the ids given
in the store_get storage variable minus the deleted ones.
2014-05-19 18:12:41 +02:00
Olivier Dony 5be9e5612f [FIX] browse()/browse_record: use iterables instead of forcing lists when constructing browse_lists
This allows iterable list_class implementations

bzr revid: odo@openerp.com-20140407105740-elbz311w5u9e8eos
2014-04-07 12:57:40 +02:00
Martin Trigaux 63763dcc55 [IMP] readability
bzr revid: mat@openerp.com-20140305143050-zddqtyh7qg6lcx3q
2014-03-05 15:30:50 +01:00
Martin Trigaux 016a1ed37b [FIX] orm: create a foreign key for the function fields of type many2one and store value
bzr revid: mat@openerp.com-20140305140514-2sksy3lwqm07wvjh
2014-03-05 15:05:14 +01:00
Olivier Dony b79a33aefc [FIX] orm.read_group: improve test coverage and corner case handling:
- allow leading spaces in orderby spec for m2o columns
- extra test for read_group on multiple columns
- proper handling of groupby on numeric column with default order

bzr revid: odo@openerp.com-20140304152927-havybom9x1jgdzae
2014-03-04 16:29:27 +01:00
Olivier Dony 27a1770e20 [FIX] orm.read_group: fix various issues introduced in recent commit, cleanup
Fixed the implementation of the sorting for inherited
columns, many2one columns, and aggregated columns.
Added corresponding tests with increased coverage of
the read_group() method.

bzr revid: odo@openerp.com-20140228173320-p8l0jc8op7xsgn1x
2014-02-28 18:33:20 +01:00
Martin Trigaux 43df0b4d23 [MERGE] [FIX] orm: when generating xml ids for export, use the model of the exported field instead of the current model. Courtesy of Stefan Rijnhart (Therp).
bzr revid: mat@openerp.com-20140226133716-vgdjjmqc2lou0n3u
2014-02-26 14:37:16 +01:00
Martin Trigaux 9515daa3f8 [MERGE] [FIX] read_group: skip date(time) fields when generating the sql query, the monthly grouping is done afterward
lp bug: https://launchpad.net/bugs/1282485 fixed

bzr revid: mat@openerp.com-20140220103351-n3ohwombd1kk802f
bzr revid: mat@openerp.com-20140220145445-0xt7alp3uj0os1fz
2014-02-20 15:54:45 +01:00
Anael Closson 5e593b34d0 [FIX] orm: grouping of date and datetime conflicts ordering on dates with date and datetime - hotfix
bzr revid: acl@openerp.com-20140220135127-1hh7s6dx6p2wuhz9
2014-02-20 14:51:27 +01:00
Anael Closson 7080279bde [FIX] incorrect handling of orderbys when generator for the groupby field generates more than one orderby clause item
bzr revid: acl@openerp.com-20140220095911-zd5j1ssjw0cwzzz2
2014-02-20 10:59:11 +01:00
Anael Closson 90dcc00443 [FIX] OPW 598942 : orm read_group doesn't take referenced fields or aggregated fields in account when sorting
Sorting was done using a search on ids that where found in a custom SQL field,
only 1 record among aggregated records with same groupby value was used
when using search for ordering, resulting data ordered on
max(aggregated_data).field_value instead of sum(aggregated_data.field_value).

lp bug: https://launchpad.net/bugs/1060086 fixed

bzr revid: acl@openerp.com-20140217172926-ka2fw8t2l3cqi7h3
2014-02-17 18:29:26 +01:00
Anael Closson f4f6bc3d9a [REF] removing debug code
bzr revid: acl@openerp.com-20140217140705-b2erer6w4mxba3l7
2014-02-17 15:07:05 +01:00
Anael Closson ac88131405 [IMP] Speed and quality improvement
- removing the need of the use of search when groupby is set on a relation
    field.
  - creation and use of dedicated helper method to compute the orderby clause
    for easier reading

bzr revid: acl@openerp.com-20140217140144-2rm3o00g76tyhqxn
2014-02-17 15:01:44 +01:00
Martin Trigaux ff389d8478 [FIX] remove useless cr.commit in fields creation
This is require to be able to create revertable tests adding new fields

bzr revid: mat@openerp.com-20140213120349-a0p3bist5l5uyg6b
2014-02-13 13:03:49 +01:00
Olivier Dony 391872c4d6 [FIX] orm.copy_data: avoid reading useless and possibly expensive data when copying records
Rather than reading the data and discarding it,
it is much faster to not read it in the first place.

bzr revid: odo@openerp.com-20140206170401-brd6368pe1fmbkkc
2014-02-06 18:04:01 +01:00
Anael Closson 30d22d327e [FIX] typo, wrong ordering of lines
bzr revid: acl@openerp.com-20140205125208-8ds2hxfqnuqsngbd
2014-02-05 13:52:08 +01:00
Martin Trigaux 6ea8851fd0 [ADD] test read_group on a column of _inherits model and group on right field
bzr revid: mat@openerp.com-20140203133331-mujvv812zd971ci2
2014-02-03 14:33:31 +01:00
Anael Closson f6207124f9 [FIX] OPW 598942 : orm read_group doesn't take referenced fields or aggregated fields in account when sorting
Sorting was done using a search on ids that where found in a custom SQL field,
only 1 record among aggregated records with same groupby value was used
when using search for ordering, resulting data ordered on
max(aggregated_data).field_value instead of sum(aggregated_data.field_value).

lp bug: https://launchpad.net/bugs/106086 fixed

bzr revid: acl@openerp.com-20140203125854-ypi0bu0lbhatg9b1
2014-02-03 13:58:54 +01:00
Martin Trigaux cafa5e7854 [FIX] orm: read_group aggregates values on all columns instead of only the one of the parent model
bzr revid: mat@openerp.com-20140203123311-38rwp7tfyc08flid
2014-02-03 13:33:11 +01:00
Christophe Simonis 2f90f80ba0 [FIX] orm: As float fields are stateful (the .digit attribute depend of the database (decimal_precision)), registry model instances need their owm copy.
lp bug: https://launchpad.net/bugs/929483 fixed

bzr revid: chs@openerp.com-20140116153708-061aq2k0n1qsb2n3
2014-01-16 16:37:08 +01:00
Martin Trigaux 3fb75a44c8 [FIX] orm: add missing context (without the lang attribute to avoid setting translated values) in write call.
bzr revid: mat@openerp.com-20140109153601-13wo9gj5cz6ho3nm
2014-01-09 16:36:01 +01:00
Guewen Baconnier 780e1548c0 [CHG] set lang to False instead of en_US (already being the default language), reducing the places where this default value is set
bzr revid: guewen.baconnier@camptocamp.com-20131228203801-3z6g1bb0ggfio5x0
2013-12-28 21:38:01 +01:00
Xavier ALT 9a4c62861f [FIX] orm: early return within ``_apply_ir_rules`` for superuser.
Save a few time by not not trying to apply ir.rule for superuser, that will
  anyway be skipped within ir.rule's ``_compute_domain`` method.

bzr revid: xal@openerp.com-20131210140330-oui4oy8pez12xkxv
2013-12-10 15:03:30 +01:00
Xavier ALT f5458a954d [FIX] orm: cleaner batch number of records for auto_init() stored fields.function update
bzr revid: xal@openerp.com-20131210122312-f3f4h0z4lpiagsk3
2013-12-10 13:23:12 +01:00
Cecile Tonglet 3b328aaab4 [FIX] Trigger stored field recalculation for inherited records
The create() method implicitly creates record on objects of the _inherits.
Therefore, in order to make the trigger on linked field works, we should
include all the _inherits values (field that makes the link to the rel
record) because they are created implicitly.

bzr revid: cto@openerp.com-20131209154857-788f94w0kh6ef5pp
2013-12-09 16:48:57 +01:00
Cecile Tonglet 2e197cbb98 [IMP] Batch for the computation of function's stored values is now customizable
bzr revid: cto@openerp.com-20131209141111-tbg9x1h8l6neu0ml
2013-12-09 15:11:11 +01:00
Cecile Tonglet cdff5c1366 [IMP] Performance: by-pass call to _apply_ir_rules for user admin
bzr revid: cto@openerp.com-20131205121118-0f9087y2huo7y44l
2013-12-05 13:11:18 +01:00
Martin Trigaux 9652fb0013 [IMP] orm: force checking ir.rules on read when accessing only to _classic_write fields (o2m, m2m, function)
More consistent behaviour. Was not able to access unauthorized data (retrieving data on x2m field would trigger security rules) but make sure it raises an exception instead of silently retrieve no data.
Move construct domain inside if clause as no needed before

bzr revid: mat@openerp.com-20131205113254-j3j4bb0p6ed23oht
2013-12-05 12:32:54 +01:00
Martin Trigaux e2102ca9ce [IMP] orm: add missing space in error message during validation
bzr revid: mat@openerp.com-20131125124717-4jsqv0lfu7hpxusi
2013-11-25 13:47:17 +01:00
Martin Trigaux 3b5cf5d56c [FIX] translations: fix tests to adapt to new duplication behaviour and remove context hack in copy_data (translations are now fully handled in copy_translation)
bzr revid: mat@openerp.com-20131125115727-o9oejao1ziagqti1
2013-11-25 12:57:27 +01:00
Martin Trigaux fbbc6ea840 [FIX] orm: when duplicating translated object, modify the values to get more coherent values
user's language: old (untranslated) -> new (translated)
other language: old (untranslated) -> old (translated)

This allows to have coherent behaviour if copy() method is overwritten to change the text (usually applying _('%s (copy)')). The current user will see the translated terms with modification while the translations are kept for others (and need to be updated).
We prefer keeping slightly irrelevant translations (without translated version of '%s (copy)') for other languages than losing it.

bzr revid: mat@openerp.com-20131125110736-d6iygeq8om5y4fkz
2013-11-25 12:07:36 +01:00
Martin Trigaux 10608a5d18 [FIX] ir_translation: correctly match old and new ids on inherit fields
new_id was correctly handled at rev 5118 but the old_id wasn't which could produce inconsistency if there was a gap in ids

bzr revid: mat@openerp.com-20131122175939-lvlf4ih4pyidqxjp
2013-11-22 18:59:39 +01:00
Olivier Dony b7865502e4 [FIX] orm.browse_record: access error due to prefetch of indirectly referenced records (OPW #596679)
The browse_record prefetching algorithm attempts to
load data for all known records from the requested
model (i.e. all IDs present in the browse cache),
regardless of how indirectly/remotely they were
referenced. An indirect parent record may therefore
be prefetched along with its directly browsed children,
possibly crossing company boundaries involuntarily.

This patch implements a fallback mechanism when
the prefetching failed due to what looks like an
ACL restriction. This being a fuzzy concept at the
moment, it does its best to only catch a restricted
set of exceptions, and retry loading the data for
the directly requested ID only.

This may cause a small performance penalty in case
of real errors (with some spurious logging too),
but should only be triggered in very few cases.

The downside when this happens is that the prefetching for that
model gets effectively disabled, requiring multiple
SQL queries for further access to the data of
the other directly browsed records.

This EAFP approach seems safer and faster than
a LBYL technique where we would have to filter
all indirect m2o references according to ACLs
before allowing them to enter the cache.

lp bug: https://launchpad.net/bugs/1238042 fixed
lp bug: https://launchpad.net/bugs/1212429 fixed

bzr revid: odo@openerp.com-20131120100627-031fljyf4ckprc9b
2013-11-20 11:06:27 +01:00