Skip to content

Commit bac10b3

Browse files
committed
[FIX] l10n_it_vat_settlement_communication: prevent identificativo collisions
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.
1 parent 6e86e96 commit bac10b3

4 files changed

Lines changed: 34 additions & 45 deletions

File tree

l10n_it_vat_settlement_communication/README.rst

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
====================================
62
ITA - Comunicazione liquidazione IVA
73
====================================
@@ -17,7 +13,7 @@ ITA - Comunicazione liquidazione IVA
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
@@ -61,9 +57,9 @@ escludere il valore dell'imposta.
6157
Usage
6258
=====
6359

64-
- Creare una nuova comunicazione.
65-
- Nel "Quadro VP" aggiungere una voce selezionando in alto la
66-
liquidazione, precedentemente creata, da inserire.
60+
- Creare una nuova comunicazione.
61+
- Nel "Quadro VP" aggiungere una voce selezionando in alto la
62+
liquidazione, precedentemente creata, da inserire.
6763

6864
Bug Tracker
6965
===========
@@ -86,10 +82,10 @@ Authors
8682
Contributors
8783
------------
8884

89-
- Alessandro Camilli
90-
- Lorenzo Battistini
91-
- Lara Baggio
92-
- `Nextev Srl <https://nextev.it>`__ odoo@nextev.it
85+
- Alessandro Camilli
86+
- Lorenzo Battistini
87+
- Lara Baggio
88+
- `Nextev Srl <https://nextev.it>`__ odoo@nextev.it
9389

9490
Maintainers
9591
-----------

l10n_it_vat_settlement_communication/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "ITA - Comunicazione liquidazione IVA",
66
"summary": "Comunicazione liquidazione IVA ed esportazione file xml"
77
"conforme alle specifiche dell'Agenzia delle Entrate",
8-
"version": "18.0.1.0.1",
8+
"version": "18.0.1.0.2",
99
"category": "Account",
1010
"author": "Openforce di Camilli Alessandro, Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/l10n-italy",

l10n_it_vat_settlement_communication/models/comunicazione_liquidazione.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ def _default_company(self):
2323
company_id = self._context.get("company_id", self.env.company.id)
2424
return company_id
2525

26-
@api.constrains("identificativo")
27-
def _check_identificativo(self):
28-
domain = [("identificativo", "=", self.identificativo)]
29-
dichiarazioni = self.search(domain)
30-
if len(dichiarazioni) > 1:
31-
raise ValidationError(
32-
self.env._("Communication with identifier {} already exists").format(
33-
self.identificativo
34-
)
35-
)
26+
_sql_constraints = [
27+
(
28+
"unique_identificativo_per_company",
29+
"UNIQUE(company_id, identificativo)",
30+
"Communication with this identifier already exists for the company.",
31+
),
32+
]
3633

3734
def _compute_name(self):
3835
for dich in self:
@@ -52,11 +49,13 @@ def _compute_name(self):
5249
dich.name = name
5350

5451
def _get_identificativo(self):
55-
dichiarazioni = self.search([])
56-
if dichiarazioni:
57-
return len(dichiarazioni) + 1
58-
else:
59-
return 1
52+
company_id = self._context.get("company_id", self.env.company.id)
53+
last = self.search(
54+
[("company_id", "=", company_id)],
55+
order="identificativo desc",
56+
limit=1,
57+
)
58+
return (last.identificativo or 0) + 1
6059

6160
company_id = fields.Many2one(
6261
"res.company", string="Company", required=True, default=_default_company

l10n_it_vat_settlement_communication/static/description/index.html

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>ITA - Comunicazione liquidazione IVA</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="ita-comunicazione-liquidazione-iva">
364+
<h1 class="title">ITA - Comunicazione liquidazione IVA</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="ita-comunicazione-liquidazione-iva">
370-
<h1>ITA - Comunicazione liquidazione IVA</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:7726bc879478d9950cf5864854b51db64c583ce368ca9b079e992e5e5e330fe9
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_vat_settlement_communication"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-18-0/l10n-italy-18-0-l10n_it_vat_settlement_communication"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-italy/tree/18.0/l10n_it_vat_settlement_communication"><img alt="OCA/l10n-italy" src="https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-italy-18-0/l10n-italy-18-0-l10n_it_vat_settlement_communication"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-italy&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>Comunicazione liquidazione IVA ed export file XML, conforme alle
379374
specifiche dell’’Agenzia delle Entrate.</p>
380375
<p>I dati possono essere caricati da liquidazioni IVA effettuate in odoo
@@ -394,7 +389,7 @@ <h1>ITA - Comunicazione liquidazione IVA</h1>
394389
</ul>
395390
</div>
396391
<div class="section" id="configuration">
397-
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
392+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
398393
<p>Nella scheda dell’imposta è possibile configurare “Escludere dalle
399394
operazioni attive / passive” e/o “Escludere dall’IVA esigibile /
400395
detratta”.</p>
@@ -406,31 +401,31 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
406401
escludere il valore dell’imposta.</p>
407402
</div>
408403
<div class="section" id="usage">
409-
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
404+
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
410405
<ul class="simple">
411406
<li>Creare una nuova comunicazione.</li>
412407
<li>Nel “Quadro VP” aggiungere una voce selezionando in alto la
413408
liquidazione, precedentemente creata, da inserire.</li>
414409
</ul>
415410
</div>
416411
<div class="section" id="bug-tracker">
417-
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
412+
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
418413
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/l10n-italy/issues">GitHub Issues</a>.
419414
In case of trouble, please check there if your issue has already been reported.
420415
If you spotted it first, help us to smash it by providing a detailed and welcomed
421416
<a class="reference external" href="https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_vat_settlement_communication%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
422417
<p>Do not contact contributors directly about support or help with technical issues.</p>
423418
</div>
424419
<div class="section" id="credits">
425-
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
420+
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
426421
<div class="section" id="authors">
427-
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
422+
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
428423
<ul class="simple">
429424
<li>Openforce di Camilli Alessandro</li>
430425
</ul>
431426
</div>
432427
<div class="section" id="contributors">
433-
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
428+
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
434429
<ul class="simple">
435430
<li>Alessandro Camilli</li>
436431
<li>Lorenzo Battistini</li>
@@ -439,7 +434,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
439434
</ul>
440435
</div>
441436
<div class="section" id="maintainers">
442-
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
437+
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
443438
<p>This module is maintained by the OCA.</p>
444439
<a class="reference external image-reference" href="https://odoo-community.org">
445440
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -452,6 +447,5 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
452447
</div>
453448
</div>
454449
</div>
455-
</div>
456450
</body>
457451
</html>

0 commit comments

Comments
 (0)