Commit Graph
205 Commits
Author SHA1 Message Date
Christophe Simonis cf52a04979 [MERGE] forward port branch saas-12.1 up to d3b8422c9c
closes odoo/odoo#30614
2019-01-28 13:58:11 +00:00
Raphael Collet 139595d441 [IMP] fields: allow reuse of the m2m relation if explicitly given
This allows a model to have several fields using the same relation on purpose,
for instance to show the related items filtered by domains.

Also adapt the code to handle multiple many2many inverses.

closes odoo/odoo#30338
2019-01-18 11:09:21 +00:00
Raphael Collet 05861ffdf1 [IMP] fields: check for inconsistent many2many definitions
closes odoo/odoo#29323
2019-01-16 09:16:41 +00:00
Christophe Simonis d7c5bc02cc [MERGE] forward port branch saas-12.1 up to 8aa8548d8a 2019-01-09 19:59:27 +01:00
Xavier Morel 66f0e26f6f [CHG] *: make binary fields default to attachment=True
Check that it makes custom binary fields into attachment as that's the
main reason for the change: when users create binary fields via Studio,
they're necessarily db-stored (as the interface doesn't allow altering
the attachment attribute and it's unclear how we'd handle users
switching it on/off every time), which significantly bloats their
database (and burns storage & backup space), especially as the primary
use case for binary fields is adding images and documents to records.

* check that binary fields are properly created as attachment=True
* add attachment=False on fields where that seems relevant (most but not
  all of the fields previously using the default)
* remove occurrences of attachment=True

closes odoo/odoo#29308
2018-12-07 13:37:34 +00:00
Raphael Collet 499cdd5708 [FIX] fields: combine special values during onchange
Consider a many2one field `foo_id` on model `bar`, with an inverse one2many
field `bar_ids` on model `foo`.  During an onchange, the statement

    bar.foo_id = foo

puts a special value in cache to add `bar` to the value of `foo.bar_ids`
without explicitly reading `foo.bar_ids`.

Executing the above statement a second time, the cache of `foo.bar_ids` is no
longer empty.  This causes the actual value of `foo.bar_ids` to be read and
updated.  The issue is that this can be slow for large values of `foo.bar_ids`.

Avoid reading the value of the one2many field by handling the case where the
cache contains the special value: simply update the special value to take into
account the second assignment.

closes odoo/odoo#28982
2018-11-23 11:18:19 +00:00
Christophe Simonis afe0133302 [MERGE] forward port branch saas-11.3 up to 3e54704e66 2019-03-06 10:59:32 +01:00
Olivier Dony b9ec95a8cb [FIX] fields: delete o2m lines before creating new ones
After 12744bc81ebdaa1671a953c14ba54c637d6a9255, x2m operations are
fully batched, and deletions are processed last when the operations are
flushed, regardless of the order in which they were specified by the
write() or create() call.

This carries a risk of violating (non-deferred) unique SQL constraints,
when the operations for deleting previous lines and re-creating new
ones are processed in the same batch.

This patch executes the deletions before other operations during a
flush, which should be safer with regard to SQL constraints.

An extra constraint is added in test_performance.line to simulate this
corner case, then covered by an extra unit test.
Another unrelated test had to be altered to avoid violating the
new constraint.

This can be reproduced easily by upgrading the `project` module in master,
due to the unique constraint[1] on `ir.actions.act_window.view`, that
gets violated when processing the batch write on this o2m[2].

[1] https://github.com/odoo/odoo/blob/ccc42f16/odoo/addons/base/models/ir_actions.py#L288-L289
[2] https://github.com/odoo/odoo/blob/ccc42f16/addons/project/views/project_views.xml#L394-L396

closes odoo/odoo#28314
2018-11-05 11:11:26 +00:00
Raphael Collet 650074e8b2 [IMP] fields: faster x2many fields
Perform all operations in batch, except for updates (command (1, id, vals)).

closes odoo/odoo#28029
2018-10-30 15:08:02 +00:00
TWA 983c7e8152 [IMP] mail,crm,...: Replace occurences of name_get()[0][1] by display_name
Purpose
=======

display_name is equal to doing name_get()[0][1]

Replacing name_get()[0][1] by display_name could be good for 2 things:
- Uniformization of the code
- Probable optimization if name_get is used inside a for loop on a recordset (as the values will be prefetched and put in the cache).

TaskID: 1849250

closes odoo/odoo#26341
2018-10-09 11:28:00 +00:00
Pedro M. Baeza 1be50fdeaf [ADD] *: support SVG images
Introduce official support for SVG files in the framework, including the
following parts:

