Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] l10n_pt_vat: hook to control when to use PT VAT features #88

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions l10n_pt_account_invoicexpress/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def _compute_invoicexpress_doc_type(self):
" If unset, InvoiceXpress will not be used.",
)

def _compute_is_l10npt_vat_enabled(self):
super()._compute_is_l10npt_vat_enabled()
# Disable VAT PT options is InvoiceXpress is disabled
for invoice in self.filtered("invoice.is_l10npt_vat_enabled"):
if not invoice.can_invoicexpress:
invoice.is_l10npt_vat_enabled = False

@api.constrains("journal_id", "company_id")
def _check_invoicexpress_doctype_config(self):
"""
Expand Down
11 changes: 8 additions & 3 deletions l10n_pt_vat/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class AccountMove(models.Model):
_inherit = "account.move"

is_l10npt_vat_enabled = fields.Boolean(compute="_compute_is_l10npt_vat_enabled")
vat_adjustment_norm_id = fields.Many2one(
"account.vat.adjustment_norm",
string="VAT Adjustment Norm",
Expand All @@ -25,6 +26,12 @@ class AccountMove(models.Model):
readonly=False,
)

def _compute_is_l10npt_vat_enabled(self):
for invoice in self:
invoice.is_l10npt_vat_enabled = (
invoice.country_code == "PT" and invoice.is_sale_document()
)

@api.depends("country_code", "move_type", "invoice_line_ids")
def _compute_l10npt_has_tax_exempt_lines(self):
for invoice in self:
Expand Down Expand Up @@ -53,9 +60,7 @@ def action_post(self):
"""
VAT Exemption reason is required if there are lines without tax
"""
for invoice in self.filtered(
lambda x: x.country_code == "PT" and x.is_sale_document()
):
for invoice in self.filtered("is_l10npt_vat_enabled"):
exempt_lines = invoice.invoice_line_ids.filtered(
lambda x: not x.tax_ids.filtered("amount")
)
Expand Down
9 changes: 5 additions & 4 deletions l10n_pt_vat/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
<field name="arch" type="xml">

<data>
<!-- Add the VAT Adjustment Norm (Fields 40/41 of the VAT Statement) !-->
<!-- Add the VAT Adjustment Norm (Fields 40/41 of the VAT Statement) -->
<div name="journal_div" position="after">
<field name="move_type" invisible="1" />
<field name="is_l10npt_vat_enabled" invisible="1" />
<field
name="l10npt_vat_exempt_reason"
attrs="{'invisible': [('country_code', '!=', 'PT')]}"
attrs="{'invisible': [('is_l10npt_vat_enabled', '=', 'False')]}"
/>
<field name="move_type" invisible="1" />
<field
name="vat_adjustment_norm_id"
attrs="{'invisible': ['|',('country_code', '!=', 'PT'),('move_type', 'not in', ['out_refund', 'in_refund'])]}"
attrs="{'invisible': ['|',('is_l10npt_vat_enabled', '=', False),('move_type', 'not in', ['out_refund', 'in_refund'])]}"
domain="[('move_type', '=', move_type)]"
/>
</div>
Expand Down
Loading