Skip to content

Commit

Permalink
[FIX] l10n_it_account_stamp: stamp invoice line deleted on reset to d…
Browse files Browse the repository at this point in the history
…raft
  • Loading branch information
primes2h committed Jan 16, 2025
1 parent d8eaef7 commit 0650f1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
10 changes: 4 additions & 6 deletions l10n_it_account_stamp/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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()
)

Expand Down
35 changes: 16 additions & 19 deletions l10n_it_account_stamp/tests/test_account_stamp_invoicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 7 additions & 3 deletions l10n_it_account_stamp/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
invisible="l10n_it_account_stamp_auto_compute_stamp_duty"
/>
<field
name="l10n_it_account_stamp_is_stamp_duty_present"
name="l10n_it_account_stamp_is_stamp_duty_invoice_line_present"
invisible="1"
/>
</xpath>
Expand All @@ -48,7 +48,9 @@
src="/l10n_it_account_stamp/static/description/icon.png"
alt="Stamp Duty"
/>
<span invisible="l10n_it_account_stamp_is_stamp_duty_present">
<span
invisible="l10n_it_account_stamp_is_stamp_duty_invoice_line_present"
>
<span invisible="state != 'draft'">
<button
type="object"
Expand All @@ -60,7 +62,9 @@
Stamp can only be charged to customer when invoice is in draft state
</span>
</span>
<span invisible="not l10n_it_account_stamp_is_stamp_duty_present">
<span
invisible="not l10n_it_account_stamp_is_stamp_duty_invoice_line_present"
>
Stamp charged to customer
</span>
</div>
Expand Down

0 comments on commit 0650f1d

Please sign in to comment.