Skip to content

[14.0][IMP] connector_sage: detect employee code reassignment on import - #950

Open
deeniiz wants to merge 1 commit into
14.0from
14.0-imp-connector_sage-detect_employee_code_reassignment
Open

[14.0][IMP] connector_sage: detect employee code reassignment on import#950
deeniiz wants to merge 1 commit into
14.0from
14.0-imp-connector_sage-detect_employee_code_reassignment

Conversation

@deeniiz

@deeniiz deeniiz commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Sage reuses employee codes: a code can be given to a different person. The importer resolves the binding by (CodigoEmpresa, CodigoEmpleado) alone, so a reassigned code relabeled the existing employee while the partner kept the old person (partner fields are @only_create), silently mixing two people and misattributing payroll payments.

Add a _validate_update() hook to the generic importer, called on an existing binding right before the write. The partner importer overrides it to compare the incoming identity (SiglaNacion+Dni) against the partner VAT, frozen at first import by the @only_create euvat mapping: on mismatch the import raises ValidationError and the queue job fails visibly, with both unlock procedures in the message (same person with a new document → fix the partner VAT and retry; real reassignment → delete the Sage bindings and retry). The employee import brings the partner as a dependency, so the single guard covers both flows. Partners without VAT (employees_exclude_nif_pattern) are skipped.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.10%. Comparing base (56d37f5) to head (fccc866).

Additional details and impacted files
@@            Coverage Diff             @@
##             14.0     #950      +/-   ##
==========================================
+ Coverage   51.50%   52.10%   +0.59%     
==========================================
  Files        1182     1184       +2     
  Lines       20438    20504      +66     
  Branches     4299     4302       +3     
==========================================
+ Hits        10526    10683     +157     
+ Misses       9657     9542     -115     
- Partials      255      279      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sage reuses employee codes: a code can be given to a different person.
The importer resolves the binding by (CodigoEmpresa, CodigoEmpleado)
alone, so after a reassignment the sync relabeled the employee while
the partner kept the old person, misattributing payroll payments.

Add a _validate_update() hook to the generic importer, called on an
existing binding after the mapping and right before the write. The
partner importer overrides it to compare the incoming Sage identity
(SiglaNacion+Dni) against the partner VAT, which holds the identity
the code belonged to at first import (the euvat mapping is
@only_create, so no later sync rewrites it). On mismatch the import
stops with ValidationError and the queue job fails without retries;
the error message documents both unlock procedures (same person with
a new identity document -> fix the partner VAT and retry the job;
real reassignment -> delete the Sage bindings of the code and retry).

The employee import always imports the partner dependency first, so a
reassigned code stops before the employee is touched. Partners
without VAT (e.g. excluded by employees_exclude_nif_pattern) cannot
be checked and are skipped.

The identity normalization is a single mapper method, sage_identity(),
shared by the euvat mapping and the guard.
@deeniiz
deeniiz force-pushed the 14.0-imp-connector_sage-detect_employee_code_reassignment branch from 7066dee to fccc866 Compare July 17, 2026 10:16
@deeniiz
deeniiz requested a review from eantones July 17, 2026 12:09
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.

1 participant