summaryrefslogtreecommitdiff
path: root/odoo/models.py
AgeCommit message (Collapse)Author
2019-04-10[MERGE] forward port branch saas-12.2 up to 2694174b410Christophe Simonis
2019-04-09[MERGE] forward port branch saas-12.1 up to 6d4940675f1Christophe Simonis
2019-04-09[MERGE] forward port branch 12.0 up to ea1fc124efcChristophe Simonis
2019-04-02[IMP] core: avoid to check access rules on empty recordsetXavier-Do
Checking access rules only makes sence if we have some records, _filter_access_rules will always return a subset or current recordset, and a subset or a empty recordset is an empty recordset. closes odoo/odoo#32313 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-04-04[FIX] base: upsert translations during copy_translationsMartin Trigaux
When doing a copy, create the new translations directly in SQL and handle potential conflicts. Conflicts can occure in case of reinstallation as showed in opw-1955062 and opw-1950117. In case of "leftovers" of translations (e.g. remaining after the uninstallation of a module), creating the new translations (when reinstalling the module) may produce a conflict with (type, name, res_id, lang) and raise an error. This is NOT a problem of reading .po file during installation (which handles correctly conflicts) but of business code creating new records and linked translations (e.g. website copying website.menu records). Removing old translations during uninstall is handled in a previous commit in ir.model.fields _drop_column method. This commit fixes the reinstallation on instances with leftover translations and fixes the issue without needing a manual intervention (i.e. delete the old translations manually). Closes odoo/odoo#32056 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-02-22[MERGE] forward port branch saas-12.1 up to 0f4abc5c228Christophe Simonis
2019-02-21[MERGE] forward port branch 12.0 up to 84143a34b31Christophe Simonis
2019-03-29[IMP] base: Remove useless ACL rulesYannick Tivisse
Now that portal users don't have access to the backend, it doesn't make sense to give the read access on attachments, as this is the role of the specific controllers to provide this access according to the business logic. For the record, these rules have been introduced at: https://github.com/odoo/odoo/commit/61065b6d04248aa496765e1035c4c90cbdc38de7 https://github.com/odoo/odoo/commit/f3fa266d115ac9d4723164af10f8dee40821b290 closes odoo/odoo#32134 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-02-20[MERGE] forward port branch saas-11.3 up to 2c495502aa3Christophe Simonis
2019-02-20[MERGE] forward port branch 11.0 up to de8cefcef4dChristophe Simonis
2019-02-13[FIX] models: check groups on inverse fieldsRaphael Collet
Before this, groups on non-stored inverse fields were not checked upon write. The impact on existing fields is pretty small, since the inverse methods of those fields are subject to access rights on the records they use. closes odoo/odoo#30357
2019-02-14[MERGE] forward port branch saas-15 up to c0f24d54cfaChristophe Simonis
2019-02-14[MERGE] forward port branch saas-14 up to c1fe9f18d5aChristophe Simonis
2019-02-14[MERGE] forward port branch 10.0 up to 69719f598aaChristophe Simonis
2019-02-13[FIX] models: check groups on inverse fieldsRaphael Collet
Before this, groups on non-stored inverse fields were not checked upon write. The impact on existing fields is pretty small, since the inverse methods of those fields are subject to access rights on the records they use. closes odoo/odoo#30356
2019-02-13[IMP] models: more meaningful comment for the `ensure_one` implementationYannick Vaucher
See discussion comment https://github.com/odoo/odoo/pull/30817#discussion_r255899919 This revision is related to ce0575ef274ec6419ffb08211461e7bdcbed1019
2019-03-08[MERGE] forward port branch saas-11.3 up to ecd8c023b7cChristophe Simonis
2019-03-08[MERGE] forward port branch 11.0 up to e5f93b83c68Christophe Simonis
2019-03-08[FIX] core: remove extra exception log, redundant in P3Jairo Llopis
Reverts 2b1d3ff82dd23fb0372b3b73ecb84841a0d593d3 introduced in 10.0 via It was relatively useful in Odoo 10.0 because in Python 2 the exception was missing a root cause traceback. But Python 3 includes exception chaining by default, so it comes for free. See [PEP3134](https://legacy.python.org/dev/peps/pep-3134/) On top of being redundant in P3, it can also break some testcases by causing an extra ERROR log entry, even when the final exception is expected and caught. So it's simpler to remove it. closes odoo/odoo#31699 Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2019-03-05[MERGE] forward port branch 11.0 up to 27081bf6f5fChristophe Simonis
2019-03-05[REV] orm: revert d855e3911faMartin Trigaux
This commit introduced a regression in web_studio, discovered at opw-1947380 A fix in web_studio will be integrated too but the regression is the proof this commit should not have been integrated in 11.0. While the new behaviour introduced at d855e3911fa makes more sense, it is still a change of behaviour that should not target a stable version. For the problem raised at opw-1887162 that d855e3911fa was trying to fix, a workaround should be used instead. For instance, setting a widget='html_frame' allows to translate in the website editor that handles this correctly. In master, the new behaviour can be maintained and eventual regressions will be investigated there. closes odoo/odoo#31585 Signed-off-by: "Martin Trigaux (mat)" <mat@odoo.com>
2019-03-04[MERGE] forward port branch saas-15 up to 1f1fa35c072Christophe Simonis
2019-03-04[MERGE] forward port branch saas-14 up to 232da9a0eceChristophe Simonis
2019-02-27[MERGE] forward port branch 10.0 up to 2f139632d60Christophe Simonis
2019-02-28[FIX] orm: backport of 06d73eab62 to 11.0Martin Trigaux
[FIX] models: do not erase master version For a translated field with a callable method (e.g. xml_translate), when modifying the value of this field in another language than en_US, the master version was lost. Before this patch: >>> record.arch = "<h1>Title</h1>" >>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>" >>> record.with_context(lang='fr_FR').arch "<h1>Titre</h1>" >>> record.arch "<h1>Titre</h1>" # lost English version After this patch: >>> record.arch = "<h1>Title</h1>" >>> record.with_context(lang='fr_FR').arch = "<h1>Titre</h1>" >>> record.with_context(lang='fr_FR').arch "<h1>Title</h1>" # write had no effect >>> record.arch "<h1>Title</h1>" When modifying a translated HTML field in English, a matching to detect the difference and avoid losing the translations is done. This is not supported for update in another language. The main reason is the difficulty to detect changes in the architecture. To update translations, the supported way is to go to the list of translations and update them there. Before this patch, the given value in another language was given to the SQL query and made an update in database: if single_lang or not (has_translation and field.translate is True) -> True or not (True and False) -> True If a field is callable, it should also be ignored, the same way than translate=True fields opw-1887162 closes odoo/odoo#31451
2019-03-06[REV] models: do not erase master versionMartin Trigaux
This commit has been backported in 11.0 [1] and then reverted [2], because it introduced a regression in web_studio, discovered at opw-1947380 As no forward-port has been done between the backport and the revert, the forward-port of the revert also contains the patch itself, resulting in a noop. Actually revert 06d73eab623e58427a7387879d242c320dc5d399 in branch `12.0`. [1] d855e3911fa40472f471439c5b3d78e3f7f493a8 [2] 1748b4671816a5b29f349978c2536eb6018a1bf0 closes odoo/odoo#31637 Signed-off-by: Christophe Simonis <chs@odoo.com>
2019-02-20[FIX] core: log unexpected validation exceptionsJairo Llopis
Before this patch, any exception raised by a constraint method that were not of type `ValidationError` were hard to debug, because the origin line was never logged. Explicitly logging the error (with traceback) when we catch it ensures proper contextual info, even in the absence of exception chaining. closes odoo/odoo#28612
2019-02-06[IMP] access errors through related fieldsXavier Morel
When an access error bubbles through a related field (aka the user doesn't have access to the delegate or the delegate's field), append the "intermediate step" so that it's easier to understand e.g. that the access error to a partner really comes from accessing a user or somesuch.
2019-02-06[IMP] access error messages on fields with groupsXavier Morel
2019-02-06[FIX] core, base: rules detail on access errorXavier Morel
In debug mode, if an access fails due to access rules, try to provide a clearer error message & include a list of the rules which fail for the record-set. Note: for read() operations it'll be a bit misleading as failed records will get a list of all the rules failing for the recordset, only some of which might apply to that specific record.
2019-01-31[IMP] models: remove orphan translationsMartin Trigaux
Same logic as for the mail.message or ir.attachment, when a record is deleted, drop the ir.translations linked to it as well. Fixes odoo/odoo#25105 Co-authored-by: Raphael Collet <rco@odoo.com> closes odoo/odoo#30721
2019-01-15[MERGE] forward port branch 11.0 up to 4f2f2995346Christophe Simonis
2019-01-15[MERGE] forward port branch saas-15 up to 3374ac805f1Christophe Simonis
2019-01-15[MERGE] forward port branch saas-14 up to 28785f21e42Christophe Simonis
2019-01-15[MERGE] forward port branch 10.0 up to 6edfadbdd2aChristophe Simonis
2019-01-08[MERGE] forward port branch 11.0 up to c07b7200b26Christophe Simonis
2019-01-07[MERGE] forward port branch saas-15 up to e1c7fefe894Christophe Simonis
2019-01-07[MERGE] forward port branch saas-14 up to cdb0c08cb9aChristophe Simonis
2019-01-07[MERGE] forward port branch 10.0 up to d4024a713c5Christophe Simonis
2019-01-03[FIX] models: avoid prefetch hell when reading fieldsRaphael Collet
The method `read()` may be very slow when reading relational fields and computed fields, because the computed fields can be computed on a recordset that is larger than expected. The issue occurs on model 'res.partner' when reading fields 'child_ids' and 'purchase_order_count', for instance. Suppose we read those two fields on a partner with 1000 contacts. First, the one2many field is read from the database and stored to the cache; the latter adds the value ids to the prefetching of 'res.partner'. Then, the fields are fetched from the cache. When 'purchase_order_count' is accessed on the partner, the field is computed on all its children as well... closes odoo/odoo#29867
2019-01-11[FIX] models: make prefetching more specific in read()Raphael Collet
Commit a07a076c45fc4b83caa9ab30ca919b30016015a7 restricts the prefetching to `self` when accessing the fields to return. This is too restrictive, as it cancels prefetching of secondary records in computed fields. In this commit we limit the scope of the restriction to `self`'s model only; this fixes the original issue without impacting other models. closes odoo/odoo#30133
2019-01-10[FIX] website: handle COW'd views during module install/updateRomain Derie
Since multi-website, we COW (copy on write) views when editing a view on a website. This is causing 2 issues related to module install/update: 1. During a module install, when creating an inherited view, it will create that view as expected on the generic tree. But that generic tree may not be used on website(s). Indeed, if the view was edited, we are now using a copy of the view instead of the original XML view (with an xml_id). That copied view won't get the new inherited view in its view tree. Now, we correctly copy the new view under every specific view tree (if exists). 2. During a module update, when updating a view, it will only update the view having the xml_id, so the generic one. But most of the time, the generic view is not used as it was usually COW'd and the specific view now replace the generic one. Now, we also apply the update on the COW'd view. Note that only unmodified field will be updated, this behavior basically mimic the noupdate behavior on view's ir.model.data. Step to reproduce for bug 1: - Install website_sale module - Go to a product page and then enter edit mode - Make a modification to trigger COW, eg edit the information area under the price "30-day money-back guarantee". - Now install website_sale_comparison module - The product page won't have the comparison button as the comparison view inheriting the product view was created on the generic tree and not copied on the specific tree (COW'd before the comparison module install). Step to reproduce for bug 2: - Repeat first 3 steps of bug 1 - Now make a modification in a view from the XML file in website_sale_comparison module and update the module - Only the view with the xml_id is updated, not it's COW'd views. This mean that only the generic view is updated and not the specific one(s) really used on the website. task-1920487 closes odoo/odoo#29956
2019-01-16[MERGE] forward port branch saas-11.3 up to 83cc046e9a9Christophe Simonis
2019-01-08[MERGE] forward port branch saas-11.3 up to 2d824a5b7adChristophe Simonis
2019-01-04[MERGE] forward port branch saas-11.3 up to 27a084eb814Christophe Simonis
2019-02-11[IMP] read, cache: faster read by updating the cache by fieldsDenis Ledoux
instead of updating the cache by records. We use `cr.fetchall()` and `zip` to get the values by field, which is more convenient to be stored in cache. Result of `cr.fetchall()`: ``` [ (3, 'Marc Demo', 'demo@example.com', '032'), (1, 'Mitchell Admin', 'admin@example.com', '001'), ] ``` After being grouped by field: ``` [ [3, 1], ['Marc Demo', 'Mitchell Admin], ['demo@example.com', 'admin@example.com'], ['032', '001'], ] ``` That way we can update the cache of a field for all records at once, by calling the builtin `update` method of `dict` with the `zip` of record ids and corresponding values. This significantly speeds up the storage of field values in the cache. closes odoo/odoo#30817
2019-02-11[IMP] models: read, faster missing algorithmDenis Ledoux
Instead of fetching the cache values of records that will eventually be removed, skip fetching values of a record as soon as we know a it is missing.
2019-02-11[IMP] models: read, speed up by avoiding the use of indexationDenis Ledoux
Instead of iterating on self and then putting the values in the right place in the `data` dict, iterate over data directly. This removes the need of the indexing `data[record]`, which takes a significant time when dealing with hundred of thousands of records.
2019-02-11[IMP] models: faster ensure_one implementationDenis Ledoux
Calling `len` on a long list and checking that its value is 1 is slower than just unpacking the list. The point is to check whether there is just one item in the list, and counting all items just for that is a bit overkill.
2019-02-11[IMP] models: faster browse records iterationDenis Ledoux
By avoiding to update the prefetch ids for each record when iterating on recordsets. This is faster when iterating on very large recordsets.