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 15, 2025
1 parent 5d42080 commit e75bc23
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
12 changes: 6 additions & 6 deletions l10n_it_account_stamp/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class AccountMove(models.Model):
compute="_compute_tax_stamp",
store=True,
)
tax_stamp_line_present = fields.Boolean(
tax_stamp_invoice_line_present = fields.Boolean(
string="Stamp line is present in invoice",
compute="_compute_tax_stamp_line_present",
compute="_compute_tax_stamp_invoice_line_present",
)
auto_compute_stamp = fields.Boolean(
related="company_id.tax_stamp_product_id.auto_compute"
Expand Down Expand Up @@ -84,7 +84,6 @@ def add_tax_stamp_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 @@ -97,7 +96,6 @@ def add_tax_stamp_line(self):
inv.write({"invoice_line_ids": [(0, 0, invoice_line_vals)]})

def is_tax_stamp_line_present(self):
self.ensure_one()
for line in self.line_ids:
if line.is_stamp_line:
return True
Expand All @@ -108,9 +106,11 @@ def is_tax_stamp_line_present(self):
"invoice_line_ids.product_id",
"invoice_line_ids.product_id.is_stamp",
)
def _compute_tax_stamp_line_present(self):
def _compute_tax_stamp_invoice_line_present(self):
for invoice in self:
invoice.tax_stamp_line_present = invoice.is_tax_stamp_product_present()
invoice.tax_stamp_invoice_line_present = (
invoice.is_tax_stamp_product_present()
)

def is_tax_stamp_product_present(self):
product_stamp = self.invoice_line_ids.filtered(
Expand Down
36 changes: 17 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 @@ -102,27 +102,25 @@ def test_amount_total_changing_currency(self):
invoice.action_post()
self.assertEqual(total, invoice.amount_total)

def test_tax_stamp_line_button(self):
"""Stamp fields show when stamp is added with the button to the invoice."""
# Arrange: Create an invoice eligible for tax stamp 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
are deleted."""
invoice = first(
self.invoices.filtered(lambda inv: inv.move_type == "out_invoice")
)
# pre-condition
self.assertTrue(invoice.tax_stamp)
self.assertFalse(invoice.tax_stamp_line_present)

# Act
invoice.add_tax_stamp_line()
self.assertEqual(len(invoice), 1)
self.assertEqual(len(invoice.invoice_line_ids), 2)

# Assert
self.assertTrue(invoice.tax_stamp_line_present)
invoice.invoice_line_ids[0].write({"tax_ids": [(6, 0, [self.tax_id.id])]})
invoice.action_post()

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.tax_stamp_line_present)

self.assertEqual(
len(invoice.line_ids.filtered(lambda line: line.is_stamp_line)), 0
)
6 changes: 3 additions & 3 deletions l10n_it_account_stamp/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
name="manually_apply_tax_stamp"
attrs="{'invisible': [('auto_compute_stamp', '=', True)]}"
/>
<field name="tax_stamp_line_present" invisible="1" />
<field name="tax_stamp_invoice_line_present" invisible="1" />
</xpath>
<field name="narration" position="before">
<div
Expand All @@ -40,7 +40,7 @@
alt="Tax stamp"
/>
<span
attrs="{'invisible': [('tax_stamp_line_present', '=', True)]}"
attrs="{'invisible': [('tax_stamp_invoice_line_present', '=', True)]}"
>
<span attrs="{'invisible': [('state', 'not in', 'draft')]}">
<button
Expand All @@ -54,7 +54,7 @@
</span>
</span>
<span
attrs="{'invisible': [('tax_stamp_line_present', '=', False)]}"
attrs="{'invisible': [('tax_stamp_invoice_line_present', '=', False)]}"
>
Stamp charged to customer
</span>
Expand Down

0 comments on commit e75bc23

Please sign in to comment.