From 0650f1d2e1e84da3e78b3f9eb5f84d8a2afe612d Mon Sep 17 00:00:00 2001 From: Sergio Zanchetta Date: Wed, 15 Jan 2025 11:29:49 +0100 Subject: [PATCH] [FIX] l10n_it_account_stamp: stamp invoice line deleted on reset to draft --- l10n_it_account_stamp/models/account_move.py | 10 +++--- .../tests/test_account_stamp_invoicing.py | 35 +++++++++---------- .../views/account_move_view.xml | 10 ++++-- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/l10n_it_account_stamp/models/account_move.py b/l10n_it_account_stamp/models/account_move.py index 4e1a9baab51d..27243383fb24 100644 --- a/l10n_it_account_stamp/models/account_move.py +++ b/l10n_it_account_stamp/models/account_move.py @@ -15,9 +15,9 @@ class AccountMove(models.Model): compute="_compute_l10n_it_account_stamp_is_stamp_duty_applied", store=True, ) - l10n_it_account_stamp_is_stamp_duty_present = fields.Boolean( + l10n_it_account_stamp_is_stamp_duty_invoice_line_present = fields.Boolean( string="Stamp line is present in invoice", - compute="_compute_l10n_it_account_stamp_is_stamp_duty_present", + compute="_compute_l10n_it_account_stamp_is_stamp_duty_invoice_line_present", ) l10n_it_account_stamp_auto_compute_stamp_duty = fields.Boolean( related="company_id.l10n_it_account_stamp_stamp_duty_product_id.l10n_it_account_stamp_auto_compute", @@ -94,7 +94,6 @@ def add_stamp_duty_line(self): invoice_line_vals = { "move_id": inv.id, "product_id": stamp_product_id.id, - "is_stamp_line": True, "name": stamp_product_id.description_sale, "sequence": 99999, "account_id": stamp_account.id, @@ -107,7 +106,6 @@ def add_stamp_duty_line(self): inv.write({"invoice_line_ids": [(0, 0, invoice_line_vals)]}) def is_stamp_duty_line_present(self): - self.ensure_one() for line in self.line_ids: if line.is_stamp_line: return True @@ -118,9 +116,9 @@ def is_stamp_duty_line_present(self): "invoice_line_ids.product_id", "invoice_line_ids.product_id.l10n_it_account_stamp_is_stamp", ) - def _compute_l10n_it_account_stamp_is_stamp_duty_present(self): + def _compute_l10n_it_account_stamp_is_stamp_duty_invoice_line_present(self): for invoice in self: - invoice.l10n_it_account_stamp_is_stamp_duty_present = ( + invoice.l10n_it_account_stamp_is_stamp_duty_invoice_line_present = ( invoice.is_stamp_duty_product_present() ) diff --git a/l10n_it_account_stamp/tests/test_account_stamp_invoicing.py b/l10n_it_account_stamp/tests/test_account_stamp_invoicing.py index a50544bcb759..36048e6c70fe 100644 --- a/l10n_it_account_stamp/tests/test_account_stamp_invoicing.py +++ b/l10n_it_account_stamp/tests/test_account_stamp_invoicing.py @@ -108,28 +108,25 @@ def test_amount_total_changing_currency(self): invoice.action_post() self.assertEqual(total, invoice.amount_total) - def test_stamp_duty_line_button(self): - """Stamp fields show when stamp is added with the button to the invoice.""" - # Arrange: Create an invoice eligible for stamp duty but without it - stamp_tax = self.tax_id - invoice = self.init_invoice( - "out_invoice", - taxes=stamp_tax, - amounts=[ - 100, - ], + def test_reset_invoice_to_draft(self): + """Reset an invoice to draft and check that relative tax stamp accounting lines + has been deleted.""" + invoice = first( + self.invoices.filtered(lambda inv: inv.move_type == "out_invoice") ) - # pre-condition - self.assertTrue(invoice.l10n_it_account_stamp_is_stamp_duty_applied) - self.assertFalse(invoice.l10n_it_account_stamp_is_stamp_duty_present) - # Act - invoice.add_stamp_duty_line() + self.assertEqual(len(invoice), 1) + self.assertEqual(len(invoice.invoice_line_ids), 2) + + invoice.invoice_line_ids[0].write({"tax_ids": [(6, 0, [self.tax_id.id])]}) invoice.action_post() - # Assert - self.assertTrue(invoice.l10n_it_account_stamp_is_stamp_duty_present) + self.assertEqual( + len(invoice.line_ids.filtered(lambda line: line.is_stamp_line)), 2 + ) - # Resetting to draft removes the stamp invoice.button_draft() - self.assertFalse(invoice.l10n_it_account_stamp_is_stamp_duty_present) + + self.assertEqual( + len(invoice.line_ids.filtered(lambda line: line.is_stamp_line)), 0 + ) diff --git a/l10n_it_account_stamp/views/account_move_view.xml b/l10n_it_account_stamp/views/account_move_view.xml index 2946386a85a0..6a0b534bfef8 100644 --- a/l10n_it_account_stamp/views/account_move_view.xml +++ b/l10n_it_account_stamp/views/account_move_view.xml @@ -34,7 +34,7 @@ invisible="l10n_it_account_stamp_auto_compute_stamp_duty" /> @@ -48,7 +48,9 @@ src="/l10n_it_account_stamp/static/description/icon.png" alt="Stamp Duty" /> - +