1. When client-side SVG images are uploaded, the content is displayed until
you save using data URI scheme according RFC 2397 [1]. This scheme requires
to specify content format. Using hardcoded "image/png" works for all images
types except SVG.
Type-sniffing is done using "magic byte" detection via the first base64
encode byte, so that the proper data URI scheme can be used.
This should not cause SVG-related security problems as the file is
displayed through `<img>` tag, which does not allow SVG scripting [2].

2. Make /web/image controller compatible with SVG

3. Add support for SVG files for company logo, which uses a dedicated
controller.

4. Resizing of SVG files is a no-op, as it makes little sense for a
vector-based format. We also want to avoid micro-alterations to the SVG
document (in "natural" viewport parameters) as we would store multiple
copies of the files in the filestore.

5. Because SVG files are inherently dangerous, upload of SVG files is
restricted to administrators, either by blocking it directly before
saving it in the database (binary fields with attachment=False), or by
neutering them to text/plain mimetype (for binary fields with
attachment=True)

6. Add tests for the SVG upload cases and for the non-admin uploads.

[1] https://tools.ietf.org/html/rfc2397
[2] https://www.w3.org/wiki/SVG_Security

Closes #26635
2018-10-03 17:48:01 +02:00
Christophe Simonis 43b63a0465 [MERGE] forward port branch saas-11.4 up to 57e387b645 2018-10-01 16:01:54 +02:00
Adrian Torres 52a8ed3c0c [IMP] fields: make related fields readonly by default
With this commit, any *explicitly* related fields will be `readonly=True`
by default.

*Implicitly* related fields (i.e. _inherits fields) however will keep the
source field's `readonly` attribute.

The rationales behind this patch are:
    * Enforce good practices, as the most common use-case for
      related fields is the same as for compute fields: to read data.
    * Avoid errors where some user saves a form view which contains
      a related field that the user doesn't have write access to.
2018-09-27 12:10:23 +02:00
Moens Alexandre 21e44d472d [DOC] base: more explicit documentation
compute_sudo has no effects on non stored computed fields.
It was technically already said in the previous lines (REcomputed) but
it was not particularly explicit

closes odoo/odoo#31320
2019-02-21 13:00:47 +00:00
Goffin Simon 1ec6c069aa [FIX] base: Traceback when uploading a file with no ASCII name
When trying to upload a file with no ASCII name, it raised a
traceback saying: "UnicodeEncodeError: 'ascii' codec can't encode character ..."

opw:1886602
2018-09-24 09:25:53 +02:00
Raphael Collet 71613d9eab [FIX] fields: avoid _update to raise AccessError
During an onchange, setting a many2one field automatically updates its inverse
one2many field.  If the update raises an exception, catch it and put it in
cache, so that it is re-raised when the value is read from the cache.
2018-09-18 16:00:32 +02:00
Xavier Morel c3216db4c1 [IMP] fields: performance of creating with m2m fields
Note: all costs are according to cprofile on my machine, as a fraction
of total time to import, python-flamegraph has somewhat different cost
distributions, YMMV. Profiles use test-import of a 2500 partners file,
with name, country, street and 0~4 tags, all randomly
generated/assigned.

Costs were profiled as split 8.5%/32%/57% between data conversion,
creating records (Model.create/Model._create) and populating stored
computed fields for a total import time (unprofiled) of 1mn (±2s or
something).

For the creation step, 27% (of total runtime) were assigned to the m2m
(fields.Many2many.create), almost all of which (25%) was assigned to
accessing a record's id in a listcomp in a loop.

Optimisations:

* optimise the case where we're only adding / creating values:
  represent the relation as a dict of sets instead of a set of pairs;
  commands 5 and 6 will only operate on the current record's value,
  instead of traversing all pairs in the relation
* optimise accessing the value of an id field by hand-inlining the
  various bits, this is mostly obviated by the other previous
  optimisations (number of Id.__get__ calls reduced from 5.4 millions
  to 0.55) but given how common accessing a record's id is (and
  how it's usually considered to be free) it's still a good idea: cost
  of accessing the id field was reduced by 75% (0.55 million accesses
  went from 3.32% of total runtime to 0.83%)

Without profiling, time to import my test file went from ~1mn to ~45s.
2018-09-11 16:43:55 +02:00
jem-odoo a6401391ed [FIX] fields: raise when setting aware datetime
Now that Date/Datetime fields use python naive datetime, we want
to prevent developper to call  or assign aware datetime to
fields. Moreover, if so, the timezone will be stored in the
database, but when reading Datetime fields, we expect naive datetime.
Comparing naive and aware datetime objects leads to errors.

