Coverage for ingadhoc-account-payment / account_payment_pro / tests / test_account_paymet_pro_unit_test.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 19:54 +0000

1from datetime import timedelta 

2 

3from odoo import Command, fields 

4from odoo.tests import common, tagged 

5 

6 

7@tagged("post_install", "-at_install") 

8class TestAccountPaymentProUnitTest(common.TransactionCase): 

9 @classmethod 

10 def setUpClass(cls): 

11 super(TestAccountPaymentProUnitTest, cls).setUpClass() 

12 cls.today = fields.Date.today() 

13 cls.ar = ar = cls.env.ref("base.ar") 

14 

15 cls.company = cls.env.company 

16 cls.company_bank_journal = cls.env["account.journal"].search( 

17 [("company_id", "=", cls.company.id), ("type", "=", "bank")], limit=1 

18 ) 

19 cls.company_journal = cls.env["account.journal"].search( 

20 [("company_id", "=", cls.company.id), ("type", "=", "sale")], limit=1 

21 ) 

22 cls.company.use_payment_pro = True 

23 cls.eur_currency = cls.env["res.currency"].with_context(active_test=False).search([("name", "=", "EUR")]) 

24 cls.eur_currency.active = True 

25 cls.rates = cls.env["res.currency.rate"].create( 

26 [ 

27 { 

28 "name": "2024-01-01", 

29 "inverse_company_rate": 800, 

30 "currency_id": cls.eur_currency.id, 

31 "company_id": cls.company.id, 

32 }, 

33 { 

34 "name": (cls.today - timedelta(days=10)).strftime("%Y-%m-%d"), 

35 "inverse_company_rate": 1000, 

36 "currency_id": cls.eur_currency.id, 

37 "company_id": cls.company.id, 

38 }, 

39 ] 

40 ) 

41 cls.partner_ri = cls.env["res.partner"].create(dict(name="RI Partner", vat="34278580484", country_id=ar.id)) 

42 

43 def test_create_payment_with_a_date_rate_then_change_rate(self): 

44 invoice = self.env["account.move"].create( 

45 { 

46 "partner_id": self.partner_ri.id, 

47 "invoice_date": self.today - timedelta(days=14), 

48 "move_type": "out_invoice", 

49 "journal_id": self.company_journal.id, 

50 "company_id": self.company.id, 

51 "currency_id": self.eur_currency.id, 

52 "invoice_line_ids": [ 

53 Command.create( 

54 { 

55 "product_id": self.env.ref("product.product_product_16").id, 

56 "quantity": 1, 

57 "price_unit": 100, 

58 } 

59 ), 

60 ], 

61 } 

62 ) 

63 invoice.action_post() 

64 

65 vals = { 

66 "journal_id": self.company_bank_journal.id, 

67 "amount": invoice.amount_total, 

68 "currency_id": self.eur_currency.id, 

69 "date": self.today - timedelta(days=1), 

70 } 

71 action_context = invoice.action_register_payment()["context"] 

72 payment = self.env["account.payment"].with_context(**action_context).create(vals) 

73 payment.action_post() 

74 eur_actual_rate_1 = 1 / invoice.currency_id._get_rates(self.company, self.today).get(self.eur_currency.id) 

75 

76 self.assertEqual(payment.exchange_rate, eur_actual_rate_1, "no se tomo de forma correcta el tipo de cambio") 

77 self.rates[1].inverse_company_rate = 2000 

78 eur_actual_rate_2 = 1 / invoice.currency_id._get_rates(self.company, self.today).get(self.eur_currency.id) 

79 self.assertNotEqual( 

80 payment.exchange_rate, 

81 eur_actual_rate_2, 

82 "Se tomo de forma incorrecta el tipo de cambio en un pago ya posteado", 

83 ) 

84 self.assertEqual(payment.exchange_rate, eur_actual_rate_1, "no se tomo de forma correcta el tipo de cambio") 

85 

86 payment.action_draft() 

87 payment.date = self.today 

88 payment._compute_amount_company_currency() 

89 payment.action_post() 

90 self.assertEqual(payment.exchange_rate, eur_actual_rate_2, "no se tomo de forma correcta el tipo de cambio")