Commit Graph
354 Commits
Author SHA1 Message Date
Martin Trigaux a1fbb3d389 [FIX] base: translate _constraint message
While the error content is automatically translatable, the header was not.

Fixes #5645
2016-08-08 11:54:32 +02:00
Christophe Simonis 10550aa5a5 [MERGE] forward port of branch saas-6 up to e68ed41 2016-06-28 13:11:35 +02:00
Christophe Simonis 4030f2fd32 [MERGE] forward port of branch 8.0 up to 297bbff 2016-06-23 16:21:28 +02:00
Raphael Collet ff93777099 [FIX] models: inverse several computed fields based on a common computed field
Consider fields G1 and G2 being computed fields with inverse methods that
require the value of a common dependency F, which is also a computed field.
For inversing G1 and G2, their values are put in cache, then their inverse
method is called.  If the inverse method of G1 requires the computation of F,
setting F's value will invalidate both G1 and G2 in cache.  Hence the value of
G2 is lost when invoking its inverse method!

The fix consists in marking G1 and G2 as being computed before invoking their
inverse method, which prevents them from being invalidated by field F.
2016-06-22 14:01:59 +02:00
Christophe Simonis e37ba61832 [MERGE] forward port of branch saas-6 up to b87a93a 2016-06-20 14:20:03 +02:00
Christophe Simonis b87a93a091 [MERGE] forward port of branch 8.0 up to 5b1beec 2016-06-20 13:34:46 +02:00
Christophe Simonis 5b1beec1f2 [FIX] models: commit *before* trying to set NOT NULL constraint
Setting NOT NULL constraints on required fields may fail if there are
any row with unset value for this column.
The ORM handle this case by catching the exception raised and warning
user.

However, not commiting the current transaction before, will rollback
changes made before like setting default values or renaming a column.
2016-06-20 11:53:59 +02:00
Christophe Simonis 2f374c4cba [MERGE] forward port of branch 8.0 up to 3a32021 2016-05-12 12:38:02 +02:00
Nicolas Seinlet 3a32021122 [IMP] models: mark records as recomputed as soon as they are
When recomputing stored function fields, the `write` may trigger a
cache invalidation which lead to a recompute of all the recordset
values, even the ones already saved in database.
2016-05-12 11:44:57 +02:00
Christophe Simonis ac16454965 [MERGE] forward port of branch saas-6 up to ba34df1 2016-04-25 12:40:13 +02:00
Christophe Simonis ba34df1ead [MERGE] forward port of branch 8.0 up to 0410d11 2016-04-25 11:56:52 +02:00
Raphael Collet 86d276b4bb [FIX] models: fix *2many multi-onchange bug
This fixes the case where the lines of a one2many field are modified several
times by onchange methods: instead of retrieving the most recent updates, we
merge them with former updates.

This solution was written as an improvement of a proposal made by Alexis
Delattre and Sébastien Beau as #11620.
2016-04-22 16:25:11 +02:00
Martin Trigaux fd7a7207ac [FIX] orm: do not save empty translation as 'false'
When writting a value on a translatable field in a different language than
English, the submitted *raw* value was saved in the database.

This could cause the following issues:
- empty value (provided as `False` by the web client) saved as the string
  'false' in the translations table
- no encoding or sanitization convertion
- ignore size parameter on the translatable field

Process the submitted translation through symbol_set method to clean it before
storing it blindly in the database.

This allows to convert `False` into `''` for empty value and fixes #10862
2016-04-22 16:14:19 +02:00
Christophe Simonis 87d160a742 [FIX] models: partial loading of manual fields
Related and function manual fields may not be loadable during initial
setup (partial=True) due to dependencies being not loaded. Ignore
theses fields during partial loading.
2016-04-11 14:52:42 +02:00
Raphael Collet 2d77941844 [FIX] models: enable modification of the help of custom fields
The field was not used when building the registry, hence when synchronizing the
field back to the database, the field `help` was set to `NULL`.
2016-03-21 12:23:17 +01:00
Raphael Collet dd048ae730 [FIX] fields: skip missing triggers for computed custom fields
This improves ddafbab3e4 by still loading the
field, but be tolerant if setting its triggers fails.
2016-03-15 15:03:44 +01:00
Raphael Collet ddafbab3e4 [FIX] models: do not load custom fields with depends when partial=True
Upgrading a module in the presence of computed custom fields can fail, if a
computed custom field depends on another field from a module that is not loaded
yet.  The patch simply prevents custom fields with dependencies from being
loaded in partial mode.
2016-03-15 14:30:39 +01:00
Denis Ledoux db95dcd8bc [FIX] models: translate fields label, even for en_US
In Odoo 7.0 & 8.0, this was possible to translate
a field label, from `en_US` to `en_US`. It was
used as an easy way to change the fields label,
instead of creating an inherited view changing
the string attribute of the field everywhere it was needed.

This was no longer the case in 9.0,
following the revision 9593a29.

The translated terms for `en_US` have been
excluded, for performance reasons
as it was considered not possible to have
translated terms for the `en_US` language.

