You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.4 KiB

  1. # Copyright 2017 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.addons.contract.tests.test_contract import TestContractBase
  4. class TestContractMandate(TestContractBase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super(TestContractMandate, cls).setUpClass()
  8. cls.payment_method = cls.env['account.payment.method'].create({
  9. 'name': 'Test SDD',
  10. 'code': 'test_code_sdd',
  11. 'payment_type': 'inbound',
  12. 'mandate_required': True,
  13. })
  14. cls.payment_mode = cls.env['account.payment.mode'].create({
  15. 'name': 'Test payment mode',
  16. 'bank_account_link': 'variable',
  17. 'payment_method_id': cls.payment_method.id,
  18. })
  19. cls.partner = cls.env['res.partner'].create({
  20. 'customer': True,
  21. 'name': 'Test Customer',
  22. 'customer_payment_mode_id': cls.payment_mode.id,
  23. })
  24. cls.partner_bank = cls.env['res.partner.bank'].create({
  25. 'acc_number': '1234',
  26. 'partner_id': cls.partner.id,
  27. })
  28. cls.mandate = cls.env['account.banking.mandate'].create({
  29. 'partner_id': cls.partner.id,
  30. 'partner_bank_id': cls.partner_bank.id,
  31. 'signature_date': '2017-01-01',
  32. })
  33. cls.contract_with_mandate = cls.contract2.copy(
  34. {
  35. 'partner_id': cls.partner.id,
  36. 'payment_mode_id': cls.payment_mode.id,
  37. 'mandate_id': cls.mandate.id,
  38. }
  39. )
  40. def test_contract_mandate(self):
  41. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  42. self.assertEqual(new_invoice.mandate_id, self.mandate)
  43. def test_contract_not_mandate(self):
  44. self.contract_with_mandate.mandate_id = False
  45. self.mandate2 = self.mandate.copy(
  46. {'unique_mandate_reference': 'BM0000XX2'}
  47. )
  48. self.mandate2.validate()
  49. self.mandate.state = 'expired'
  50. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  51. self.assertEqual(new_invoice.mandate_id, self.mandate2)
  52. def test_contract_mandate_default(self):
  53. self.payment_mode.mandate_required = False
  54. self.contract_with_mandate.mandate_id = False
  55. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  56. self.assertFalse(new_invoice.mandate_id)