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

[FIX] l10n_it_withholding_tax: fix amount_net_pay compute and add new field amount_net_pay_signed to show the value with a proper sign #4606

Open
wants to merge 1 commit into
base: 16.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
15 changes: 14 additions & 1 deletion l10n_it_withholding_tax/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class AccountMove(models.Model):
"invoice_line_ids.price_subtotal",
"withholding_tax_line_ids.tax",
"amount_total",
"amount_total_signed",
# "payment_move_line_ids",
)
def _compute_amount_withholding_tax(self):
Expand All @@ -287,7 +288,12 @@ def _compute_amount_withholding_tax(self):
withholding_tax_amount += float_round(
wt_line.tax, dp_obj.precision_get("Account")
)
invoice.amount_net_pay = invoice.amount_total - withholding_tax_amount
wt_sign = -1 if 'refund' in invoice.move_type else 1
# amount_net_pay_signed will be shown into the invoice tree, while
# amount_net_pay will be used into the invoice form and to compute residual
invoice.amount_net_pay_signed = invoice.amount_total_signed + (wt_sign * withholding_tax_amount)
amount_net_pay = abs(invoice.amount_total_signed) - withholding_tax_amount
invoice.amount_net_pay = amount_net_pay
amount_net_pay_residual = invoice.amount_net_pay
invoice.withholding_tax_amount = withholding_tax_amount

Expand Down Expand Up @@ -339,6 +345,13 @@ def _compute_amount_withholding_tax(self):
store=True,
readonly=True,
)
amount_net_pay_signed = fields.Float(
compute="_compute_amount_withholding_tax",
digits="Account",
string="Net To Pay Signed",
store=True,
readonly=True,
)

@api.onchange("invoice_line_ids")
def _onchange_invoice_line_wt_ids(self):
Expand Down
6 changes: 3 additions & 3 deletions l10n_it_withholding_tax/views/account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@
<field name="arch" type="xml">
<field name="amount_residual_signed" position="after">
<field
name="amount_net_pay"
name="amount_net_pay_signed"
widget="monetary"
options="{'currency_field': 'currency_id'}"
sum="Net to pay"
options="{'currency_field': 'company_currency_id'}"
sum="Net to pay signed"
/>
</field>
</field>
Expand Down
Loading