Skip to content

Commit

Permalink
[IMP] l10n_it_account_stamp: Usability for stamp in invoice.
Browse files Browse the repository at this point in the history
If stamp line can be added (invoice in draft): show button to add stamp line.
If stamp line can't be added (invoice not in draft): show message explaining why it can't be added.
If stamp line has already been added: show message saying it has already been added (useful if invoice has many lines).
Button and messages update live while updating the invoice.
Better messages to user for charging stamp to customer

Co-authored-by:  Simone Rubino <[email protected]>
  • Loading branch information
2 people authored and sergiocorato committed Oct 18, 2024
1 parent 92535f0 commit f29210b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 13 deletions.
5 changes: 4 additions & 1 deletion l10n_it_account_stamp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ITA - Imposta di bollo
======================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down Expand Up @@ -135,6 +135,9 @@ Contributors
* Marco Colombo <https://github.com/TheMule71>
* Gianmarco Conte <[email protected]>
* Giovanni Serra <[email protected]>
- `Aion Tech <https://aiontech.company/>`__:

- Simone Rubino <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
22 changes: 21 additions & 1 deletion l10n_it_account_stamp/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 Simone Rubino - Aion Tech
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import _, api, fields, models
Expand All @@ -8,7 +9,15 @@ class AccountMove(models.Model):
_inherit = "account.move"

tax_stamp = fields.Boolean(
"Tax Stamp", readonly=False, compute="_compute_tax_stamp", store=True
"Tax Stamp",
help="Tax stamp is applied to this invoice.",
readonly=False,
compute="_compute_tax_stamp",
store=True,
)
tax_stamp_line_present = fields.Boolean(
string="Stamp line is present in invoice",
compute="_compute_tax_stamp_line_present",
)
auto_compute_stamp = fields.Boolean(
related="company_id.tax_stamp_product_id.auto_compute"
Expand Down Expand Up @@ -76,6 +85,7 @@ 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 @@ -94,11 +104,21 @@ def _move_autocomplete_invoice_lines_values(self):
return super()._move_autocomplete_invoice_lines_values()

def is_tax_stamp_line_present(self):
self.ensure_one()
for line in self.line_ids:
if line.is_stamp_line:
return True
return False

@api.depends(
"invoice_line_ids",
"invoice_line_ids.product_id",
"invoice_line_ids.product_id.is_stamp",
)
def _compute_tax_stamp_line_present(self):
for invoice in self:
invoice.tax_stamp_line_present = invoice.is_tax_stamp_line_present()

def is_tax_stamp_product_present(self):
product_stamp = self.invoice_line_ids.filtered(
lambda line: line.product_id.is_stamp
Expand Down
4 changes: 4 additions & 0 deletions l10n_it_account_stamp/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Marco Colombo &lt;<a class="reference external" href="https://github.com/TheMule71">https://github.com/TheMule71</a>&gt;</li>
<li>Gianmarco Conte &lt;<a class="reference external" href="mailto:gconte&#64;dinamicheaziendali.it">gconte&#64;dinamicheaziendali.it</a>&gt;</li>
<li>Giovanni Serra &lt;<a class="reference external" href="mailto:giovanni&#64;gslab.it">giovanni&#64;gslab.it</a>&gt;</li>
<li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
25 changes: 25 additions & 0 deletions l10n_it_account_stamp/tests/test_account_stamp_invoicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,28 @@ def test_amount_total_changing_currency(self):
total = invoice.amount_total
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,
],
)
# pre-condition
self.assertTrue(invoice.tax_stamp)
self.assertFalse(invoice.tax_stamp_line_present)

# Act
invoice.add_tax_stamp_line()

# Assert
self.assertTrue(invoice.tax_stamp_line_present)

# Resetting to draft removes the stamp
invoice.button_draft()
self.assertFalse(invoice.tax_stamp_line_present)
44 changes: 33 additions & 11 deletions l10n_it_account_stamp/views/account_move_view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
~ Copyright 2023 Simone Rubino - Aion Tech
~ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
-->
<odoo>

<!-- Form: Invoice Customer -->
Expand All @@ -23,20 +27,38 @@
name="manually_apply_tax_stamp"
attrs="{'invisible': [('auto_compute_stamp', '=', True)]}"
/>
<field name="tax_stamp_line_present" invisible="1" />
</xpath>
<field name="narration" position="before">
<img
src="/l10n_it_account_stamp/static/description/icon.png"
alt="Tax stamp"
<div
name="stamp_applicability"
attrs="{'invisible': [('tax_stamp', '=', False)]}"
/>
<button
class="oe_edit_only"
type="object"
string="Add tax stamp line"
name="add_tax_stamp_line"
attrs="{'invisible': ['|',('tax_stamp', '=', False),('state', 'not in', 'draft')]}"
/>
colspan="2"
>
<img
src="/l10n_it_account_stamp/static/description/icon.png"
alt="Tax stamp"
/>
<span
attrs="{'invisible': [('tax_stamp_line_present', '=', True)]}"
>
<span attrs="{'invisible': [('state', 'not in', 'draft')]}">
<button
type="object"
string="Charge stamp to customer"
name="add_tax_stamp_line"
/>
</span>
<span attrs="{'invisible': [('state', '=', 'draft')]}">
Stamp can only be charged to customer when invoice is in draft state
</span>
</span>
<span
attrs="{'invisible': [('tax_stamp_line_present', '=', False)]}"
>
Stamp charged to customer
</span>
</div>
<!--move narration down-->
<div />
</field>
Expand Down

0 comments on commit f29210b

Please sign in to comment.