Commit Graph
66 Commits
Author SHA1 Message Date
Raphael Collet ad065093eb [FIX] models: ormcache invalidation on import
Do not propagate cache invalidations to other workers when changes must be
discarded, because of an import error or a dry run, which are both handled as
successful transactions.
2018-11-22 11:03:51 +00:00
Xavier Morel 1ef791d1de [FIX] base_import: date(time) columns matching
* actually pass the flags as flags in re.sub, passing re.IGNORECASE
  as *count* doesn't actually ignore case
* ensure the entire string is matched by the pattern, or we'll get
  shortest-matching-pattern which is *not* what the later strptime
  will do

closes odoo/odoo#27925
2018-10-18 08:05:18 +00:00
Xavier Morel 139aa9367d [IMP] base_import: performances of parse_preview by way of _try_match_date_time
* reduce number of patterns: using localised month names is useless
  since we're not setting the locale so it always uses the server's own
* avoid going through the entire strptime machinery: lift the bits of
  TimeRE we're interested in to get regex bits out of strptime patterns
  and just to an re.match to check whether value & pattern match

Further possible optimisation: cache REs and only compile user-provided
patterns dynamically.
2018-09-28 13:15:04 +02:00
Nimesh Jethva 7eea263f36 [IMP]base_*: Improvement in model description
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-21 11:45:15 +02:00
Mohammed Shekha 8fbadb9575 [ADD] base_import: debug option to create M2O/M2M records
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-08-16 11:10:35 +02:00
Xavier Morel 8c2b380768 [FIX] base_import: datetime patterns
Turns out %s is not the pattern for sub-minute seconds, that'd be
%S (note the casing). The former is the number of seconds since
epoch, which tends not to match sub-minute second patterns (sounds
like bull to me but there you are), and so importing datetimes was a
bit broken since the previous improvements.

Fix that.
2018-08-14 17:26:14 +02:00
Xavier Morel d680ae5619 [CHG] base_import: sort-of reduce o2m depth by 1 level
Before, once reaching level 0 all of an O2M's fields would still be
selected, so we would really be selecting depth+1 levels of fields,
which makes for an extremely busy list as it's a combinatorial
explosion.

Change this so at level 0 the only field selected from a field is an
xid. Not sure that's even necessary though, do xids really make sense
for o2ms?
2018-08-10 11:40:33 +02:00
Xavier Morel be96188f2f [IMP] base_import: date-parsing patterns
* expand auto-detected date and time patterns (e.g. %b, %I, ...)
* try to make date-pattern-detection clearer
* add a select2 dropdown for date patterns (with a bunch of
  preselected patterns) rather than just an input
* also try to improve other column-matching bits (e.g. less reliance
  on exceptions, attempts to avoid redundant work)
2018-08-09 10:58:52 +02:00
Xavier Morel 36ee8a78ec [IMP] base_import: attempt to automatically guess the separator
It would probably be even better to iterate the file content and get
the non-quoted non-alphanumeric characters as separator
candidates (instead of a hard-coded list) however Python does not seem
to have a decoding iterator (taking bytes and yielding an iterator of
codepoints or even grapheme clusters) — incidentally uniseg seems to
require up-front decoding as well — so that's not really convenient as
we may be dealing with large-ish files and not want to load it
entirely in memory.

An alternative would be to use TextIOWrapper and iterate the file by
buffers of a few ks, and classify that based on either codepoints or
grapheme clusters.
2018-08-07 16:46:29 +02:00
Xavier Morel 5f92f853e2 [FIX] base_import: trying to import an empty file
Various bits would lead to odd tracebacks or a complete lack of
actionable feedback.

Discover that a binary field set to b'' will return None when read back,
handle that, then handle reading an empty CSV file, then handle the
resulting iterator having no lines whatsoever when trying to match
headers.

At least for CSVs, we're now properly telling users that their file
seems to have no content when they literally upload an empty file.
2018-08-07 14:02:39 +02:00
Xavier Morel 5aba5ac99e [IMP] base_import: reintroduce encoding selector & override guess
* if an encoding is explicitly specified, use it and don't guess
* otherwise guess and return the guessed encoding so it can be
  displayed in the configuration UI
* fix less-than-stellar configuration & behaviour of select2 inputs
  to properly reflect underlying values as they get modified, to
  correctly handle future configuration guesses
2018-08-07 13:07:05 +02:00
Xavier Morel cb9c99b937 [IMP] base_import: parsing/cleanup of floats
* Handle a leading + in import data, some contexts (e.g. bank
  statements) will mark positive sums explicitly for clarity
* Add basic grouping/decimal separator inference for people importing
  data from many localisations or to avoid them *having* to configure
  their separators if we can handle it for them, currently very basic
2018-08-06 12:03:12 +02:00
Atul Patel db403e6dd7 [IMP] base_import: Import images via URL
Task 32132

Currently, importing image requires either uploading them
one-by-one (after the initial import), scripting that upload, or
converting all images to base64 and putting that in the import
file (leading to a huge unreadable file) before actually doing the
import.

This is problematic for non-technical users, especially when they're
deploying or synchronising e-commerce products.

This change matches URLs in image fields and goes to read the URL &
load that as image data. It performs the read inline which is reactive
but means the imports will be very slow (wallclock) as each URL will
have to be fetched and encoded.

Configuration: via config file only

* import_image_timeout (seconds, default 3), initial connection timeout (not
  overall file download)
* import_image_maxbytes (bytes, default 10MB): maximum image size to
  download, checked before download (Content-Length) and validated
  during (in case Content-Length is missing)
* import_image_regex (str), matches field content as "probably an
  image", by default checks that the field value starts with
  http|https and ends with an image-type extension (e.g. bmp, png, jpg)

Hard Limits:

* only works on fields actually called "icon", "image", "logo" or
  "picture"
* the image can't be more than 42MP (checked after all data is
  downloaded)

Hooks:

* _can_import_remote_urls (on res.users) checks whether the current
  user is allowed to import via URLs
* _import_image_by_url (on base_import.import) performs the actual
  download, could be overridden to store urls to import and
  batch/queue the actual imports
2018-07-18 16:56:47 +02:00
Jigar Patel b60de0db41 [IMP] import/export UIs
Task 40692

Various changes to import/export (mainly) UIs:

* default to excel & "full" (non-import-compatible) export
* auto-detect encoding of CSV using chardet
* remember column -> field mapping after having imported a file (useful
   for repeated imports where auto-matching failed)
* better handle localised booleans & column names
* automatically select source list view's fields when exporting
* better integrate import templates feature and add a number of templates
2018-07-17 15:19:05 +02:00
Christophe Simonis 74033eb007 [MERGE] forward port branch saas-11.2 up to 90f8f17fb4 2018-04-16 19:50:50 +02:00
Christophe Simonis 5f2d080cf8 [MERGE] forward port branch 11.0 up to ad825b673b 2018-04-16 18:34:56 +02:00
Nicolas Martinelli 7242544506 [FIX] base_import: activate advanced mode
The commit 1ba4fbe640 did not match the specs of the task, but
was merged anyway. Reverting the commit, and check by default so the
user is not confused with missing fields.

opw-1824074
2018-04-12 14:54:25 +02:00
Christophe Simonis 76027a6e12 [MERGE] forward port branch saas-11.2 up to 6773bdbe32 2018-03-21 19:42:34 +01:00
Christophe Simonis 6773bdbe32 [MERGE] forward port branch 11.0 up to e8f630e44d 2018-03-21 19:36:58 +01:00
Nicolas Martinelli aed8e199ce [FIX] base_import: import empty date/datetime
When a user imports a file with a datetime field set to a blank space,
the value is computed as 1900-01-01 00:00:00. However, when converted in
the user's TZ, this can lead to a value < 1900-01-01, which is not
recognized at the JS level as a valid value.

This makes the access to the record impossible, and possibly makes the
access to an app impossible. It is for example the case with Purchase,
where the order date is displayed on the default's action view (list
view).

We strip the value before testing if the value exists to avoid this
case.

opw-1826344
2018-03-21 14:43:45 +01:00
Christophe Simonis 0f57bdba72 [MERGE] forward port branch saas-11.2 up to 42659dc70c 2018-03-09 16:25:58 +01:00
Christophe Simonis 36945a5853 [MERGE] forward port branch 11.0 up to c2e878e34c 2018-03-01 19:43:25 +01:00
Nicolas LempereurandHumberto Arocha f0c801778a [FIX] base_import: allow whitespace as empty float
Empty cells containing only spaces may have unexpected results (not
shown traceback and broken import) when being imported and they were
intended for a float or monetary field.

To avoid the error we could either, ignore left/right whitespace when
parsing a float value (so same behavior as en emtpy cell) or prevent the
error and get an friendly import report error:

 ' ' does not seem to be a number for field 'Name of Field'

This change choose the first way, so a float ' ' (just whitespace) will
be considered as '' (empty).

opw-1816784
closes #23105
closes #23355

Co-authored-by: Humberto Arocha <hbto@vauxoo.com>
2018-02-28 11:17:21 +01:00
Raphael Collet 80f1ac3599 [REF] never defer parent_store computation
Simplify the implementation of parent_left/parent_right by removing this
optimization.
2018-02-28 10:33:44 +01:00
Ivan Yelizariev decc668f76 [FIX] base_import: typo 2018-01-25 12:59:19 +01:00
Christophe Simonis f02ed9ab9a [MERGE] forward port branch saas-16 up to 0af13af5de 2018-01-02 16:54:38 +01:00
Christophe Simonis 0af13af5de [MERGE] forward port branch saas-15 up to ddd293065e 2018-01-02 15:36:25 +01:00
Nicolas Martinelli 601bf82ba9 [FIX] base_import: currency removal
Typo in the currency removal method.

opw-787873
2017-12-15 10:55:03 +01:00
Raphael Collet 446be392ea [FIX] base_import, web: error messages related to data import modules
OPW 777366
2017-10-25 15:44:18 +02:00
Christophe Simonis 10128fa7e8 [MERGE] forward port branch saas-16 up to dc2a6c6cd2 2017-10-20 19:27:04 +02:00
Christophe Simonis 868e718e09 [MERGE] forward port branch saas-15 up to 8d0942380b 2017-10-17 15:14:47 +02:00
Yannick Tivisse 2651717251 [IMP] base_import: Defer parent computation after record creation/update
Currently when importing files, the parent left and right are recomputed on each record creation/update, which could lead to a lot a request.

This commit will defer the parent field recomputation to the end on the `load` function by recomputing the values from the MPTT and inserting directly the new values on the records.

Tested on a customer instance, this will reduce the execution time when importing a thousand stock.location from 15 minutes to several seconds.
2017-10-13 15:24:05 +02:00
amoyaux e1769cbea9 [FIX] base_import: parse date and float for relational fields
Use case to reproduce:
-> Import a file with a float using a coma related to the model
(for example the product.supplierinfo/price)

It happens because the method that parse the date and float field
only compare them to the main imported model.

This commit complete the method by using a recursion on relational
model in order to also parse the relational subfields.
2017-10-13 09:43:11 +02:00
Christophe Simonis bd08d4f052 [MERGE] forward port branch saas-16 up to 3ac2a1106c 2017-09-11 14:02:19 +02:00
Christophe Simonis 3ac2a1106c [MERGE] forward port branch saas-15 up to ec15765eec 2017-09-11 13:30:03 +02:00
Christophe Simonis 48f88992da [MERGE] forward port branch 10.0 up to 7d7e94c6ef 2017-09-11 11:45:44 +02:00
Goffin Simon 8fd5951fbe [FIX] base_import: Specified Date Format in Import Statment is not recognized
Steps to reproduce the bug:

1. Import a bank statement with the shown dateformad DDMMYYYY (without headers)
2. Specify this date format in the advanced options
3. Try to find the date column to assign.

Bug:

The date format is not suggested for the fields with format DDMMYYYY.

opw:769118
2017-09-06 13:45:16 +02:00
Christophe Simonis b8dd34fcbb [MERGE] forward port branch saas-16 up to 64d56995e0 2017-09-06 13:29:05 +02:00
Christophe Simonis 64d56995e0 [MERGE] forward port branch saas-15 up to ef5ac872b8 2017-09-06 12:26:36 +02:00
Christophe Simonis ec0d51f20e [MERGE] forward port branch 10.0 up to a4bcb66bfc 2017-09-06 10:59:06 +02:00
Nicolas Martinelli a4bcb66bfc [FIX] base_import: headerless import
- Import a CSV file without header
- Untick the option 'The first row contains the label of the column'

An error is reported.

If no header, the method `_match_headers` should return consistent
object types.

opw-769117
2017-09-05 16:37:48 +02:00
Christophe Simonis 30bd5ac0e9 [MERGE] forward port branch saas-16 up to aec6248bb3 2017-08-23 16:44:58 +02:00
Christophe Simonis 59f8b849fb [MERGE] forward port branch saas-15 up to d5f2a38b50 2017-08-23 11:23:08 +02:00
Olivier Dony 695716efb0 [FIX] P3: remove pycompat.{keys,items,values} helpers
Now that we're closer to switching to P3 for good, these helpers have
outlived their usefulness, and mostly add noise.

All remaining dict.iter*() or dict.view*() must be converted to the
normal keys(), values() or items() calls.

Whenever the result is likely to be used for more than the scope of a
loop, or when the dict needs to be modified during iteration, the calls
must be wrapped in a ``list()``, to protect the new P3 semantics.
Those cases are very exceptional.

Also removed some dead code or improved the API to remove unnecessary
conversions.
2017-08-20 23:25:54 +02:00
Xavier Morel e33a79c65b [FIX] P3: date parsing text model 2017-08-20 23:25:54 +02:00
Xavier Morel be7c5aefdf [FIX] P3: CSV reading & writing 2017-08-20 23:25:54 +02: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
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
Yannick Tivisse fd089ee467 [IMP] base_import: Defer parent computation after record creation/update
Currently when importing files, the parent left and right are recomputed on each record creation/update, which could lead to a lot a request.

This commit will defer the parent field recomputation to the end on the `load` function by recomputing the values from the MPTT and inserting directly the new values on the records.

Tested on a customer instance, this will reduce the execution time when importing a thousand stock.location from 15 minutes to several seconds.
2017-08-14 15:02:52 +02:00
Christophe Simonis db2f82d5f1 [MERGE] forward port branch saas-16 up to 4ca3d9cadf 2017-07-14 15:51:59 +02:00