Skip to content

[18.0][FIX] l10n_it_vat_settlement_communication: fix for check_identificativo in multi-company#5194

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
stesi:18.0-fix-l10n-it-vat-settlement-comm-multicompany
Jun 5, 2026
Merged

[18.0][FIX] l10n_it_vat_settlement_communication: fix for check_identificativo in multi-company#5194
OCA-git-bot merged 1 commit into
OCA:18.0from
stesi:18.0-fix-l10n-it-vat-settlement-comm-multicompany

Conversation

@micheledic

Copy link
Copy Markdown
Contributor

Description

The _check_identificativo Python constraint on comunicazione.liquidazione ran self.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_identificativo has the same problem, so two companies installed in the same database will return the first item also if more than one company is selected

Steps to reproduce

  1. Install the module in a database with two companies, A and B.
  2. Log in as a user with access to both companies and the
    account.group_account_manager group.
  3. Create a comunicazione.liquidazione for company A. Note its
    identificativo (say, 1).
  4. Switch the active company to B and create a new
    comunicazione.liquidazione.
  5. The form picks the same identificativo and the Python constraint
    even though company B has none.

Fix

  • Converted the _check_identificativo constraint.to a SQL constraint UNIQUE(company_id, identificativo). The database enforces uniqueness per company and ignores ORM record rules.
  • The _get_identificativo default by company_id from context orenv.company, so the auto-assigned number counts records inside the current company.

@OCA-git-bot OCA-git-bot added series:18.0 mod:l10n_it_vat_settlement_communication Module l10n_it_vat_settlement_communication labels May 14, 2026
@micheledic micheledic force-pushed the 18.0-fix-l10n-it-vat-settlement-comm-multicompany branch from bac10b3 to 54a67f5 Compare May 14, 2026 09:35
@francesco-ooops francesco-ooops added the missing issue PRs must be linked to an issue. See the wiki. label May 14, 2026
…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.
@micheledic micheledic force-pushed the 18.0-fix-l10n-it-vat-settlement-comm-multicompany branch from 54a67f5 to 43f1b33 Compare June 5, 2026 08:37
@micheledic

Copy link
Copy Markdown
Contributor Author

@OCA/local-italy-maintainers rebased ed è green

@sergiocorato

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 18.0-ocabot-merge-pr-5194-by-sergiocorato-bump-patch, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

It looks like something changed on 18.0 in the meantime.
Let me try again (no action is required from you).
Prepared branch 18.0-ocabot-merge-pr-5194-by-sergiocorato-bump-patch, awaiting test results.

1 similar comment
@OCA-git-bot

Copy link
Copy Markdown
Contributor

It looks like something changed on 18.0 in the meantime.
Let me try again (no action is required from you).
Prepared branch 18.0-ocabot-merge-pr-5194-by-sergiocorato-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 84fe1f7 into OCA:18.0 Jun 5, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 9bf7ae5. Thanks a lot for contributing to OCA. ❤️

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[18.0]l10n_it_vat_settlement_communication: "identifier already exists" error on save

5 participants