This commit forces developpers to use naive datetime when saving
data in database.

As example, we have to erase the timezone of dates in calendar
modules. We also regroup the 2 assignations in one call to
`write` for performance reason.

Thanks to @dbeguin and @RomainLibert for spending some time
on this bug.
2018-09-05 15:05:33 +02:00
Raphael Collet 7ba9acea18 [FIX] fields: context on Many2many field 2018-08-23 21:38:57 +02:00
Mohammed Shekha 8fbadb9575 [ADD] base_import: debug option to create M2O/M2M records
Adds a checkbox to import columns (in debug mode) allowing a user to
create records M2O and M2M records not found (via name_search).

Task ID: 1850633

* uses a context key to avoid altering basically all the import callstack
* attempted to lift the creation in the `_str_to_*` functions and create
  m2m via commands, but that doesn't really work out
2018-08-16 11:10:35 +02:00
Raphael Collet 960360afe4 [REF] *: use native date/datetime for Date/Datetime fields
From this commit onwards, Date fields will return datetime.date objects and Datetime fields will return datetime.datetime objects, this implies a number of things that are clearly explained both in the ORM API for master.

This commit also introduces a number of helper functions for dates and datetimes that are exposed in tools.date_utils and fields.Date[time], explained in the documentation as well.

Task-ID: 47189
2018-08-06 14:37:19 +02:00
Christophe Simonis ba202dbe63 [MERGE] forward port branch saas-11.2 up to 3c521f6d05 2018-07-24 18:10:32 +02:00
Raphael Collet 3b710ed640 [IMP] fields: optimize field.write for batch creation 2018-07-24 16:58:14 +02:00
Raphael Collet b1e83fd7b8 [REF] models: make create work in batch
Add a decorator `model_create_multi` to indicate whether a `create` method is
implemented to work in batch.
2018-07-24 16:58:14 +02:00
Christophe Simonis 4e76173a43 [MERGE] forward port branch 11.0 up to 219d2296d6 2018-07-23 16:03:25 +02:00
Xavier Morel 9f8eae34d1 [FIX] undefined variables (potential nameerror)
Backport 9ec0455abc and
6a601fe6dc as they fixed various
possible NameError but did so in later sub-releases.
2018-07-19 13:37:10 +02:00
Christophe Simonis f36e6917bd [MERGE] forward port branch saas-11.3 up to 37eed7c509 2018-05-29 17:34:43 +02:00
Raphael Collet 6a601fe6dc [IMP] test-pylint: check for undefined variables 2018-05-16 13:58:39 +02:00
Christophe Simonis bca769a1e8 [MERGE] forward port branch saas-11.2 up to e70e5b6cf3 2018-05-14 17:31:53 +02:00
Christophe Simonis e70e5b6cf3 [MERGE] forward port branch 11.0 up to 2787de8c68 2018-05-14 16:46:11 +02:00
Raphael Collet 7f27992998 [FIX] fields: convert selection value to int
When a string value is assigned to a selection field expecting integers, the
value simply rejected.  In such a case, convert the value to an integer before
validating it.
2018-05-14 12:08:59 +02:00
Christophe Simonis 1f22b81203 [MERGE] forward port branch saas-11.2 up to 7113b70762 2018-04-23 19:36:25 +02:00
Christophe Simonis e8bf128318 [MERGE] forward port branch 11.0 up to 3ab25b60bc 2018-04-23 18:15:25 +02:00
Nicolas Lempereur 96ce375c61 [FIX] models: more than one prefetch in onchange
When a record fields are prefetched, the currently accessed record is
prefetched as well as PREFETCH_MAX (=1000) minus currenly accessed
records.

Since 439fa826 the id field was thought as "prefetched" but was not,
which caused that in an onchange, we would have a prefetching as follow
for 1200 records:

- get records 1-1000
- get record 1001 (1001-1200 INTERSECTION 1-999 (id) + 1001 (current))
- get record 1002 (1002-1200 INTERSECTION 1-999 (id) + 1002 (current))
- get record 1003 (1003-1200 INTERSECTION 1-999 (id) + 1003 (current))
- ...
- get record 1200 (1200 INTERSECTION 1-999 (id) + 1200 (current))

So we would do 201 queries instead of 2 when prefetching the records.

The added test without this change failed the query count with:

 "AssertionError: 284 not less than or equal to 5 : admin"