The fact is, this is very possible: Nothing
prevents to add a translated term
in `en_US` for a translate-able field,
as this is the case for the fields label,
as mentioned above. This field is then
used as the display value instead of the source
term when being in the `en_US` language.

Besides, the above revision was mainly to
give the possibility to sort a model records
on a translated field, using a join on the translations
table. It was then considered that the join could
be avoided, in the case where the user language was `en_US`,
for performance reasons, but, as this is possible
to give another value to the field value trough
the translations, it should actually be done, even
for the records sorting.

opw-670814
2016-03-03 13:21:56 +01:00
Christophe Simonis dd875ed1a1 [MERGE] forward port of branch saas-6 up to f5ed710 2016-02-24 18:02:53 +01:00
Christophe Simonis f5ed710c74 [MERGE] forward port of branch 8.0 up to d4e5019 2016-02-24 16:37:41 +01:00
Nicolas Martinelli 68f9f99ed3 [FIX] models: export of booleans
In the case of a `raw_data` export, a boolean which has the value
`False` will not be exported correctly.

The fix handles the `False` value as a valid value for a field.

opw-666142
2016-02-23 15:06:14 +01:00
Martin Trigaux c51c3254b8 [FIX] models: escape colomn name in read_group
In PostgreSQL, if not double-quoted, the columns are considered as lower case.
http://www.postgresql.org/docs/9.4/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Courtesy of Philippe Halbardier, SimplyCIT
2016-02-19 12:13:30 +01:00
Christophe Simonis f7432efb95 [MERGE] forward port of branch saas-6 up to 07d7147 2016-02-10 18:17:21 +01:00
Christophe Simonis 07d7147846 [MERGE] forward port of branch 8.0 up to cdf21eb 2016-02-10 18:03:42 +01:00
Laurent Mignon d82e489add [FIX] models: use column._symbol_c as placeholder for the column value
When generating SQL queries, `column._symbol_c` must be used as placeholder as
for the method 'set' of the column itself.  Otherwise it is not possible to
define specialized columns.
2016-02-09 09:20:17 +01:00
Olivier Dony 709323f071 [MERGE] Forward-port saas-6 up to 6562309927 2016-02-03 00:46:18 +01:00
Olivier Dony 6562309927 [MERGE] Forward-port 8.0 up to e8d06f7b20 2016-02-03 00:44:04 +01:00
Olivier Dony e8d06f7b20 [MERGE] Forward-port 7.0 up to bdbcbea285 2016-02-03 00:40:27 +01:00
Christophe Simonis fbd5fab238 [MERGE] forward port of branch saas-6 up to 9ca7ad8 2016-02-02 13:18:33 +01:00
Christophe Simonis 9ca7ad87b2 [MERGE] forward port of branch 8.0 up to 3ac46ee 2016-02-02 12:25:06 +01:00
Goffin Simon 08b286111c [FIX] models: MissingError when writing on recordset with duplicates
When writing on a recordset with duplicates, the ORM raises a `MissingError`
because the rowcount gives a difference with the injected ids.  The fix simply
eliminates duplicates from ids.
2016-02-01 14:56:49 +01:00
Martin Trigaux bb56e484b7 [FIX] all: construction of translations lookup
When evaluated, the translation function never finds a match if a variable is
integrated into the untranslated text.

SHAME! 🔔 🙋
2016-01-13 14:46:30 +01:00
Christophe Simonis 33299fd689 [MERGE] forward port of branch saas-6 up to 5eee559 2016-01-12 18:46:23 +01:00
Denis Ledoux 6a366b216b [FIX] models: order by translatable fields with multiple translations
When a model list is ordered on a translatable field,
a join on the `ir_translation` is done, so the order
is correctly done on the translation value rather
than the translation source (in English).

This join wasn't entirely correct: If there were
multiple translations for a same record field
(which should not happen, but which is not forbidden)
e.g. Two different translations for the name of a same product,
then this record appeared several times in the result of the query,
while this is expected to only have each record once
(Obviously, when you perform a search on products, you do not expect
to have multiple times the same products returned by the search query)

This had as side-effect, when searching records with a limit of 80
items, to return actually less than 80 items
(e.g. 72 products, with multiple translations),
and, as the limit of the search was not reached (e.g. 72 instead of 80),
the web client did not perform the `search_count`, as it does not do
it when the limit of the search is not reached (meaning there is no
more items than what has been returned by the search query), and therefore
the web client did not consider there was actually more results, more
pages of results.

In summary, the count of records of a model could be different
when performing the order on a translatable field from one
language to another.
(e.g. A database could return 150 products in English, but
only 72 in Spanish).

To solve this issue, we have required the use of the operator
`DISTINCT ON`, which provides the possibility to keep only
the first translation for each record according to a given
order (in this case, we keep the translation that has been
added the most recently)

From the PostgreSQL documentation:
DISTINCT ON ( expression [, ...] ) keeps only the first row
of each set of rows where the given expressions evaluate to equal.
The DISTINCT ON expressions are interpreted
using the same rules as for ORDER BY (see above).
Note that the "first row" of each set is unpredictable
unless ORDER BY is used to ensure that the desired row appears first

The performance of this new query is similar to the performance
of the former query.

