Skip to content

Commit 3e55774

Browse files
committed
[FIX] l10n_it_edi_ndd: prevent wrong value error
The computation of `l10n_it_document_type` fails when multiple `l10n_it.document.type` records share the same code. This can happen if a user duplicates an existing Document Type or creates a new one with the same code, causing `get()` on the grouped recordset to return multiple results. This fix adds a check to ensure that the `code` field remains unique across all `l10n_it.document.type` records. Steps to Reproduce: - Install the `l10n_it_edi_ndd` module. - create a new invoice and confirm it. - from `Electronic Invoicing` page, Open Document Type and duplicate it. - Create another invoice and confirm it. observation: you will receive a traceback for wrong value error opw - 4902513 closes odoo#217155 Signed-off-by: Wala Gauthier (gawa) <[email protected]>
1 parent 7df78a2 commit 3e55774

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

addons/l10n_it_edi_ndd/i18n/it.po

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ msgstr "Nome visualizzato"
7575
msgid "Document Type"
7676
msgstr "Tipi di documento"
7777

78+
#. module: l10n_it_edi_ndd
79+
#. odoo-python
80+
#: code:addons/l10n_it_edi_ndd/models/l10n_it_document_type.py:0
81+
#, python-format
82+
msgid "Document Type code must be unique."
83+
msgstr "Il codice del tipo di documento deve essere univoco."
84+
7885
#. module: l10n_it_edi_ndd
7986
#: model:ir.model.fields,field_description:l10n_it_edi_ndd.field_l10n_it_document_type__id
8087
msgid "ID"

addons/l10n_it_edi_ndd/i18n/l10n_it_edi_ndd.pot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ msgstr ""
7575
msgid "Document Type"
7676
msgstr ""
7777

78+
#. module: l10n_it_edi_ndd
79+
#. odoo-python
80+
#: code:addons/l10n_it_edi_ndd/models/l10n_it_document_type.py:0
81+
#, python-format
82+
msgid "Document Type code must be unique."
83+
msgstr ""
84+
7885
#. module: l10n_it_edi_ndd
7986
#: model:ir.model.fields,field_description:l10n_it_edi_ndd.field_l10n_it_document_type__id
8087
msgid "ID"

addons/l10n_it_edi_ndd/models/l10n_it_document_type.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from odoo import fields, models
1+
from odoo import _, api, fields, models
2+
from odoo.exceptions import ValidationError
23

34

45
class L10nItDocumentType(models.Model):
@@ -18,3 +19,15 @@ class L10nItDocumentType(models.Model):
1819
def _compute_display_name(self):
1920
for document_type in self:
2021
document_type.display_name = f"{document_type.code} - {document_type.name}"
22+
23+
@api.constrains('code')
24+
def _check_code_unique(self):
25+
duplicate = self._read_group(
26+
domain=[],
27+
groupby=['code'],
28+
aggregates=['id:recordset'],
29+
having=[('__count', '>', 1)],
30+
limit=1,
31+
)
32+
if duplicate:
33+
raise ValidationError(_('Document Type code must be unique.'))

0 commit comments

Comments
 (0)