Skip to content

[19.0][MIG] base_import_match: Migration to 19.0#467

Open
AungKoKoLin1997 wants to merge 34 commits into
OCA:19.0from
qrtl:19.0-mig-base_import_match
Open

[19.0][MIG] base_import_match: Migration to 19.0#467
AungKoKoLin1997 wants to merge 34 commits into
OCA:19.0from
qrtl:19.0-mig-base_import_match

Conversation

@AungKoKoLin1997

@AungKoKoLin1997 AungKoKoLin1997 commented Jun 26, 2026

Copy link
Copy Markdown

@qrtl QT6935

Jairo Llopis and others added 30 commits June 25, 2026 09:27
By default, when importing data (like CSV import) with the ``base_import``
module, Odoo follows this rule:

1. If you import the XMLID of a record, make an **update**.
2. If you do not, **create** a new record.

This module allows you to set additional rules to match if a given import is an
update or a new record.

This is useful when you need to sync heterogeneous databases, and the field you
use to match records in those databases with Odoo's is not the XMLID but the
name, VAT, email, etc.

After installing this module, the import logic will be changed to:

1. If you import the XMLID of a record, make an **update**.
2. If you do not:
   1. If there are import match rules for the model you are importing:
       1. Discard the rules that require fields you are not importing.
       2. Traverse the remaining rules one by one in order to find a match in
          the database.
          1. If one match is found:
             1. Stop traversing the rest of valid rules.
             2. **Update** that record.
          2. If zero or multiple matches are found:
             1. Continue with the next rule.
          3. If all rules are exhausted and no single match is found:
             1. **Create** a new record.
   2. If there are no match rules for your model:
      1. **Create** a new record.
This patch allows to import res.partner records by VAT when is_company==True by default.
* Fix wrong README format.

* [FIX][base_import_match] Avoid UnicodeEncodeError.

When the model or field you chose was translated and had some non-ascii
character, you got an error like this: `UnicodeEncodeError: 'ascii' codec can't
encode character u'\xed' in position 15: ordinal not in range(128)`.

Now, using unicode strings, that won't happen again.

* Do not require a hidden field.

* Further unicode protection, add ondelete clause.
Includes:

- Normal migration steps.
- Usage of brand new `_inherit = "base"` in Odoo 10, which implies
  removing a lot of monkey-patching code.
- Log a warning when multiple matches are found.
[UPD] README.rst

[UPD] Update base_import_match.pot
Currently translated at 100.0% (27 of 27 strings)

Translation: server-backend-12.0/server-backend-12.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-12-0/server-backend-12-0-base_import_match/pt_BR/
[UPD] Update base_import_match.pot
Currently translated at 100.0% (27 of 27 strings)

Translation: server-backend-14.0/server-backend-14.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-14-0/server-backend-14-0-base_import_match/vi_VN/
Cached methods should never return recordsets, which are tied to
specific context, env, cursor, uid. Instead, they should return IDs
which, later, can be browsed in the current context.

With this change _usable_rules() cached method is now returing ids instead
of a recordset, and also the _match_find method is properly browsing the
results ids of the cached method.
Currently translated at 51.8% (14 of 27 strings)

Translation: server-backend-16.0/server-backend-16.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_match/it/
Currently translated at 51.8% (14 of 27 strings)

Translation: server-backend-16.0/server-backend-16.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_match/it/
Currently translated at 100.0% (27 of 27 strings)

Translation: server-backend-16.0/server-backend-16.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_match/es/
Currently translated at 51.8% (14 of 27 strings)

Translation: server-backend-16.0/server-backend-16.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_match/it/
Currently translated at 100.0% (27 of 27 strings)

Translation: server-backend-16.0/server-backend-16.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-16-0/server-backend-16-0-base_import_match/it/
Includes:
- POT file update
- Post-merge bot changes
Currently translated at 85.1% (23 of 27 strings)

Translation: server-backend-18.0/server-backend-18.0-base_import_match
Translate-URL: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-base_import_match/sl/
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-base_import_match branch from c3ac1ee to 2be69d7 Compare June 29, 2026 03:28
@AungKoKoLin1997
AungKoKoLin1997 marked this pull request as ready for review June 29, 2026 03:32

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AungKoKoLin1997 Can you please move test refactoring outside the migration commit?

Rewrite the test suite to create its own records inline (via a new
_create_rule helper) instead of relying on demo data and CSV fixture
files, and drop the now-unused import_data CSV files.
Add a Match column to the import preview UI. Checking a field uses it to
find existing records (match key) without writing its value during import.
Pre-configured Import Match rules pre-check their fields automatically. If a
row matches zero or multiple records, the whole import is blocked.

Enhancement from OCA#426.
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-base_import_match branch from 2be69d7 to ca0b45e Compare June 30, 2026 06:48
@AungKoKoLin1997

Copy link
Copy Markdown
Author

Can you please move test refactoring outside the migration commit?

@yostashiro Done!

@AungKoKoLin1997
AungKoKoLin1997 marked this pull request as draft June 30, 2026 10:04
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-base_import_match branch 2 times, most recently from 7feb2f0 to ae0a721 Compare July 2, 2026 07:07
@AungKoKoLin1997
AungKoKoLin1997 marked this pull request as ready for review July 2, 2026 07:10
- load() no longer mutates the fields/data list passed in by core. Work
  on local copies so the import success screen reports names correctly
  instead of match values (e.g. emails).
- Invalidate the _usable_rules ormcache on create/write/unlink of match
  rules and their fields, so programmatic imports don't use stale rules.
- Make the Match column tooltip translatable (bind via _t).
- Add a regression test covering the name-reporting fix.
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 19.0-mig-base_import_match branch from ae0a721 to 9f48040 Compare July 2, 2026 07:11

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review. LGTM.

@smorita7749 smorita7749 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review: LGTM

I tried to import the following and the name is correctly updated.(Conditional and Imported value as well)
Image

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.