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
  • Loading branch information
TonyMasciI committed Jul 7, 2023
1 parent b9c0521 commit 7fba782
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
22 changes: 21 additions & 1 deletion l10n_it_account_stamp/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
class AccountMove(models.Model):
_inherit = "account.move"

tax_stamp = fields.Boolean(readonly=False, compute="_compute_tax_stamp", store=True)
tax_stamp = fields.Boolean(
"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 @@ -86,11 +96,21 @@ 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
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
41 changes: 28 additions & 13 deletions l10n_it_account_stamp/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,37 @@
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')]}"
/>
<!--move narration down-->
<div />
>
<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>
</field>
<xpath
expr="//form/sheet/notebook/page[@id='invoice_tab']/field/form/sheet/group/field[@name='product_id']"
Expand Down

0 comments on commit 7fba782

Please sign in to comment.