@@ -371,3 +371,124 @@ def test_create_vendor_payment_with_receiptbook_and_withholdings(self):
371371 {"debit" : 655000.0 , "credit" : 0.0 , "amount_currency" : 655000.0 },
372372 ],
373373 )
374+
375+ def test_withholding_amounts (self ):
376+ """Verify withholding amount precision under 'round_globally' rounding method.
377+
378+ With price_unit=391683 and a 4.5% withholding tax, the exact amount is
379+ 391683 * 0.045 = 17625.735. Under 'round_globally', this rounds to 17625.74.
380+ The test ensures the rounding method is respected and the resulting
381+ withholding line carries the correctly rounded amount_currency.
382+ """
383+ company = self .env .company
384+ previous_rounding_method = company .tax_calculation_rounding_method
385+ company .tax_calculation_rounding_method = "round_globally"
386+ try :
387+ # Create a vendor bill with a single line subject to 21% VAT
388+ in_invoice_wht = self .env ["account.move" ].create (
389+ {
390+ "move_type" : "in_invoice" ,
391+ "date" : "2025-10-01" ,
392+ "invoice_date" : "2025-10-01" ,
393+ "partner_id" : self .env .ref ("l10n_ar_tax.res_partner_adhoc_caba" ).id ,
394+ "invoice_line_ids" : [
395+ Command .create (
396+ {
397+ "product_id" : self .product_a .id ,
398+ "price_unit" : 391683 ,
399+ "tax_ids" : [Command .set (self .tax_21 .ids )],
400+ }
401+ )
402+ ],
403+ "l10n_latam_document_number" : "2-5" ,
404+ }
405+ )
406+ in_invoice_wht .action_post ()
407+
408+ # Set withholding tax rate to 4.5% (produces a non-trivial rounding case)
409+ self .tax_wth_test_1 .write ({"amount" : 4.5 })
410+
411+ # Create fiscal position with withholding for CABA partner
412+ fiscal_pos = self .env ["account.fiscal.position" ].create (
413+ {
414+ "name" : "IIBB CABA Rounding" ,
415+ "l10n_ar_afip_responsibility_type_ids" : [(6 , 0 , [self .env .ref ("l10n_ar.res_IVARI" ).id ])],
416+ "sequence" : 10 ,
417+ "auto_apply" : True ,
418+ "country_id" : self .env .ref ("base.ar" ).id ,
419+ "company_id" : self .company_ri .id ,
420+ "state_ids" : [(6 , 0 , [self .env .ref ("base.state_ar_c" ).id ])],
421+ }
422+ )
423+ self .env ["account.fiscal.position.l10n_ar_tax" ].create (
424+ {
425+ "fiscal_position_id" : fiscal_pos .id ,
426+ "default_tax_id" : self .tax_wth_test_1 .id ,
427+ "tax_type" : "withholding" ,
428+ }
429+ )
430+
431+ # Create payment using register payment context
432+ action_context = in_invoice_wht .action_register_payment ()["context" ]
433+ vals = {
434+ "journal_id" : self .company_bank_journal .id ,
435+ "amount" : in_invoice_wht .amount_total ,
436+ "date" : "2025-10-01" ,
437+ }
438+ payment = self .env ["account.payment" ].with_context (** action_context ).create (vals )
439+
440+ # In direct payment creation flow, amount must be net of withholdings to fully reconcile the invoice.
441+ payment .amount = in_invoice_wht .amount_total - payment .withholdings_amount
442+ payment .action_post ()
443+
444+ self .assertEqual (payment .company_id .tax_calculation_rounding_method , "round_globally" )
445+ # 391683 * 21% = 82253.43 (VAT) -> total invoice: 473936.43
446+ # 391683 * 4.5% = 17625.735 -> rounded globally to 17625.74 (withholding)
447+ # net payment (liquidity): 473936.43 - 17625.74 = 456310.69
448+ self .assertRecordValues (
449+ payment .move_id .line_ids .sorted ("balance" ),
450+ [
451+ # Liquidity line:
452+ {
453+ "debit" : 0.0 ,
454+ "credit" : 456310.69 ,
455+ "currency_id" : payment .currency_id .id ,
456+ "amount_currency" : - 456310.69 ,
457+ "reconciled" : False ,
458+ },
459+ # base line:
460+ {
461+ "debit" : 0.0 ,
462+ "credit" : 391683.0 ,
463+ "currency_id" : payment .currency_id .id ,
464+ "amount_currency" : - 391683.0 ,
465+ "reconciled" : False ,
466+ },
467+ # withholding line:
468+ {
469+ "debit" : 0.0 ,
470+ "credit" : 17625.74 ,
471+ "currency_id" : payment .currency_id .id ,
472+ "amount_currency" : - 17625.74 ,
473+ "reconciled" : False ,
474+ },
475+ # base line:
476+ {
477+ "debit" : 391683.0 ,
478+ "credit" : 0.0 ,
479+ "currency_id" : payment .currency_id .id ,
480+ "amount_currency" : 391683.0 ,
481+ "reconciled" : False ,
482+ },
483+ # Receivable line:
484+ {
485+ "debit" : 473936.43 ,
486+ "credit" : 0.0 ,
487+ "currency_id" : payment .currency_id .id ,
488+ "amount_currency" : 473936.43 ,
489+ "reconciled" : True ,
490+ },
491+ ],
492+ )
493+ finally :
494+ company .tax_calculation_rounding_method = previous_rounding_method
0 commit comments