Skip to content

Commit

Permalink
[IMP] l10n_it_vat_settlement_date: Prevent edit after posting
Browse files Browse the repository at this point in the history
Make the field `l10n_it_vat_settlement_date` follow the same readonly logic as `invoice_date`: it can be edited only when the invoice is in draft.
  • Loading branch information
SirAionTech committed Dec 18, 2024
1 parent 3c1a3e0 commit 8af45aa
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions l10n_it_vat_settlement_date/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class AccountMove(models.Model):
compute="_compute_l10n_it_vat_settlement_date",
store=True,
readonly=False,
states={
"posted": [
("readonly", True),
],
},
)

@api.depends(
Expand Down
1 change: 1 addition & 0 deletions l10n_it_vat_settlement_date/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_account_move
from . import test_vat_period_end_statement
from . import test_vat_registry
60 changes: 60 additions & 0 deletions l10n_it_vat_settlement_date/tests/test_account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import datetime

from dateutil.relativedelta import relativedelta

from odoo.tests import Form, tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestAccountMove(AccountTestInvoicingCommon):
def test_draft_not_readonly(self):
"""VAT settlement date is not readonly when invoice is in draft."""
# Arrange
bill = self.init_invoice(
"in_invoice",
invoice_date=datetime.date(2020, 1, 1),
amounts=[
100,
],
)
settlement_date = bill.invoice_date + relativedelta(days=1)
# pre-condition
self.assertEqual(bill.state, "draft")

# Act
with Form(bill) as bill_form:
bill_form.l10n_it_vat_settlement_date = settlement_date

# Assert
self.assertEqual(bill.l10n_it_vat_settlement_date, settlement_date)

def test_posted_readonly(self):
"""VAT settlement date is readonly when invoice is posted."""
# Arrange
bill = self.init_invoice(
"in_invoice",
invoice_date=datetime.date(2020, 1, 1),
amounts=[
100,
],
post=True,
)
settlement_date = bill.invoice_date + relativedelta(days=1)
# pre-condition
self.assertEqual(bill.state, "posted")

# Act
with self.assertRaises(AssertionError) as ae:
with Form(bill) as bill_form:
bill_form.l10n_it_vat_settlement_date = settlement_date

# Assert
exc_message = ae.exception.args[0]
self.assertIn("readonly field", exc_message)
self.assertIn("l10n_it_vat_settlement_date", exc_message)
self.assertNotEqual(bill.l10n_it_vat_settlement_date, settlement_date)

0 comments on commit 8af45aa

Please sign in to comment.