Commit Graph
25 Commits
Author SHA1 Message Date
Julien Castiaux ca903577d2 [REF] test_*: Use Command helper for x2many
Task: 2366606
2020-11-30 10:16:09 +00:00
574d7f0d4c [IMP] core: import-compatible export of m2m fields
When performing an import-compatible export, m2m values would be
exported as a record per cell unless the `id` subfield was the first
to be exported. Which is not the case when using the export UI (as it
always adds the field itself before any subfield). This would make the
m2m not actually export-compatible in most cases.

* export m2m "display name" in an import compatible format as well
* re-prioritise exporting xids when there are multiple m2m exports in
  import-compatible mode
* never fall back on the o2m / non-import-compatible m2m path for m2ms
  in import-compatible mode

Note: if multiple m2m fields are specified only one of them gets filled.

Task 2065428

closes odoo/odoo#37407

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Co-authored-by: Ravi Singh <ras@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
Co-authored-by: Xavier Morel <xmo@odoo.com>
2020-02-21 12:12:19 +00:00
Martin Trigaux 49fbab5329 [IMP] base: split and deprecate load_lang
load_lang was a kind of hybrid method trying to active or creating a
language if not found. This was error prone.
Instead rely on two methods with clear purpose:
ResLang._create_lang(lang, lang_name=None)
  - create a new res.lang entry using the locale of the server
    return the res.lang record to match the API of _activate_lang

ResLang._active_lang(code)
  - activate the given code lang

Most of the time, _active_lang is what is expected

tools.trans_load_data and IrTranslation._load_module_terms no longer
activate the language if not active.
Loading the translations should be explicit on an activated language,
it is too error prone to silently activate/create a language if not
found.
Remove lang_name from trans_load_data as no longer needed.
2019-11-19 10:37:01 +01:00
Martin TrigauxandRaphaël Collet 7593b887df [REF] fields: use ir.model.fields.selection
The selection values of a selection field are now stored in database in the
model ir.model.fields.selection

This will allow to have a modular approche on selections and each selection
is now linked to the module that declared it.
Previously to this change, the selections were linked to the field, meaning
uninstalling a module had no impact on the selections stored on database.

With this change, the selections will now be translated in the correct module
(having an external id) and the records having a used selection will now be
reset to null.

closes odoo/odoo#30228

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>


Co-authored-by: Raphaël Collet <rco@odoo.com>
2019-08-19 11:44:34 +00:00
Martin Trigaux 66dea8bb7b [REF] web: remove raw_mode flag on export
The export is now always in raw_mode
Adapt the tests

Fixes odoo/odoo#18798

closes odoo/odoo#26724

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2019-08-02 08:53:24 +00:00
Xavier Morel a0e05e2ab9 [IMP] fields: selection fields only use strings
closes odoo/odoo#29039
2019-01-26 14:25:44 +00:00
Christophe Simonis 8aa8548d8a [MERGE] forward port branch 12.0 up to 3e4138deaa
closes odoo/odoo#30045
2019-01-09 15:56:53 +00:00
Nicolas Martinelli c819fc69ee [FIX] fields, test_impex: export Datetime
- Set a TZ on the user different from UTC
- Export a record containing a datetime, e.g. the Order Date of a SO
- Import the file

The Order Date is changed on the record.

The data export is always in UTC, but the data import takes into account
the user TZ, which explains the difference.

There is no good way of solving this in stable. We have 3 choices:
1. Do nothing: the flow export then import the same data is broken, as
   explained above.
2. Export in the user TZ: if the file is imported in a third-party
   software, we break the flow.
3. Import in UTC: if the file is generated from a third-party software,
   we break the flow.

Whatever the choice is, we either break a flow or keep an inconsistent
behavior. We choose option 2, assuming that in most cases the user wants
to export the data in his TZ, therefore keeping the values displayed. We
only do it in v12 in order to mitigate the impact on existing
installations. A proper fix should be discussed for v13.

opw-1915631

closes odoo/odoo#29576
2018-12-18 07:13:34 +00:00
Nicolas Martinelli dc9e87baa6 [FIX] test_impex: use context provided
The `export` method accepts a `context` parameter, but doesn't use it.
This actually hides an incorrect test: when exporting in French, `Bar`
should be exported as `titi`.
2018-12-17 13:37:32 +00:00
Adrian Torres 52f5528cfb [REF] *: replace deprecated pycompat helpers for builtins
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-11-29 09:28:17 +00:00
xmo-odoo 4ac7820afb [IMP] export: move XIDs management to end of export & batch further
* export benches for m2o
* tag benches instead of requiring editing the source to enable them
* dump the profiling stats intead of saving to disk (less convenient
  for complex analysis but way more so for simple overview)
* add M2O benching in addition to the existing integer-based one in
  order to expose problematic behaviour when exporting significant
  numbers of non-shared relational records (& quantify impact of
  creation v read)

Following odoo/odoo#22493 the performances of exporting XIDs was
greatly improved by batching XIDs and avoiding the ~3 SQL queries per
xid/record when no xid exists yet.

*However* the batching was done per call of _export_rows and to handle
relational fields _export_rows calls itself recursively leading to
sub-standard xid batching:

* for M2M and O2M fields, some batching would happen on a
  parent-record basis, each M2M or O2M field (in a parent) would be
  xid-batched, but two parent records wouldn't see their children
  xid-batched together
* for M2O, there would be essentially no batching with a call to
  __ensure_xml_id per record and while less queries than before in the
  worst case more complex ones in fact

Change: rather than ensure XIDs exist when performing the export, add
XIDs export as a post-processing of the exported records table. This
way, each involved model can be entirely batched and exporting 10000
records's (id, value_id/id) 2 calls instead of 10001.

Also rename _export_rows's recursion parameter for clarity, it has
clearly outgrown its use as a batch invalidation flag and the name
is now less than clear.

Furthermore _-prefix & mandate kwarg usage to make it clearer it's not
really a "public" parameter, and is intended as an internal recursion
flag.
2018-05-24 14:50:13 +02:00
Xavier Morel b41c4396dd [FIX] handling of empty/absent modules in xids
Restore behaviour of not adding the separating dot if the module field
of an ir.model.data record is empty. This is useful/important for
interop with external systems.
2018-04-20 11:03:33 +02:00
xmo-odoo b5c660d8c0 [IMP] base: batch XID generation during export
* add UUIDs to XID sections (4 bytes / 8 hex digits) so it's not
  necessary to handle collisions & add a fallback generator
* use COPY for performances over executemany: executemany just
  performs an implicit loop on all statements (in psycopg2)
* ~pure SQL was possible:

      INSERT INTO ir_model_data (module, model, name, res_id)
      SELECT
          '__export__',
          '{model}',
          '{table}_' || A.id || '_' || uuid_generate_v4(),
          A.id
      FROM {table} A
      LEFT JOIN ir_model_data B
             ON A.id = B.res_id AND B.model = %s
      WHERE B.res_id IS NULL;

  but would have required installing pg extensions (problematic
  especially in stable) and performances are about the same as
  the COPY version

task 36343
Fixes #22493
2018-04-05 10:34:48 +02:00
Christophe Simonis bd16df15ea [MERGE] forward port branch saas-16 up to 98d01e46e5 2018-02-20 11:53:06 +01:00
Xavier Morel a583a56324 [FIX] base, web: don't fold M2M when not in import compatible mode
Before this commit, if the first exported field of an M2M is `id` (the
xid) the entire M2M is folded into a single cell with comma-separated
xids and any following field is ignored. If `id` is any but the first
field, the export behaves normally (with the m2m exported as a "table"
inside the parent record).

This behaviour makes sense for import-compatible exports where the id
is the only thing which can be exported anyway, but it is troublesome
outside of that mode as the behaviour of m2m under export becomes
incoherent/unpredictable (ish) as it depends on the position of the
m2m's `id` in the exports list.

Change it so we only perform folding in import-compatible mode (which
is the default for backwards compatibility with e.g. API calling
export_data directly & the like).

opw-813361

Fixes #22600
2018-02-19 10:43:15 +01:00
Christophe Simonis 42264d8dcb [MERGE] forward port branch saas-16 up to 5d7ad2b16c 2017-11-30 18:43:08 +01:00
Raphael Collet 0d5ac92ff0 [FIX] models: nonsensical special case in CSV export
Remove weird special case: when the first field of the first line of a one2many
is empty, replace this first field by the comma-separated names of the lines,
and discard the other lines.
2017-11-23 11:35:39 +01:00
Christophe Simonis a094f6318b [MERGE] forward port branch saas-16 up to 745d00362a 2017-11-16 12:40:36 +01:00
Nicolas Martinelli e77fa0051c [FIX] models: blank export
Exporting One2many files gives blank export.

This reverts commit 2c61c54ffa.

opw-781399
opw-781457
2017-11-10 10:35:43 +01:00
Christophe Simonis 8f1e2044cd [MERGE] forward port branch saas-16 up to 810b6aa760 2017-10-31 16:29:07 +01:00
Raphael Collet 2c61c54ffa [FIX] models: nonsensical special case in CSV export (#20499)
Remove weird special case: when the first field of the first line of a one2many
is empty, replace this first field by the comma-separated names of the lines,
and discard the other lines.
2017-10-30 17:12:45 +01:00
Xavier Morel 7dd062f835 [FIX] P3: text model types
* remove references to basestring & unicode (use relevant pycompat
  helpers)
* remove some str calls (either entirely or replaced by relevant
  helper, either text or native)
* use better API to avoid unnecessary conversions
* remove some XML declarations in views
2017-08-20 23:25:54 +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
Sébastien BEAU f72c7c3adf [REF] models: rename __export_rows to _export_rows to make it inheritable
Closes #10270.
2016-10-14 15:00:37 +02:00
Raphael Collet 9e64f9f951 [REF] openerp: move openerp to odoo 2016-09-02 17:28:12 +02:00