Skip to content

Commit 7dfbaa4

Browse files
committed
[FIX] l10n_account_withholding_tax: partner on journal items
Fixes an issue where the partner is missing from the journal items generated by the withholding tax on payment system. closes odoo#220117 X-original-commit: 94a81e0 Signed-off-by: William André (wan) <wan@odoo.com> Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
1 parent 0450e21 commit 7dfbaa4

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

addons/l10n_account_withholding_tax/models/account_payment_withholding_line.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ def _get_valid_liquidity_accounts(self):
8989
self.payment_id.journal_id.outbound_payment_method_line_ids.payment_account_id |
9090
self.payment_id.outstanding_account_id
9191
)
92+
93+
def _get_comodel_partner(self):
94+
return self.payment_id.partner_id

addons/l10n_account_withholding_tax/models/account_withholding_line.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def _prepare_withholding_amls_create_values(self):
381381
'name': self.env._("WH Tax: %(name)s", name=tax_line_vals['name']),
382382
'amount_currency': -tax_line_vals['amount_currency'],
383383
'balance': -tax_line_vals['balance'],
384+
'partner_id': self._get_comodel_partner().id,
384385
})
385386

386387
# Aggregate the base lines.
@@ -406,6 +407,7 @@ def _prepare_withholding_amls_create_values(self):
406407
'name': self.env._('WH Base: %(names)s', names=', '.join(amounts['names'])),
407408
'amount_currency': amounts['amount_currency'],
408409
'balance': amounts['balance'],
410+
'partner_id': self._get_comodel_partner().id,
409411
})
410412
aml_create_values_list.append({
411413
**grouping_key,
@@ -415,6 +417,7 @@ def _prepare_withholding_amls_create_values(self):
415417
'analytic_distribution': None,
416418
'amount_currency': -amounts['amount_currency'],
417419
'balance': -amounts['balance'],
420+
'partner_id': self._get_comodel_partner().id,
418421
})
419422

420423
return aml_create_values_list
@@ -532,3 +535,7 @@ def grouping_function(base_line_data, tax_data):
532535
def _get_valid_liquidity_accounts(self):
533536
""" Get the valid liquidity accounts for the payment; we need to ensure that the line account does not match any of them. """
534537
return ()
538+
539+
def _get_comodel_partner(self):
540+
""" Get the partner from the comodel record; in order to have it available when required. """
541+
return self.env['res.partner']

addons/l10n_account_withholding_tax/tests/test_account_withholding_flows.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,3 +1039,32 @@ def test_manual_adjustments(self):
10391039
line_form.amount = 11
10401040
self.assertEqual(line['base_amount'], 500)
10411041
self.assertEqual(line['amount'], 11)
1042+
1043+
def test_partner_is_set_on_lines(self):
1044+
""" Test that the partner is set on the lines generated by the withholding tax on payment system. """
1045+
withholding_tax = self.percent_tax(-10, is_withholding_tax_on_payment=True, withholding_sequence_id=self.withholding_sequence.id)
1046+
1047+
invoice = self.env['account.move'].create({
1048+
'move_type': 'out_invoice',
1049+
'partner_id': self.partner_a.id,
1050+
'invoice_line_ids': [Command.create({
1051+
'product_id': self.product_a.id,
1052+
'price_unit': 1000.0,
1053+
'tax_ids': [Command.set(withholding_tax.ids)],
1054+
})],
1055+
})
1056+
invoice.action_post()
1057+
wizard = self.env['account.payment.register']\
1058+
.with_context(active_model='account.move', active_ids=invoice.ids)\
1059+
.create({})
1060+
payment = wizard._create_payments()
1061+
self.assertRecordValues(payment, [{
1062+
'amount': 1000.0,
1063+
}])
1064+
self.assertRecordValues(payment.move_id.line_ids, [
1065+
{'balance': 900.0, 'tax_ids': [], 'partner_id': self.partner_a.id},
1066+
{'balance': -1000.0, 'tax_ids': [], 'partner_id': self.partner_a.id},
1067+
{'balance': 100.0, 'tax_ids': [], 'partner_id': self.partner_a.id},
1068+
{'balance': 1000.0, 'tax_ids': withholding_tax.ids, 'partner_id': self.partner_a.id},
1069+
{'balance': -1000.0, 'tax_ids': [], 'partner_id': self.partner_a.id},
1070+
])

addons/l10n_account_withholding_tax/wizards/account_payment_register_withholding_line.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ def _get_valid_liquidity_accounts(self):
104104
self.payment_register_id.journal_id.outbound_payment_method_line_ids.payment_account_id |
105105
self.payment_register_id.withholding_outstanding_account_id
106106
)
107+
108+
def _get_comodel_partner(self):
109+
return self.payment_register_id.partner_id

0 commit comments

Comments
 (0)