opw-666071
2016-01-12 17:40:58 +01:00
Raphael Collet 02165536e4 [FIX] models: remove call to dead method log
Also remove the flag `_log_create` that was enabling the log.
2016-01-11 13:39:21 +01:00
Martin Trigaux 8b4f052a38 [MERGE] Forwardport of branch saas-6 up to c649bb0df 2016-01-05 18:28:06 +01:00
Martin Trigaux 955ed51687 [MERGE] Forwardport of branch 8.0 up to 6efc3712 2015-12-30 11:48:14 +01:00
Denis Ledoux 79a0d1defb Revert "[FIX] models: in onchange, add missing fields when comparing values"
This reverts commit 882bbf46e2.

This revision leads to a crash when creating a new user:

Traceback (most recent call last):
  File "/home/dle/odoo/9/openerp/http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/dle/odoo/9/openerp/http.py", line 680, in dispatch
    result = self._call_function(**self.params)
  File "/home/dle/odoo/9/openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/dle/odoo/9/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/dle/odoo/9/openerp/http.py", line 309, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/dle/odoo/9/openerp/http.py", line 959, in __call__
    return self.method(*args, **kw)
  File "/home/dle/odoo/9/openerp/http.py", line 509, in response_wrap
    response = f(*args, **kw)
  File "/home/dle/odoo/enterprise-9/web/controllers/main.py", line 907, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/dle/odoo/enterprise-9/web/controllers/main.py", line 899, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/home/dle/odoo/9/openerp/api.py", line 238, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/dle/odoo/9/openerp/api.py", line 369, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/dle/odoo/9/openerp/models.py", line 5998, in onchange
    record.mapped(name)
  File "/home/dle/odoo/9/openerp/models.py", line 5497, in mapped
    recs = recs._mapped_func(operator.itemgetter(name))
  File "/home/dle/odoo/9/openerp/models.py", line 5477, in _mapped_func
    vals = [func(rec) for rec in self]
  File "/home/dle/odoo/9/openerp/models.py", line 5715, in __getitem__
    return self._fields[key].__get__(self, type(self))
KeyError: u'in_group_18'
2015-12-23 17:59:36 +01:00
Xavier Morel f839c9358a [FIX] sudo() docstring
rST uses double-backticks for literal text, not single
2015-12-21 12:34:53 +01:00
xmo-odoo 7c0e734785 [FIX] strip group name before calling has_group
user_has_groups is used to check for groups in e.g. view attributes (`@groups`).
When trying to format lists of groups in views, it would break down as it would 
pass e.g. `\n        some.group` to `res.users.has_group`, which would look for 
an xid with the module `\n        some` and (oddly enough) not find it.

Theoretically could also handle that inside res.users.has_group but it seems
ever-so-slightly more risky, and has_group is only used programmatically and 
should thus already be called correctly.

fixes #9797
2015-12-21 10:30:37 +01:00
Raphael Collet 8325014b63 [FIX] models: when evaluating old-API onchanges, ensure all fields are available 2015-12-18 16:51:52 +01:00
Raphael Collet 882bbf46e2 [FIX] models: in onchange, add missing fields when comparing values 2015-12-18 16:51:52 +01:00
Christophe Simonis 521b90a8da [MERGE] forward port of branch saas-6 up to 12d7996 2015-12-08 15:17:06 +01:00
Christophe Simonis 12d799623c [MERGE] forward port of branch 8.0 up to 83a4a58 2015-12-08 13:03:08 +01:00
Martin Trigaux 27d439901c [FIX] base: create translations of a duplicated record
When creating translations (click on blue flag) of a duplicated record, it used
to have the module information of the duplicated record.
It is also not useful to check the module when trying to find if a translation
exists on this record as the res_id is present in the query.

Fixes #9480
2015-12-02 10:57:46 +01:00
Christophe Simonis 56a442e205 [MERGE] forward port of branch saas-6 up to dade7e3 2015-11-25 13:26:02 +01:00
Christophe Simonis 12d5b4168f [MERGE] forward port of branch 8.0 up to 8e1a5ad 2015-11-25 11:18:21 +01:00
Raphael Collet 8e1a5add38 [FIX] api: improve decorator returns to handle special cases, like method search
Add the possibility in the decorator to specify the `upgrade` and `downgrade`
functions that convert values between APIs.  Both function have the same API:

    upgrade(self, value, *args, **kwargs)
    downgrade(self, value, *args, **kwargs)

The arguments ``self``, ``*args`` and ``**kwargs`` are the ones passed to the
method, following its new-API signature.

Fixes #4944, #7830.
2015-11-25 09:59:35 +01:00
Denis Ledoux 32fd520d97 [MERGE] forward port of branch 8.0 up to 6f29cbe 2015-11-23 17:40:15 +01:00
Raphael Collet baa3ce58fd [FIX] models: update field transient only, and do not modify state
Fixes regression introduced at 4d9e36a459
that caused all custom (manual) models to be reset to "base" models.

This prevented the creation and proper use of custom models.

opw-657017
Closes #9670

Partial version of #9663
2015-11-20 17:36:23 +01:00