Commit Graph
205 Commits
Author SHA1 Message Date
Xavier Morel 3824b5dcc1 [FIX] P3: fix base64 and StringIO uses
* StringIO removed from stdlib, replace with io
* try to correctly handle BytesIO/StringIO (one is for bytes the other
  is for text)
* fix base64: Python 3 removed bytes-encoding and bytes-bytes
  codecs (via #encode) so replace all calls to str.encode('base64'),
  also b64encode is a bytes->bytes conversion so attempt to properly
  handle that

issue #8530
2017-08-20 23:25:54 +02:00
Christophe Simonis 48b2ce60ed [MERGE] forward port branch saas-16 up to 85571bb78c 2017-08-10 17:01:05 +02:00
Christophe Simonis 85571bb78c [MERGE] forward port branch saas-15 up to dde62073ba 2017-08-10 16:22:36 +02:00
Christophe Simonis dde62073ba [MERGE] forward port branch saas-14 up to a2361e23ea 2017-08-10 16:17:28 +02:00
Christophe Simonis a2361e23ea [MERGE] forward port branch 10.0 up to 544aa9b04a 2017-08-10 15:45:07 +02:00
xmo-odoo d140f0ef0e [FIX] prefetch issues on computed/related fields (#18644)
When deciding to prefetch records (getting records from the cache with
no value for the field being fetched), if the field was computed
`determine_value` would just get all records, not limited by the normal
prefetch limit; for large recordsets this would generate gigantic
prefetch lists for records we may not need at all.

Fix by applying the `PREFETCH_MAX` limit to records from the cache as is
done in `_prefetch_field`.

Complementarily, when traversing related fields the prefetch
environment would be lost and every record would get an empty prefetch
environment, so the values would ultimately be read one by one.

Example: select (search) 1000 product.product records, access a
related field (e.g. categ_id) in a loop, on the first iteration the
system would first read 1000 templates, then it would read each
categ_id individually, resulting in >1000 SQL queries rather than the
~2 we would expect.

Fixes #18511
2017-08-10 14:51:27 +02:00
Raphael Collet e25bcf41e2 [REF] models: group recomputation triggers to minimize the number of requests
When several fields are modified and trigger the same recomputations, the same
SQL queries were made to determine the records to recompute, because each field
was processed independently.  In order to avoid duplicated SQL queries, process
the triggers of the modified fields altogether.

This reduces the number of queries by 15% to 25%, depending on the number of
computed fields.
2017-07-10 16:18:33 +02:00
Xavier Morel b62ba7ee1a [FIX] P3: initialisation order of columns
Python 3's hash randomisation means columns can be iterated — and thus
initialised — in any order (within a given model/override anyway),
which means there can be an implicit dependency on column
initialisation order e.g. (res.company).currency_id has a default
which fetches the currency_id of the company_id of the administrator,
and res.company has a _order=sequence,name, if the currency_id field
is created before the sequence the SELECT query will blow up as the
sequence column will not exist yet.

Attempt to always manipulate (iterate & initialize) fields based on
their order of definition using a global sequence number.
2017-06-12 11:04:23 +02:00
Raphael Collet afef71d6b9 [FIX] Always round monetary values in database (#17010)
Let `create` and `write` round monetary field values before sending them to the
database. Pass the values to be written to `field.convert_to_column`, so that
the currency can be retrieved from the values, and the value be rounded.
2017-05-18 14:15:07 +02:00
Xavier Morel 54df4b36d7 [FIX] P3: types.NoneType removed 2017-05-15 12:26:29 +02:00
xmo-odoo 6659d5a7d2 [FIX] P3: metaclasses handling
* cross-version metaclass spec
* more formally deprecate browse_record and browse_null since they
  were using metaclasses anyway
* update docstrings referencing the latter
2017-05-11 15:25:36 +02:00
xmo-odoo fffaf735f5 [FIX] P3: list -> iterable builtins (#16811)
In Python 3:

* various builtins and dict methods were changed to return
  view/iterable objects rather than lists
* and the separate Python 2 view/iterable builtins and methods were
  removed altogether

This is problematic when using these items as list (which the happens
repeatedly in Odoo), but more viciously when iterating *multiple times*
over them (which also happens, which I've messed up multiple times while
writing this, and which is a pain to debug even when you've just created
the issue).

Convert all code using these to semantics-matching cross-version
helper functions to get the LCD behaviour between P2 and P3, and
forbid the builtins via lint.

issue #8530
2017-05-10 09:39:55 +02:00
Raphael Collet 59ee813a82 [IMP] fields: clean up comparisons to False 2017-05-03 15:54:36 +02:00
xmo-odoo b4429c2a91 [FIX] Various P3-related import changes
* LDAP import: python-ldap is not python3-compatible, pyldap is

  Warning: only supported from debian Stretch (current testing)?
  https://packages.debian.org/search?searchon=names&keywords=pyldap

* implicitly relative imports
* imports of moved or removed stdlib modules

issue #8530
2017-04-28 09:06:53 +02:00
xmo-odoo 2e6a589f41 [FIX] builtins removed from Python 3
* Reverse wrapper courtesy of @rco-odoo's original P3 branch
* thin compat module stripped down from werkzeug (to augment as needed)

issue 8530
2017-04-27 13:59:33 +02:00
Christophe Simonis b0992d082d [MERGE] forward port branch saas-14 up to 8f30e707e5 2017-04-13 15:31:27 +02:00
Christophe Simonis 13ad16104a [MERGE] forward port branch 10.0 up to 00e169c05a 2017-04-13 13:22:27 +02:00
Raphael Collet 3481f0faff [FIX] fields: recompute recursive stored fields 2017-04-11 15:34:34 +02:00
Christophe Simonis 2df5faa551 [MERGE] forward port branch saas-14 up to 2f68e9e93a 2017-03-28 18:05:31 +02:00
Christophe Simonis 2f68e9e93a [MERGE] forward port branch 10.0 up to 72fa3e8bda 2017-03-28 17:27:19 +02:00
Nicolas Lempereur f65475d68c [FIX] fields, web: improve form onchange to x2many
In a form view, when a field onchange lead to a change on a x2many,
there was two different behavior:

- if the x2many had an embedded view (eg. a tree view inside a form
view) the onchange would notify that it expected the x2many field in
this embedded view to be changed and handled the changes correctly.

- if the x2many had a default view, the onchange ORM would not be
aware the x2many could be modified and would not sent the changes
back causing blank or not updated x2m lines and error on save.

---

Two solutions were birthed to solve the second point:

=> PR #10557 = solving everything

With this PR the onchange in the ORM is aware of every fields in the
current view (even field in a x2m in a x2m in a x2m in a form view) and
if any of these are change the javascript gets back the value of the
fields present in the view.

This PR has currently not been merged by fear of changing too much and
anyway could only be done in master.

=> PR #12249 = if no field for x2many, send its form view fields

With this change, if the ORM onchange is not aware of the fields in the
x2many widget to returns, all the field in the x2m default form view are
returned.

This was merged in bbdf960 but introduced a number of other issue:

- in most situation the x2many is represented by a list view, which may
have fields missing of the form view,  so the original is still present.

- the view used may differ from the default form view in other way
(depending on value in context or other possibilities).

- the form view could have fields not present in the form view which
could end up in `write` on fields which should not be written to.

---

This commit reverts bbdf960 and adapts a small part of #10557 so the
x2many with default view works as an embedded x2many. For more than one
level (eg. a x2many in a x2many) this would still not work but it is
only solvable by a PR such as #10557 which could only be targetted for
master.

With this commit:

- the list of fields sent to ORM onchange is computed at the first onchange
- the fields from a x2many field default view is sent for onchange
- the initial onchange on record creation is delayed to when x2many are loaded

closes #12249, closes #15336, closes #15890
fixes #11236, fixes #12249, fixes #15129, #15419
opw-705965 opw-716095 opw-715619 opw-710440
2017-03-20 13:25:07 +01:00
Christophe Simonis 68176d80ad [MERGE] forward port branch saas-14 up to eddefc9948 2017-03-01 16:49:15 +01:00
Christophe Simonis 85368d7f86 [MERGE] forward port branch 10.0 up to 387b2acfcb 2017-02-23 20:15:38 +01:00
Christophe Simonis 387b2acfcb [MERGE] forward port branch saas-11 up to 1730dca101 2017-02-23 19:40:03 +01:00
Raphael Collet e78269664d [IMP] tools: use information_schema instead of pg-specific tables 2017-02-22 15:24:08 +01:00
Raphael Collet f8e573db23 [REF] models: refactoring of foreign keys 2017-02-22 15:24:08 +01:00
Raphael Collet dc82ff59ac [REF] models: in _auto_init, delegate field schema updates to fields
The fields objects are responsible for creating their column/table and indexes.
The methods that update the schema are overridden to handle cases specific to
each type of field.
2017-02-22 15:24:07 +01:00
Raphael Collet d024c76021 [REF] tools: add functions for SQL schema manipulation
This helps factoring out a certain number of similar queries, and removing a
few methods from `BaseModel`.
2017-02-22 15:24:07 +01:00
Raphael Collet 8225f36497 [IMP] models: speed up schema update for models
Simply remove most `commit()` statements from code that updates the database
schema.  This improves the performance of the schema update by 30%.
2017-02-22 15:24:06 +01:00
Raphael Collet 2b46025dd5 [REF] models: use Registry.post_init() for reflecting models, fields, relations and constraints 2017-02-22 15:23:48 +01:00
Raphael Collet b6103d0b1b [REF] models: foreign keys use Registry.post_init() instead of BaseModel._auto_end()
Also use Registry.post_init() for the creation of foreign keys in
`_sql_constraints`.
2017-02-22 15:22:26 +01:00
Raphael Collet d0591c18e5 [REF] base: refactor the API of model, field, constraint and relation reflection
Simplify the API as much as possible, and delegate all the implementation
details to the models `ir.model`, `ir.model.fields`, `ir.model.constraint` and
`ir.model.relation`.
2017-02-22 15:16:35 +01:00
Christophe Simonis fded0065ae [MERGE] forward port branch saas-14 up to 6c4389df41 2017-01-23 14:51:11 +01:00
Christophe Simonis 6c4389df41 [MERGE] forward port branch 10.0 up to 6804085b8c 2017-01-23 14:33:53 +01:00
Raphael Collet b0646f9d2c [REF] move support for sparse fields into a separate module (#15070)
This removal has led to a necessary refactoring:
- make the setup of field attributes extensible;
- make the instantiation of custom fields extensible;
- delegate model and field reflection to `ir.model` and `ir.model.fields`;
- move the implementation of sparse and serialized fields to module `base_sparse_field`;
2017-01-19 16:29:29 +01:00
Christophe Simonis f0a5618e61 [MERGE] forward port branch saas-11 up to 6169018c33 2017-01-18 16:21:55 +01:00
qdp-odoo 4f29b77e3d [MERGE] foward port of 10.0 up to revision 84a650e33a 2016-12-30 17:21:25 +01:00
Raphael Collet 253b1a8251 [FIX] performance: do not prefetch binary and serialized fields by default 2016-12-21 09:22:30 +01:00
Denis Ledoux 487c612f0c [FIX] web, orm: allow 0 as key for selection fields
Before this revision,
using a selection field with as possible keys `0`,
such as `require_payment` in `website_quote`,
resulted to the records field values to be stored
as `NULL` instead of `0` in the database.

This leads to the inability:
 - To distinguish records with this selection field not set
   or set to `0` (as both are stored as `NULL`)
 - To search for records with the field set to `0`
   (as they are considered not set)

For instance, while having `website_quote` installed,
search for sales orders with `Payment` set to
`Not mandatory on website quote validation`: It won't
return any result, even if you have some.

opw-697454
2016-12-12 18:18:51 +01:00
Christophe Simonis 8a808d1703 [MERGE] forward port branch 10.0 up to 8094970 2016-12-11 10:57:39 +01:00
Christophe Simonis 8094970df1 [FIX] fields: also protect computation of draft record fields 2016-12-11 10:24:29 +01:00
Christophe Simonis c292202a47 [MERGE] forward port branch 10.0 up to 18456b9 2016-12-09 15:58:39 +01:00
Christophe Simonis 18456b9d42 [MERGE] forward port branch saas-11 up to 321b7dc 2016-12-09 15:44:01 +01:00
Moises Lopez f507fc95c7 [IMP] fields: remove '_id(s)' from the label
For autogenerated labels.
Use title instead of capitalize to get every word with a capital letter.

Closes #12769
2016-12-07 10:47:04 +01:00
Christophe Simonis 13dc7041a6 [MERGE] forward port branch saas-12 up to 1ef4061 2016-11-17 15:24:36 +01:00
Christophe Simonis bcddba4e4b [FIX] fields: set attributes before accessing them
If renamed attributes are used, a warning is emit with `repr` of the
culprit field, which need attributes to be set.

Fixes #14036
2016-11-17 13:40:24 +01:00
Christophe Simonis 3d085f632d [MERGE] forward port branch saas-12 up to 6386037 2016-11-08 15:01:20 +01:00
Christophe Simonis 97debd09c0 [MERGE] forward port branch saas-12 up to 57774ef 2016-10-28 17:05:21 +02:00
Raphael Collet cae04ba1d3 [IMP] fields: add warning for field attributes select and digits_compute 2016-10-24 12:27:33 +02:00
Christophe Simonis 53d8f76a40 [MERGE] forward port branch saas-12 up to e8e4145 2016-10-17 16:00:39 +02:00