Skip to content

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

@micheledic

Description

@micheledic

Module

l10n_it_vat_settlement_communication

Describe the bug

Saving a comunicazione.liquidazione raises
ValidationError: Communication with identifier N already exists
even when no record with that identifier is visible to the user. The
error fires on single-company databases and with a single company
selected in the top-right switcher.

Two defects combine.

1. _get_identificativo default

The default returns count(records) + 1. Row counting does not produce
unique values. A deleted row, a gap, or an out-of-order import lets
the default land on an identifier that already exists.

2. _check_identificativo constraint scope

The Python constraint searches without a company_id filter

To Reproduce

Affected versions: 18.0 (module 18.0.1.0.1)

Steps to reproduce the behavior:

  1. Create three comunicazione.liquidazione records on one company.
    The default assigns identifiers 1, 2, 3.
  2. Delete the record with identifier 2.
  3. Create a new record. The default returns 2 + 1 = 3, the save
    fails with
    ValidationError: Communication with identifier 3 already exists.

Expected behavior

The default returns a value that does not collide with an existing
record. The uniqueness check matches records on the same company only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions