summaryrefslogtreecommitdiff
path: root/odoo/addons/base/models/ir_fields.py
AgeCommit message (Collapse)Author
2020-12-14[FIX] core: imports with one2many lines with dangling external idsRaphael Collet
Consider a model M with a one2many field with comodel L, such that deleting records in M cascade-deletes records in L. Import a bunch of records in M with one2many lines having specific external ids. Delete the imported records: the database cascade-deletes the corresponding lines, but the lines' external ids are not deleted. Now re-import the same records: this crashes, because the import process finds the lines' external ids and tries to update the deleted lines! The fix consists in checking that an external id's record actually exists. The existence check was removed for performance reasons by https://github.com/odoo/odoo/pull/26496. We reintroduce it by resolving the external id with a join on the model's name, which checks the record's existence faster than an extra query. This patch allows to re-create the imported records' lines. Another patch is necessary to actually update the external ids that refer to deleted records, otherwise they remain dangling, and importing the same records again duplicates the lines, because their external ids do not match any existing record. OPW 2409649 closes odoo/odoo#63077 Related: odoo/enterprise#15202 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-07-31[FIX] base: fix create option of import for Many2one in One2manyAnh Thao Pham (pta)
- Install Inventory - Create an excel file with the following values : -------------------------------------------------------------------------------------------------------------------------------------------------------- location_id | location_dest_id | Operation Type / database ID | Stock moves / product | Stock moves / unit of measure | Stock moves / name -------------------------------------------------------------------------------------------------------------------------------------------------------- Partner Locations/Vendors | WH/Stock | 1 | Non existent product | Units | Test -------------------------------------------------------------------------------------------------------------------------------------------------------- - Go to Inventory > Operations > Transfers and import the file - Check the "Create if doesn't exist" option for "Stock moves / Product" and click on "TEST" button Import fails because Product does not exist and is not created. "name_create_enabled_fields" is used in frontend to store which fields have to be created if they don't exist. The issue comes from the fact that the keys used in "name_create_enabled_fields" contain the full path to the related field (i.e. move_lines/product_id), but only the final field name is used when checking "name_create_enabled_fields" in the backend (i.e. product_id). The prefix from the keys in "name_create_enabled_fields" should be removed when parsing fields from One2many. opw-2282087 X-original-commit: fadce5c117e3a14ec659cf0accee85502214120d
2020-06-18[IMP] *: replace to new _() syntaxMartin Trigaux
Using a few regex like \((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\) ($1, $3)) Old syntax is still compatible but starts the migration to the new syntax that catches error.
2020-05-28[IMP] core: batching during importXavier Morel
By default importing is batched (or at least attempted to), however because the import is functionally sequential it's possible for a record to refer to a previously imported record of the same batch. When records are referenced by xid this is easy, we can just keep track of all the xids we *should* have created so far and when trying to look up a xid if it's one of those flush all pending creations (otherwise assume it's some other unrelated xid which already exists in the system). For "name_search" lookups however this is more complicated, so we'd just flush the entire thing. This, then, is an issue when importing records with an m2o which is *generally* looked up by "name" rather than xid e.g. when importing partners it's more likely the "state" will be specified by name (e.g. AZ or Arizona) than xid (base.state_us_3 lol), because it means more or less every line will be flushed, defeating all batching and slowing down the import. To fix this, allow passing *model names* to flush (not just xids), and try to collate all the models we could be creating (or updating) records for in the process of importing. If we see a name_search on one of these models flush, otherwise don't because we couldn't have impacted the search. Task 1951307 While at it, f2a16187582ed697ffeea1522e4f0c745bf77016 removed all usage of model_load_save, but left the creation of the savepoint itself. The InternalError check should be left in place to catch things like conversion issues which put the tnx in an invalid state (only invalid states should trigger an InternalError according to psycopg's errors documentation). closes odoo/odoo#49289 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-03-23[IMP] base: display full name of the field in import warningJinal Patel
Before this change, if an error occurs while trying to match / import a sub-field e.g. order_line/product_id, only the name of the top-level field is showing when displaying the error e.g. "Order Line", which lacks precision and makes understanding and fixing the issue more complicated. After this change, the entire field path should be displayed, e.g. "Order Line / Product" in the example above. Task-1906700 closes odoo/odoo#33031 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com> Co-authored-by: Mohammed Shekha <msh@odoo.com>
2019-11-04[ADD] base: allow importing new O2M values with an xidWolfgang Taferner
When importing an O2M value (sub-record), rather than raising an error if the value has a xid set (foo_ids/id) and the xid does not exist in the database, re-insert the xid as the "id" field of the sub-record, then re-extract it at creation (the ORM will have ignored it) and associate it with the newly created record. Advantages: * keeps o2m creation in the proper order during import (sub-records remain created after the parent) meaning o2ms with a required parent can take advantage of the feature * avoids breaking batching when creating the objects * no new command or smuggling through an existing command closes odoo/odoo#35995 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-10-30[FIX] ir_fields: import many2one_reference fieldsNans Lefebvre
Since a many2one_reference is simply an int, we can defer _str_to_many2one_reference to _str_to_integer. Note that to really validate the integer, we need the model_field of the field, which should be stored in the record's values. To get this information, _extract_records would have to be modified. For the reported use-case, it does not matter as the create of the message record checks for the existence of the related record, so the validation works as expected. Better support for this type of fields would be to allow for import/export of xml_ids, which would avoid the need for the model. opw 2087353 closes odoo/odoo#39601 X-original-commit: 77f616e9359272b2598d414672cffbc06cee2a33 Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
2019-10-10[FIX] odoo: Import data with falsy many2one fieldsGoffin Simon
Steps to reproduce: - Export a partner with country set to False, using EXCELL - Try to import it with the xls file Bug: It raised: "No matching record found for name 'False' in field 'Country' at row 2" opw:2080376 closes odoo/odoo#38379 X-original-commit: 01caf1e44f653a8e9bf5edd583bc2421905d9464 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
2019-08-20[IMP] base_import: Improve import general UX (back2basics)Yannick Tivisse
Purpose ======= Improve error management UX on import. TaskID: 2049992 closes odoo/odoo#35804 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-06-17[IMP] *: remove 'view_type' on window actions.Hiral Bhavsar
The old tree views don't really exist anymore, this odd pseudo-flag to dispatch between "list" and "tree" tree views has no reason to remain. Task 1937686 closes odoo/odoo#31243 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2018-11-29[REF] *: replace deprecated pycompat helpers for builtinsAdrian Torres
This commit replaces calls to pycompat helpers that were intended for python 2 <-> python 3 interoperability for python 3 builtins, as python 2 is no longer officially supported by Odoo. This includes: * calls to imap/izip/ifilter replaced by map/zip/filter * uses of text_type replaced by str * uses of unichr replaced by chr * calls to implements_to_string, implements_iterator removed * string_types and integer_types replaced by str, int respectively * calls to to_native replaced by calls to to_text This is done in preparation to the removal of these deprecated helpers in the following commit.
2018-09-21[IMP]base_*: Improvement in model descriptionNimesh Jethva
Purpose of this commit is to give description more "business oriented" because those descriptions appears in Odoo Studio which is supposed to be used by end users, not only by developers. Related Task ID : 37311
2018-09-11[IMP] base: avoid ref() in conversion of M2O/M2MXavier Morel
A proper ref() call implies an exists(), which isn't that expensive but piles up over a few thousand calls. The partner import test case trigger 7394 calls to exists, for a total of ~6% runtime (and under 2% for the actual xid lookup).
2018-08-16[ADD] base_import: debug option to create M2O/M2M recordsMohammed Shekha
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-07-24[REF] models: import records in batchRaphael Collet
Create new methods on `BaseModel` to create records with given xml ids in batch. Those methods replace the methods `_update` and `_update_dummy` of model 'ir.model.data', which are now deprecated. Adapt XML and CSV import code to create records in batch.
2017-11-27[MOV] base: move ir_* models into models/Thibault Delavallée