[18.0][FIX] l10n_it_vat_settlement_communication: fix for check_identificativo in multi-company#5194
Merged
OCA-git-bot merged 1 commit intoJun 5, 2026
Conversation
2 tasks
bac10b3 to
54a67f5
Compare
…llisions The _get_identificativo default returned `count(records) + 1`. Counting is not a unique generator: deleted rows, gaps, or out-of-order creation let the default return a value that already exists. Two records on the same company then share the same `identificativo`, and `_check_identificativo` raises `ValidationError` on the next save even with a single company selected in the top-right switcher. The Python `_check_identificativo` constraint also ran `self.search()` without filtering by `company_id`. Record rules normally scope the result to `self.env.companies`, but that context can expand beyond the switcher selection (cron jobs, RPC entry points, callers that use `sudo()` or `with_company()`), and cross-company duplicates surface as spurious validation errors. Replace the Python constraint with a SQL `UNIQUE(company_id, identificativo)`. The database enforces the rule per company and ignores ORM record rules. Compute the default by reading the current maximum identificativo for the active company instead of counting rows, so the next value never collides with an existing record.
54a67f5 to
43f1b33
Compare
Contributor
Author
|
@OCA/local-italy-maintainers rebased ed è green |
tafaRU
approved these changes
Jun 5, 2026
Contributor
|
/ocabot merge patch |
Contributor
|
This PR looks fantastic, let's merge it! |
Contributor
|
It looks like something changed on |
1 similar comment
Contributor
|
It looks like something changed on |
Contributor
|
Congratulations, your PR was merged at 9bf7ae5. Thanks a lot for contributing to OCA. ❤️ |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
_check_identificativoPython constraint oncomunicazione.liquidazioneranself.search([("identificativo", "=", self.identificativo)])without a company filter. Creating a record on company A raises the duplicate error when company B already owns the same identifier because in the constrains defaults to allowed_company_ids instead of the current selected company.The
_get_identificativohas the same problem, so two companies installed in the same database will return the first item also if more than one company is selectedSteps to reproduce
account.group_account_managergroup.comunicazione.liquidazionefor company A. Note itsidentificativo(say, 1).comunicazione.liquidazione.identificativoand the Python constrainteven though company B has none.
Fix
_check_identificativoconstraint.to a SQL constraintUNIQUE(company_id, identificativo). The database enforces uniqueness per company and ignores ORM record rules._get_identificativodefault bycompany_idfrom context orenv.company, so the auto-assigned number counts records inside the current company.