| 1 |
# -*- coding: utf-8 -*- |
| 2 |
from odoo.addons.l10n_ar.tests.common import TestArCommon |
| 3 |
from odoo.tests import tagged |
| 4 |
from odoo import Command |
| 5 |
from datetime import datetime |
| 6 |
|
| 7 |
|
| 8 |
@tagged('post_install_l10n', 'post_install', '-at_install') |
| 9 |
class TestArWithholdingArRi(TestArCommon): |
| 10 |
|
| 11 |
@classmethod |
| 12 |
def setUpClass(cls): |
| 13 |
|
| 14 |
super().setUpClass() |
| 15 |
|
| 16 |
cls.tax_wth_seq = cls.env['ir.sequence'].create({ |
| 17 |
'implementation': 'standard', |
| 18 |
'name': 'tax wth test', |
| 19 |
'padding': 8, |
| 20 |
'number_increment': 1, |
| 21 |
}) |
| 22 |
# Withholding 1: 1% untaxed_amount |
| 23 |
cls.tax_wth_test_1 = cls.env.ref('account.%i_ex_tax_withholding_iibb_caba_applied' % cls.env.company.id) |
| 24 |
cls.tax_wth_test_1.write({ |
| 25 |
'amount': 10, |
| 26 |
'amount_type': 'percent', |
| 27 |
'l10n_ar_withholding_sequence_id': cls.tax_wth_seq.id, |
| 28 |
}) |
| 29 |
|
| 30 |
# Withholding 2: 1% total_amount |
| 31 |
cls.tax_wth_test_2 = cls.env.ref('account.%i_ex_tax_withholding_iibb_ba_applied' % cls.env.company.id) |
| 32 |
cls.tax_wth_test_2.write({ |
| 33 |
'amount': 10, |
| 34 |
'amount_type': 'percent', |
| 35 |
'l10n_ar_withholding_sequence_id': cls.tax_wth_seq.id, |
| 36 |
}) |
| 37 |
|
| 38 |
cls.tax_21 = cls.env.ref('account.%s_ri_tax_vat_21_ventas' % cls.env.company.id) |
| 39 |
|
| 40 |
cls.other_currency = cls.setup_other_currency('USD', rounding=0.001, rates=[('2023-01-01', 0.01), ('2023-05-01', 0.005)]) |
| 41 |
cls.tax_wth_earnings_incurred_scale_test_5 = cls.env.ref('account.%i_ex_tax_withholding_profits_regimen_110_insc' % cls.env.company.id) |
| 42 |
cls.tax_wth_earnings_incurred_test_6 = cls.env.ref('account.%i_ex_tax_withholding_profits_regimen_35_insc' % cls.env.company.id) |
| 43 |
cls.earnings_withholding_sequence = cls.env['ir.sequence'].create({ |
| 44 |
'implementation': 'standard', |
| 45 |
'name': 'tax wth test', |
| 46 |
'padding': 1, |
| 47 |
'number_increment': 1, |
| 48 |
}) |
| 49 |
|
| 50 |
def in_invoice_wht(self, l10n_latam_document_number): |
| 51 |
in_invoice_wht = self.env['account.move'].create({ |
| 52 |
'move_type': 'in_invoice', |
| 53 |
'date': '2023-01-01', |
| 54 |
'invoice_date': '2023-01-01', |
| 55 |
'partner_id': self.res_partner_adhoc.id, |
| 56 |
'invoice_line_ids': [Command.create({'product_id': self.product_a.id, 'price_unit': 1000.0, 'tax_ids': [Command.set(self.tax_21.ids)]})], |
| 57 |
'l10n_latam_document_number': l10n_latam_document_number, |
| 58 |
|
| 59 |
}) |
| 60 |
in_invoice_wht.action_post() |
| 61 |
return in_invoice_wht |
| 62 |
|
| 63 |
def in_invoice_2_wht(self, l10n_latam_document_number): |
| 64 |
in_invoice_wht = self.env['account.move'].create({ |
| 65 |
'move_type': 'in_invoice', |
| 66 |
'date': '2023-01-01', |
| 67 |
'invoice_date': '2023-01-01', |
| 68 |
'partner_id': self.res_partner_adhoc.id, |
| 69 |
'invoice_line_ids': [ |
| 70 |
(0, 0, {'product_id': self.product_b.id, 'price_unit': 1000.0, 'tax_ids': [Command.set(self.tax_21.ids)]}) |
| 71 |
], |
| 72 |
'l10n_latam_document_number': l10n_latam_document_number, |
| 73 |
|
| 74 |
}) |
| 75 |
in_invoice_wht.action_post() |
| 76 |
return in_invoice_wht |
| 77 |
|
| 78 |
def in_invoice_3_wht(self): |
| 79 |
invoice = self.env['account.move'].create({ |
| 80 |
"ref": "Invoice from partner Adhoc service", |
| 81 |
"partner_id": self.res_partner_adhoc.id, |
| 82 |
"move_type": "in_invoice", |
| 83 |
"invoice_line_ids": [(0, 0, { |
| 84 |
'product_id': self.service_iva_21.id, |
| 85 |
'price_unit': 30000.0, |
| 86 |
'quantity': 1 |
| 87 |
})], |
| 88 |
"invoice_date": datetime.today(), |
| 89 |
"l10n_latam_document_number": '1-1', |
| 90 |
}) |
| 91 |
invoice.action_post() |
| 92 |
return invoice |
| 93 |
|
| 94 |
def in_invoice_4_wht(self): |
| 95 |
invoice = self.env['account.move'].create({ |
| 96 |
"ref": "Invoice from partner Adhoc service", |
| 97 |
"partner_id": self.res_partner_adhoc.id, |
| 98 |
"move_type": "in_invoice", |
| 99 |
"invoice_line_ids": [(0, 0, { |
| 100 |
'product_id': self.service_iva_21.id, |
| 101 |
'price_unit': 40000.0, |
| 102 |
'quantity': 1 |
| 103 |
})], |
| 104 |
"invoice_date": datetime.today(), |
| 105 |
"l10n_latam_document_number": '1-2', |
| 106 |
}) |
| 107 |
invoice.action_post() |
| 108 |
return invoice |
| 109 |
|
| 110 |
def third_party_check_journal(self): |
| 111 |
journal_vals = { |
| 112 |
'name': ('Third Party Checks'), |
| 113 |
'type': 'cash', |
| 114 |
'outbound_payment_method_line_ids': [ |
| 115 |
Command.create({'payment_method_id': self.env.ref('l10n_latam_check.account_payment_method_out_third_party_checks').id}), |
| 116 |
], |
| 117 |
'inbound_payment_method_line_ids': [ |
| 118 |
Command.create({'payment_method_id': self.env.ref('l10n_latam_check.account_payment_method_new_third_party_checks').id}), |
| 119 |
Command.create({'payment_method_id': self.env.ref('l10n_latam_check.account_payment_method_in_third_party_checks').id}), |
| 120 |
], |
| 121 |
} |
| 122 |
third_party_check_journal = self.env['account.journal'].create(journal_vals) |
| 123 |
return third_party_check_journal |
| 124 |
|
| 125 |
def in_third_party_check(self, journal): |
| 126 |
in_third_party_check = self.env['account.payment'].create({ |
| 127 |
'date': datetime.today(), |
| 128 |
'amount': 30762.71, |
| 129 |
'payment_type': 'inbound', |
| 130 |
'partner_id': self.res_partner_adhoc.id, |
| 131 |
'journal_id': journal.id, |
| 132 |
'payment_method_line_id': journal.inbound_payment_method_line_ids[0].id, |
| 133 |
'l10n_latam_new_check_ids': [Command.clear()] + [Command.create({'name': 1, 'amount': 30762.71, 'payment_date': datetime.today()})] |
| 134 |
}) |
| 135 |
in_third_party_check.action_post() |
| 136 |
return in_third_party_check |
| 137 |
|
| 138 |
def in_invoice_wht_5(self, l10n_latam_document_number): |
| 139 |
in_invoice_wht = self.env['account.move'].create({ |
| 140 |
'move_type': 'in_invoice', |
| 141 |
'date': '2023-01-01', |
| 142 |
'invoice_date': '2023-01-01', |
| 143 |
'partner_id': self.res_partner_adhoc.id, |
| 144 |
'invoice_line_ids': [Command.create({'product_id': self.product_a.id, 'price_unit': 156087.00, 'tax_ids': [Command.set(self.tax_21.ids)]})], |
| 145 |
'l10n_latam_document_number': l10n_latam_document_number, |
| 146 |
|
| 147 |
}) |
| 148 |
in_invoice_wht.action_post() |
| 149 |
return in_invoice_wht |
| 150 |
|
| 151 |
def new_payment_register(self, move_ids, taxes): |
| 152 |
wizard = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=move_ids.ids).create({'payment_date': '2023-01-01'}) |
| 153 |
wizard.l10n_ar_withholding_ids = [Command.clear()] + [Command.create({'tax_id': x['id'], 'base_amount': x['base_amount'], 'amount': 0}) for x in taxes] |
| 154 |
wizard.l10n_ar_withholding_ids._compute_amount() |
| 155 |
return wizard |
| 156 |
|
| 157 |
def test_01_simple_full_payment(self): |
| 158 |
"""Simple full payment in Company currency""" |
| 159 |
moves = self.in_invoice_wht('2-1') |
| 160 |
taxes = [{'id': self.tax_wth_test_1.id, 'base_amount': sum(moves.mapped('amount_untaxed'))}] |
| 161 |
wizard = self.new_payment_register(moves, taxes) |
| 162 |
self.assertEqual(wizard.currency_id.round(sum(wizard.l10n_ar_withholding_ids.mapped('amount'))) + wizard.l10n_ar_net_amount, wizard.amount) |
| 163 |
action = wizard.action_create_payments() |
| 164 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 165 |
self.assertRecordValues(payment.move_id.line_ids.sorted('balance'), [ |
| 166 |
# Liquidity line: |
| 167 |
{'debit': 0.0, 'credit': 1110.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -1110.0, 'reconciled': False}, |
| 168 |
# base line: |
| 169 |
{'debit': 0.0, 'credit': 1000.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -1000.0, 'reconciled': False}, |
| 170 |
# withholding line: |
| 171 |
{'debit': 0.0, 'credit': 100.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -100.0, 'reconciled': False}, |
| 172 |
# base line: |
| 173 |
{'debit': 1000.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 1000.0, 'reconciled': False}, |
| 174 |
# Receivable line: |
| 175 |
{'debit': 1210.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 1210.0, 'reconciled': True} |
| 176 |
]) |
| 177 |
self.assertEqual(1210, payment.currency_id.round(sum(payment.l10n_ar_withholding_ids.mapped('amount_currency')) * -1 + payment.amount)) |
| 178 |
|
| 179 |
def test_02_two_payments_same_invoice(self): |
| 180 |
"""Test two payments to same invoice""" |
| 181 |
moves = self.in_invoice_wht('2-2') |
| 182 |
taxes = [{'id': self.tax_wth_test_1.id, 'base_amount': sum(moves.mapped('amount_untaxed')) * 0.5}] |
| 183 |
|
| 184 |
wizard_1 = self.new_payment_register(moves, taxes) |
| 185 |
wizard_1.amount = 605.00 |
| 186 |
self.assertEqual(wizard_1.currency_id.round(sum(wizard_1.l10n_ar_withholding_ids.mapped('amount'))) + wizard_1.l10n_ar_net_amount, wizard_1.amount) |
| 187 |
action = wizard_1.action_create_payments() |
| 188 |
payment_1 = self.env['account.payment'].browse(action['res_id']) |
| 189 |
|
| 190 |
# Alf payments in Company currency |
| 191 |
wizard_2 = self.new_payment_register(moves, taxes) |
| 192 |
self.assertEqual(605, wizard_2.source_amount) |
| 193 |
self.assertEqual(wizard_2.currency_id.round(sum(wizard_2.l10n_ar_withholding_ids.mapped('amount'))) + wizard_2.l10n_ar_net_amount, wizard_2.amount) |
| 194 |
action = wizard_2.action_create_payments() |
| 195 |
payment_2 = self.env['account.payment'].browse(action['res_id']) |
| 196 |
self.assertRecordValues(payment_1.move_id.line_ids.sorted('balance'), [ |
| 197 |
# Liquidity line: |
| 198 |
{'debit': 0.0, 'credit': 555.0, 'currency_id': wizard_1.currency_id.id, 'amount_currency': -555.0, 'reconciled': False}, |
| 199 |
# base line: |
| 200 |
{'debit': 0.0, 'credit': 500.0, 'currency_id': wizard_1.currency_id.id, 'amount_currency': -500.0, 'reconciled': False}, |
| 201 |
# withholding line: |
| 202 |
{'debit': 0.0, 'credit': 50.0, 'currency_id': wizard_1.currency_id.id, 'amount_currency': -50.0, 'reconciled': False}, |
| 203 |
# base line: |
| 204 |
{'debit': 500, 'credit': 0.0, 'currency_id': wizard_1.currency_id.id, 'amount_currency': 500, 'reconciled': False}, |
| 205 |
# Receivable line: |
| 206 |
{'debit': 605.0, 'credit': 0.0, 'currency_id': wizard_1.currency_id.id, 'amount_currency': 605.0, 'reconciled': True} |
| 207 |
]) |
| 208 |
self.assertEqual(605, payment_1.currency_id.round(sum(payment_1.l10n_ar_withholding_ids.mapped('amount_currency')) * -1 + payment_1.amount)) |
| 209 |
|
| 210 |
self.assertRecordValues(payment_2.move_id.line_ids.sorted('balance'), [ |
| 211 |
# Liquidity line: |
| 212 |
{'debit': 0.0, 'credit': 555.0, 'currency_id': wizard_2.currency_id.id, 'amount_currency': -555.0, 'reconciled': False}, |
| 213 |
# base line: |
| 214 |
{'debit': 0.0, 'credit': 500.0, 'currency_id': wizard_2.currency_id.id, 'amount_currency': -500.0, 'reconciled': False}, |
| 215 |
# withholding line: |
| 216 |
{'debit': 0.0, 'credit': 50.0, 'currency_id': wizard_2.currency_id.id, 'amount_currency': -50.0, 'reconciled': False}, |
| 217 |
# base line: |
| 218 |
{'debit': 500, 'credit': 0.0, 'currency_id': wizard_2.currency_id.id, 'amount_currency': 500, 'reconciled': False}, |
| 219 |
# Receivable line: |
| 220 |
{'debit': 605.0, 'credit': 0.0, 'currency_id': wizard_2.currency_id.id, 'amount_currency': 605.0, 'reconciled': True} |
| 221 |
]) |
| 222 |
self.assertEqual(605, payment_2.currency_id.round(sum(payment_2.l10n_ar_withholding_ids.mapped('amount_currency')) * -1 + payment_2.amount)) |
| 223 |
|
| 224 |
def test_03_two_withholdings_one_payment(self): |
| 225 |
"""Simple full payment in Company currency and two wht""" |
| 226 |
moves = self.in_invoice_2_wht('2-3') |
| 227 |
taxes = [{'id': self.tax_wth_test_1.id, 'base_amount': sum(moves.mapped('amount_untaxed'))}, {'id': self.tax_wth_test_2.id, 'base_amount': sum(moves.mapped('amount_total'))}] |
| 228 |
|
| 229 |
wizard = self.new_payment_register(moves, taxes) |
| 230 |
self.assertEqual(wizard.currency_id.round(sum(wizard.l10n_ar_withholding_ids.mapped('amount'))) + wizard.l10n_ar_net_amount, wizard.amount) |
| 231 |
action = wizard.action_create_payments() |
| 232 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 233 |
line_1 = payment.l10n_ar_withholding_ids.filtered(lambda x: x.tax_line_id.id == self.tax_wth_test_1.id) |
| 234 |
line_2 = payment.l10n_ar_withholding_ids.filtered(lambda x: x.tax_line_id.id == self.tax_wth_test_2.id) |
| 235 |
self.assertEqual(-100, line_1.amount_currency) |
| 236 |
self.assertEqual(-121, line_2.amount_currency) |
| 237 |
self.assertEqual(1210, payment.currency_id.round(sum(payment.l10n_ar_withholding_ids.mapped('amount_currency')) * -1 + payment.amount)) |
| 238 |
|
| 239 |
def test_04_two_withholdings_different_currency(self): |
| 240 |
"""Payment in other currency and two withholdings""" |
| 241 |
moves = self.in_invoice_2_wht('2-4') |
| 242 |
taxes = [{'id': self.tax_wth_test_1.id, 'base_amount': 5}, {'id': self.tax_wth_test_2.id, 'base_amount': 6.05}] |
| 243 |
wizard = self.new_payment_register(moves, []) |
| 244 |
wizard.currency_id = self.other_currency.id |
| 245 |
wizard.amount = 6.05 |
| 246 |
wizard.l10n_ar_withholding_ids = [Command.clear()] + [Command.create({'tax_id': x['id'], 'base_amount': x['base_amount'], 'amount': 0}) for x in taxes] |
| 247 |
wizard.l10n_ar_withholding_ids._compute_amount() |
| 248 |
self.assertEqual(wizard.currency_id.round(sum(wizard.l10n_ar_withholding_ids.mapped('amount')) + wizard.l10n_ar_net_amount), wizard.currency_id.round(wizard.amount)) |
| 249 |
action = wizard.action_create_payments() |
| 250 |
|
| 251 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 252 |
line_1 = payment.l10n_ar_withholding_ids.filtered(lambda x: x.tax_line_id.id == self.tax_wth_test_1.id) |
| 253 |
line_2 = payment.l10n_ar_withholding_ids.filtered(lambda x: x.tax_line_id.id == self.tax_wth_test_2.id) |
| 254 |
self.assertEqual(-0.50, line_1.amount_currency) |
| 255 |
self.assertEqual(-50, line_1.balance) |
| 256 |
self.assertEqual(-0.605, line_2.amount_currency) |
| 257 |
self.assertEqual(-60.5, line_2.balance) |
| 258 |
self.assertEqual(6.05, payment.currency_id.round(sum(payment.l10n_ar_withholding_ids.mapped('amount_currency')) * -1 + payment.amount)) |
| 259 |
|
| 260 |
def test_05_earnings_withholding_applied_with_scale(self): |
| 261 |
"""Two payments with same withholding tax (with tax type 'Earnings Scale'). Verify withholding amount.""" |
| 262 |
invoice = self.in_invoice_3_wht() |
| 263 |
self.tax_wth_earnings_incurred_scale_test_5.l10n_ar_withholding_sequence_id = self.earnings_withholding_sequence |
| 264 |
self.env['l10n_ar.partner.tax'].create({ |
| 265 |
'partner_id': self.res_partner_adhoc.id, |
| 266 |
'company_id': invoice.company_id.id, |
| 267 |
'tax_id': self.tax_wth_earnings_incurred_scale_test_5.id |
| 268 |
}) |
| 269 |
taxes = [{'id': invoice.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice.amount_untaxed}] |
| 270 |
wizard = self.new_payment_register(invoice, taxes) |
| 271 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 1600) |
| 272 |
wizard.action_create_payments() |
| 273 |
invoice2 = self.in_invoice_4_wht() |
| 274 |
taxes = [{'id': invoice2.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice2.amount_untaxed}] |
| 275 |
wizard = self.new_payment_register(invoice2, taxes) |
| 276 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 7480) |
| 277 |
wizard.action_create_payments() |
| 278 |
|
| 279 |
def test_06_earnings_withholding_applied(self): |
| 280 |
"""Two payments with same withholding tax (with tax type 'Earnings'). Verify withholding amount.""" |
| 281 |
invoice = self.in_invoice_3_wht() |
| 282 |
self.tax_wth_earnings_incurred_test_6.l10n_ar_withholding_sequence_id = self.earnings_withholding_sequence |
| 283 |
self.env['l10n_ar.partner.tax'].create({ |
| 284 |
'partner_id': self.res_partner_adhoc.id, |
| 285 |
'company_id': invoice.company_id.id, |
| 286 |
'tax_id': self.tax_wth_earnings_incurred_test_6.id |
| 287 |
}) |
| 288 |
taxes = [{'id': invoice.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice.amount_untaxed}] |
| 289 |
wizard = self.new_payment_register(invoice, taxes) |
| 290 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 1327.8) |
| 291 |
wizard.action_create_payments() |
| 292 |
invoice2 = self.in_invoice_4_wht() |
| 293 |
taxes = [{'id': invoice2.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice2.amount_untaxed}] |
| 294 |
wizard = self.new_payment_register(invoice2, taxes) |
| 295 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 2400) |
| 296 |
wizard.action_create_payments() |
| 297 |
|
| 298 |
def test_07_earnings_partial_payment_withholding_applied_with_scale(self): |
| 299 |
"""Partial payment with withholding tax (with tax type 'Earnings Scale'). Verify withholding amount.""" |
| 300 |
invoice = self.in_invoice_3_wht() |
| 301 |
self.tax_wth_earnings_incurred_scale_test_5.l10n_ar_withholding_sequence_id = self.earnings_withholding_sequence |
| 302 |
self.env['l10n_ar.partner.tax'].create({ |
| 303 |
'partner_id': self.res_partner_adhoc.id, |
| 304 |
'company_id': invoice.company_id.id, |
| 305 |
'tax_id': self.tax_wth_earnings_incurred_scale_test_5.id |
| 306 |
}) |
| 307 |
taxes = [{'id': invoice.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice.amount_untaxed}] |
| 308 |
wizard = self.new_payment_register(invoice, taxes) |
| 309 |
wizard.amount -= 2420 |
| 310 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 1360) |
| 311 |
|
| 312 |
def test_08_earnings_withholding_applied_with_scale_and_minimun_withholdable_amount_set(self): |
| 313 |
"""Payment with withholding tax type 'Earnings Scale' and minimun withholdable amount set. Verify withholding amount.""" |
| 314 |
invoice = self.in_invoice_3_wht() |
| 315 |
self.tax_wth_earnings_incurred_scale_test_5.l10n_ar_withholding_sequence_id = self.earnings_withholding_sequence |
| 316 |
self.tax_wth_earnings_incurred_scale_test_5.l10n_ar_minimum_threshold = 2000 |
| 317 |
self.env['l10n_ar.partner.tax'].create({ |
| 318 |
'partner_id': self.res_partner_adhoc.id, |
| 319 |
'company_id': invoice.company_id.id, |
| 320 |
'tax_id': self.tax_wth_earnings_incurred_scale_test_5.id |
| 321 |
}) |
| 322 |
taxes = [{'id': invoice.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice.amount_untaxed}] |
| 323 |
wizard = self.new_payment_register(invoice, taxes) |
| 324 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 0.0) |
| 325 |
|
| 326 |
def test_09_foreign_invoice(self): |
| 327 |
""" Ensure a correct behavior when the invoice has a foreign currency and the payment not. """ |
| 328 |
in_invoice_wht = self.env['account.move'].create({ |
| 329 |
'move_type': 'in_invoice', |
| 330 |
'date': '2023-01-01', |
| 331 |
'invoice_date': '2023-01-01', |
| 332 |
'currency_id': self.other_currency.id, |
| 333 |
'partner_id': self.res_partner_adhoc.id, |
| 334 |
'invoice_line_ids': [Command.create( |
| 335 |
{'product_id': self.product_a.id, 'price_unit': 1000.0, 'tax_ids': [Command.set(self.tax_21.ids)]} |
| 336 |
)], |
| 337 |
'l10n_latam_document_number': '2-1', |
| 338 |
}) |
| 339 |
in_invoice_wht.action_post() |
| 340 |
wizard = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=in_invoice_wht.ids).create({ |
| 341 |
'payment_date': '2023-01-01', |
| 342 |
'currency_id': self.company_data['currency'].id, |
| 343 |
'l10n_ar_withholding_ids': [Command.create({'tax_id': self.tax_wth_test_1.id, 'base_amount': sum(in_invoice_wht.mapped('amount_untaxed')), 'amount': 0})], |
| 344 |
}) |
| 345 |
wizard.l10n_ar_withholding_ids._compute_amount() |
| 346 |
action = wizard.action_create_payments() |
| 347 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 348 |
self.assertRecordValues(payment.move_id.line_ids.sorted('balance'), [ |
| 349 |
# Liquidity line: |
| 350 |
{'debit': 0.0, 'credit': 120900.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -120900.0, 'reconciled': False}, |
| 351 |
# base line: |
| 352 |
{'debit': 0.0, 'credit': 1000.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -1000.0, 'reconciled': False}, |
| 353 |
# withholding line: |
| 354 |
{'debit': 0.0, 'credit': 100.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -100.0, 'reconciled': False}, |
| 355 |
# base line: |
| 356 |
{'debit': 1000.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 1000.0, 'reconciled': False}, |
| 357 |
# Receivable line: |
| 358 |
{'debit': 121000.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 121000.0, 'reconciled': True} |
| 359 |
]) |
| 360 |
|
| 361 |
def test_10_foreign_invoice_and_payment(self): |
| 362 |
""" Ensure a correct behavior when the invoice and the payment have a foreign currency. """ |
| 363 |
in_invoice_wht = self.env['account.move'].create({ |
| 364 |
'move_type': 'in_invoice', |
| 365 |
'date': '2023-01-01', |
| 366 |
'invoice_date': '2023-01-01', |
| 367 |
'currency_id': self.other_currency.id, |
| 368 |
'partner_id': self.res_partner_adhoc.id, |
| 369 |
'invoice_line_ids': [Command.create( |
| 370 |
{'product_id': self.product_a.id, 'price_unit': 1000.0, 'tax_ids': [Command.set(self.tax_21.ids)]} |
| 371 |
)], |
| 372 |
'l10n_latam_document_number': '2-1', |
| 373 |
}) |
| 374 |
in_invoice_wht.action_post() |
| 375 |
wizard = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=in_invoice_wht.ids).create({ |
| 376 |
'payment_date': '2023-01-01', |
| 377 |
'currency_id': self.other_currency.id, |
| 378 |
'l10n_ar_withholding_ids': [Command.create({'tax_id': self.tax_wth_test_1.id, 'base_amount': sum(in_invoice_wht.mapped('amount_untaxed')), 'amount': 0})], |
| 379 |
}) |
| 380 |
wizard.l10n_ar_withholding_ids._compute_amount() |
| 381 |
action = wizard.action_create_payments() |
| 382 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 383 |
self.assertRecordValues(payment.move_id.line_ids.sorted('balance'), [ |
| 384 |
# Liquidity line: |
| 385 |
{'debit': 0.0, 'credit': 111000.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -1110.0, 'reconciled': False}, |
| 386 |
# base line: |
| 387 |
{'debit': 0.0, 'credit': 100000.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -1000.0, 'reconciled': False}, |
| 388 |
# withholding line: |
| 389 |
{'debit': 0.0, 'credit': 10000.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -100.0, 'reconciled': False}, |
| 390 |
# base line: |
| 391 |
{'debit': 100000.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 1000.0, 'reconciled': False}, |
| 392 |
# Receivable line: |
| 393 |
{'debit': 121000.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 1210.0, 'reconciled': True} |
| 394 |
]) |
| 395 |
|
| 396 |
def test_11_earnings_withholding_applied_with_scale(self): |
| 397 |
"""Payment with third party check with withholding tax type 'Earnings Scale'. Verify withholding amount.""" |
| 398 |
third_party_check_journal = self.third_party_check_journal() |
| 399 |
in_third_party_check = self.in_third_party_check(third_party_check_journal) |
| 400 |
invoice = self.in_invoice_4_wht() |
| 401 |
self.tax_wth_earnings_incurred_scale_test_5.l10n_ar_withholding_sequence_id = self.earnings_withholding_sequence |
| 402 |
self.env['l10n_ar.partner.tax'].create({ |
| 403 |
'partner_id': self.res_partner_adhoc.id, |
| 404 |
'company_id': invoice.company_id.id, |
| 405 |
'tax_id': self.tax_wth_earnings_incurred_scale_test_5.id |
| 406 |
}) |
| 407 |
taxes = [{'id': invoice.partner_id.l10n_ar_partner_tax_ids.tax_id.id, 'base_amount': invoice.amount_untaxed}] |
| 408 |
wizard = self.new_payment_register(invoice, taxes) |
| 409 |
wizard.journal_id = third_party_check_journal.id |
| 410 |
wizard.payment_method_line_id = wizard.journal_id.inbound_payment_method_line_ids[1].id |
| 411 |
wizard.l10n_latam_move_check_ids = in_third_party_check.l10n_latam_new_check_ids |
| 412 |
wizard._compute_amount() |
| 413 |
self.assertEqual(wizard.amount, 31929.25) |
| 414 |
self.assertEqual(wizard.l10n_ar_withholding_ids.base_amount, 26387.81) |
| 415 |
self.assertEqual(wizard.l10n_ar_withholding_ids.amount, 1166.54) |
| 416 |
self.assertEqual(wizard.l10n_ar_net_amount, 30762.71) |
| 417 |
|
| 418 |
def test_11_withholding_amounts_1(self): |
| 419 |
"""Check computation of withholding tax amount.""" |
| 420 |
self.tax_wth_test_1.write({'amount': 4.5}) |
| 421 |
moves = self.in_invoice_wht_5('2-1') |
| 422 |
taxes = [{'id': self.tax_wth_test_1.id, 'base_amount': sum(moves.mapped('amount_untaxed'))}] |
| 423 |
wizard = self.new_payment_register(moves, taxes) |
| 424 |
action = wizard.action_create_payments() |
| 425 |
payment = self.env['account.payment'].browse(action['res_id']) |
| 426 |
self.assertRecordValues(payment.move_id.line_ids.sorted('balance'), [ |
| 427 |
# Liquidity line: |
| 428 |
{'debit': 0.0, 'credit': 181841.35, 'currency_id': wizard.currency_id.id, 'amount_currency': -181841.35, 'reconciled': False}, |
| 429 |
# base line: |
| 430 |
{'debit': 0.0, 'credit': 156087.0, 'currency_id': wizard.currency_id.id, 'amount_currency': -156087.0, 'reconciled': False}, |
| 431 |
# withholding line: |
| 432 |
{'debit': 0.0, 'credit': 7023.92, 'currency_id': wizard.currency_id.id, 'amount_currency': -7023.92, 'reconciled': False}, |
| 433 |
# base line: |
| 434 |
{'debit': 156087.0, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 156087.0, 'reconciled': False}, |
| 435 |
# Receivable line: |
| 436 |
{'debit': 188865.27, 'credit': 0.0, 'currency_id': wizard.currency_id.id, 'amount_currency': 188865.27, 'reconciled': True} |
| 437 |
]) |