Commit Graph

23 Commits

Author SHA1 Message Date
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
Raphael Collet 446d59fd44 [IMP] api: improve documentation of `api.onchange`
This fixes #3968.
2015-10-02 11:58:44 +02:00
Xavier Morel 2474a91bc9 [IMP] doc: recommend not using @api.one
* alter docstring of @api.one to mark it as deprecated for 9.0,
  recommend using @api.multi instead
  - deprecation notes were not correctly styled, add styling
    matching "warning" alerts
* move @api.one down the doc page to deemphasize it
* fix "backend" tutorial to remove all instances of ``@api.one``

closes #8527
2015-09-15 14:38:45 +02:00
Xavier Morel 95e56a109d [ADD] doc: new theme
Pretty much completely rewritten theme with custom HTML translator and a
few parts of the old theme extracted to their own extensions.

Banner images thought not to be that huge after all, and not worth the
hassle of them living in a different repository.

co-authored with @stefanorigano
2015-07-07 11:22:50 +02:00
Denis Ledoux b7f1b9c01e [FIX] models: recompute nested old-style computed field
The `set` method of the one2many class returns a list
of the fields that require recomputation,
the computing of the function fields being delayed
for performances reasons.

Nevertheless, if the `set` method was called
through another `set` method, in other words,
nested `set` calls, the fields to recompute returned
by the second, nested, call to set were never recomputed,
the result list were simply lost.

e.g.:
```
create/write
│set
└─── create/write with recs.env.recompute set to False
    │set
        └─── create
             with recs.env.recompute set to False
```

To overcome this problem, the list of old api style
compute fields to recompute is stored
within the environment, and this list is cleared
each time the store_set_value has done its job of
recomputing all old api style compute fields.

opw-629650
opw-632624
closes #6053
2015-05-06 17:25:44 +02:00
Raphael Collet 071152216f [FIX] fields: when computing digits, use an existing cursor instead of a new one
The computation of property `digits` was creating a new cursor to call the
function that determines digits.  This technique is fragile because the current
cursor may have pending updates that the new cursor will not see.

The issue was discovered by Cécile Tonglet (cto).  She observed an infinite
loop during a database migration, and a traceback inside the loop showed the
presence of the `digits` property.  This change fixes the infinite loop issue.
2015-05-05 17:33:16 +02:00
Denis Ledoux c9154e08aa [FIX] api: environment recomputation
In a workflow context (for instance, in the invoice workflow),
context is not passed.

Therefore, relying on the 'recompute' key being the context
in order to not recompute the fields does not work with Workflows.

It leads to huge performance issues,
as fields are recomputed recursively (instead of sequentially)
when several records are implied.
For instance, when reconciling several invoices with one payment
(100 invoices with 1 payment for instance),
records of each invoice are recomputed uselessly in each workflow call
(for each "confirm_paid" method done for each invoice).

With a significant number of invoices (100, for instance),
it even leads to a "Maximum recursion depth reached" errror.

closes #4905
2015-02-12 14:57:31 +01:00
Raphael Collet 4fd8e40ff7 [FIX] fields: add a flag "compute_sudo" to recompute fields as user admin
This reverts commit 8cd2cc8910.

It turned out that forcing recomputing fields as user admin breaks some
existing behavior.  Instead, we make the recomputation as user admin explicit
by adding compute_sudo=True in the field's definition.
2015-02-09 09:57:34 +01:00
Stefan Rijnhart 0fc5860fca [IMP] api decorator allow both res_id as well as id
As in python id is a builtin function name.

Closes: #5027
2015-02-09 01:10:36 +01:00
Raphael Collet 8cd2cc8910 [FIX] models: recompute fields with user admin to prevent access rights issues 2015-01-22 15:32:18 +01:00
Raphael Collet 309e3def30 [FIX] api: fix api decorators to not add '_api' on original methods
This fixes an issue where the same function is used in several model classes:
once the function is wrapped for the first class, it is erroneously considered
as a wrapper for the second class, and is therefore not wrapped in other
classes.
2015-01-15 16:43:46 +01:00
Raphael Collet cd2a432362 Merge pull request #3645 from odoo-dev/8.0-fix2manyupdateonchanges-chs
[FIX] api: avoid to return all fields *2many in onchanges
2014-11-25 12:42:36 +01:00
Raphael Collet 908252ec88 [FIX] tests: make sure that a failed tests does not leave the environment dirty
When a failure occurs, or when exiting an assertRaises(), the environment
should not contain fields to recompute.
2014-11-17 14:07:42 +01:00
Denis Ledoux 999ed04c40 [FIX] api: avoid to return all fields *2many in onchanges
When an onchange returns a change in a 2many field line (a '1' tuple, update), avoid to return all fields of the *2many field but only the altered field.

Otherwise, the web client regard all the fields of the 2many as dirty, and try to write on all fields (even if the value is the same, thus)

opw-615062
2014-11-14 14:24:11 +01:00
Raphael Collet 044ed06fec [FIX] models: do not prefetch fields to recompute, and recompute once only
The method _prefetch_field() was accidentally prefetching fields to recompute;
which was skipping the actual recomputation, since a value was put in cache.
But sometimes the field's value was fixed by an extra recomputation of the
field.  Here we remove the extra recomputation and fix the cache corruption.
2014-10-13 12:38:59 +02:00
Denis Ledoux 1c6c289f7b [FIX] api: clear environments on module installation 2014-10-02 17:46:25 +02:00
Samus CTO 176e14d2bc [IMP] api: compute methods cannot depend on field 'id'
This feature hasn't been implemented because of complexity problems.
Therefore, we should not allow the developer to use it.
2014-09-15 15:06:44 +02:00
Raphael Collet 4ce06c238b [FIX] openerp.api.Environment: move recomputation todos into a shared object
This fixes a bug which is usually triggered in module account_followup, but
does not occur deterministically.  Some recomputations of computed fields are
apparently missing.  Environment objects containing recomputations todos and
kept alive by a WeakSet, are removed by the Python garbage collector before
recomputation takes place.  We fix the bug by moving the recomputation todos in
a non-weakref'ed object.
2014-09-04 10:18:55 +02:00
Raphael Collet 2ad092b5e5 [ADD] doc: new documentation, with training tutorials, and new scaffolding 2014-08-22 17:51:20 +02:00
Raphael Collet 0c20403744 [IMP] api: improve documentation of decorators constrains, depends, onchange 2014-08-08 14:34:29 +02:00
Raphael Collet 18314cf645 [IMP] openerp.api: improve documentation 2014-08-04 09:49:35 +02:00
Xavier Morel ac282e0294 [FIX] unsafe listification of weakref in Python < 2.7.4
Fixes #966

* As a preallocation optimization, ``list()`` calls ``__len__`` on its
  parameter if it's available
* Before Python 2.7.4, WeakSet has a bug[0] where ``len()`` is unsafe: it is
  done by iteration and weakrefs may be removed from the underlying set during
  the iteration

As a result, the safety feature of listifying a WeakSet to ensure we have
strong refs on all items during iteration may blow up.

Wrapping the weakset in a ``iter()`` makes ``__len__()`` invisible and ensures
we're within the IterationGuard[1].

Which now that I think about it means we *should* be able to safely iterate
weaksets in the first place and may not have needed to listify them...

[0] http://bugs.python.org/issue14159
[1] http://hg.python.org/cpython/file/b6acfbe2bdbe/Lib/_weakrefset.py#l58
2014-07-07 13:51:53 +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