Skip to content

Commit

Permalink
fixup! [FIX] l10n_it_withholding_tax: porting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMule71 committed Apr 16, 2021
1 parent 48c3674 commit 2672ea9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
18 changes: 13 additions & 5 deletions l10n_it_withholding_tax/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def default_get(self, fields):
Compute amount to pay proportionally to amount total - wt
"""
rec = super(AccountAbstractPayment, self).default_get(fields)
invoice_defaults = self.new({"reconciled_invoice_ids": rec.get("reconciled_invoice_ids")}).reconciled_invoice_ids
invoice_defaults = self.new(
{"reconciled_invoice_ids": rec.get("reconciled_invoice_ids")}
).reconciled_invoice_ids

if invoice_defaults and len(invoice_defaults) == 1:
invoice = invoice_defaults[0]
Expand Down Expand Up @@ -312,14 +314,20 @@ def _compute_amount_withholding_tax(self):
amount_net_pay_residual = invoice.amount_net_pay
invoice.withholding_tax_amount = withholding_tax_amount

reconciled_lines = invoice.line_ids.filtered(lambda line: line.account_id.user_type_id.type in ('receivable', 'payable'))
reconciled_amls = reconciled_lines.mapped('matched_debit_ids.debit_move_id') + \
reconciled_lines.mapped('matched_credit_ids.credit_move_id')
reconciled_lines = invoice.line_ids.filtered(
lambda line: line.account_id.user_type_id.type
in ("receivable", "payable")
)
reconciled_amls = reconciled_lines.mapped(
"matched_debit_ids.debit_move_id"
) + reconciled_lines.mapped("matched_credit_ids.credit_move_id")

for line in reconciled_amls:
if not line.withholding_tax_generated_by_move_id:
amount_net_pay_residual -= line.debit or line.credit
invoice.amount_net_pay_residual = float_round(amount_net_pay_residual, dp_obj.precision_get("Account"))
invoice.amount_net_pay_residual = float_round(
amount_net_pay_residual, dp_obj.precision_get("Account")
)

withholding_tax = fields.Boolean("Withholding Tax")
withholding_tax_line_ids = fields.One2many(
Expand Down
8 changes: 6 additions & 2 deletions l10n_it_withholding_tax/models/withholding_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ def _check_date(self):
]
)

overlapping_rate = rate.env["withholding.tax.rate"].search(domain, limit=1)
overlapping_rate = rate.env["withholding.tax.rate"].search(
domain, limit=1
)
if overlapping_rate:
raise ValidationError(_("Error! You cannot have 2 rates that overlap!"))
raise ValidationError(
_("Error! You cannot have 2 rates that overlap!")
)

withholding_tax_id = fields.Many2one(
"withholding.tax", string="Withholding Tax", ondelete="cascade", readonly=True
Expand Down
6 changes: 3 additions & 3 deletions l10n_it_withholding_tax/tests/test_withholding_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ def test_partial_payment(self):
register_payments.action_post()

# WT amount in payment move lines
payment_line_ids = self.invoice.line_ids.filtered(lambda l: l.account_id.internal_type in ['receivable', 'payable'])
self.assertTrue(
set(payment_line_ids.mapped("debit")) == {600, 150}
payment_line_ids = self.invoice.line_ids.filtered(
lambda l: l.account_id.internal_type in ["receivable", "payable"]
)
self.assertTrue(set(payment_line_ids.mapped("debit")) == {600, 150})

# WT aomunt applied in statement
domain = [
Expand Down

0 comments on commit 2672ea9

Please sign in to comment.