opw-1837548
opw-1837552
closes #24326
2018-04-20 10:54:29 +02:00
Christophe Simonis e82030433d [MERGE] forward port branch saas-11.2 up to 7084a5190c 2018-04-19 16:33:40 +02:00
Christophe Simonis 7084a5190c [MERGE] forward port branch 11.0 up to 841f3914cc 2018-04-19 15:04:26 +02:00
Christophe Simonis 75853066a1 [MERGE] forward port branch saas-14 up to c638cb4d56 2018-04-19 13:10:53 +02:00
Christophe Simonis c638cb4d56 [MERGE] forward port branch 10.0 up to 23431389c3 2018-04-19 13:10:12 +02:00
Raphael Collet c9caf55177 [FIX] models: bad setup of inherited custom fields
Assume a custom field F is defined on model 'res.partner'.  The setup of F may
silently fail because of missing stuff.  In that situation, setting up the
field inherited from F on model 'res.users' should also silently fail.

To reproduce the bug, install Invoicing, create a related custom field F on
'res.partner' with 'property_account_position_id.active', and install another
module.  Setting up F after loading module 'base' will fail because the field
'property_account_position_id' does not exist yet.  The error is not caught by
the inheritance of F on model 'res.users', and the installation crashes.
2018-04-19 10:00:49 +02:00
Raphael Collet 23431389c3 [FIX] models: bad setup of inherited custom fields
Assume a custom field F is defined on model 'res.partner'.  The setup of F may
silently fail because of missing stuff.  In that situation, setting up the
field inherited from F on model 'res.users' should also silently fail.

To reproduce the bug, install Invoicing, create a related custom field F on
'res.partner' with 'property_account_position_id.active', and install another
module.  Setting up F after loading module 'base' will fail because the field
'property_account_position_id' does not exist yet.  The error is not caught by
the inheritance of F on model 'res.users', and the installation crashes.

OPW 1835872
2018-04-18 17:26:05 +02:00
Raphael Collet 0eb8518786 [IMP] fields: describe group_operator when given on all field types 2018-04-06 10:57:02 +02:00
Christophe Simonis b51f2d38c2 [MERGE] forward port branch saas-11.2 up to 500e3f4970 2018-03-21 11:04:48 +01:00
Christophe Simonis e0345a4a3f [MERGE] forward port branch 11.0 up to 2835d29979 2018-03-20 11:45:11 +01:00
Christophe Simonis c921d94236 [MERGE] forward port branch saas-15 up to 3730a0d2df 2018-03-13 12:05:36 +01:00
Christophe Simonis 3730a0d2df [MERGE] forward port branch saas-14 up to 0e898eae35 2018-03-12 18:48:15 +01:00
Christophe Simonis 0e898eae35 [MERGE] forward port branch 10.0 up to 0440e25380 2018-03-12 18:16:02 +01:00
Nicolas Martinelli 2021f44c0e [FIX] fields: empty date or datetime
When the `create` or `write` method receives an empty string for a date
or a datetime field, PostgreSQL will fail since this is not an accepted
value for this field type.

We fallback on `None` for falsy values.

opw-1819336

@KangOl : watch out when forward-porting, the signature of
`convert_to_column` has changed in saas-14.
2018-03-12 12:01:42 +01:00
David Arnold 231cae2e7f [FIX] fields: copy_cache with failed values onto sudo env (#23122)
Do not copy failed values, as they usually reveal access error that should
not occur in the sudoed env.

Closes #23121
2018-03-12 10:14:01 +01:00
Christophe Simonis 0f57bdba72 [MERGE] forward port branch saas-11.2 up to 42659dc70c 2018-03-09 16:25:58 +01:00
Adrian Torres bbfb098a54 [IMP] fields: allow shared fields
Given the following variables:
    * Module A
    * Module B
    * Model M
    * Field X of model M

If module A defines M.X and is installed, an xmlid for this field is
generated in the form of A.field_M_X

Before this commit:

If module B defines M.X as well and is installed after module A, no
xmlid is generated.

This means that if module A is uninstalled, the single xmlid pointing to
M.X will be deleted and thus, the field itself will be deleted as well,
therefore any views from module B referencing M.X will crash.

After this commit:

If module B (or any subsequent modules) define M.X, an xmlid will be
generated in the form of B.field_M_X.

If module A is uninstalled, the xmlid A.field_M_X will be deleted, but
B.field_M_X will remain and thus the field itself won't be deleted.

This system means that for a single actual field, there can be multiple
xmlids, each xmlid sharing the same field, thus the name "shared
fields".

Task ID 38016
2018-03-09 15:44:39 +01:00