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.

72 lines
2.8 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.tests import common
  4. from odoo.addons.contract.tests.test_contract import TestContractBase
  5. class TestContractMandate(TestContractBase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestContractMandate, cls).setUpClass()
  9. cls.payment_method = cls.env['account.payment.method'].create({
  10. 'name': 'Test SDD',
  11. 'code': 'test_code_sdd',
  12. 'payment_type': 'inbound',
  13. 'mandate_required': True,
  14. })
  15. cls.payment_mode = cls.env['account.payment.mode'].create({
  16. 'name': 'Test payment mode',
  17. 'bank_account_link': 'variable',
  18. 'payment_method_id': cls.payment_method.id,
  19. })
  20. cls.partner = cls.env['res.partner'].create({
  21. 'customer': True,
  22. 'name': 'Test Customer',
  23. 'customer_payment_mode_id': cls.payment_mode.id,
  24. })
  25. cls.partner_bank = cls.env['res.partner.bank'].create({
  26. 'acc_number': '1234',
  27. 'partner_id': cls.partner.id,
  28. })
  29. cls.mandate = cls.env['account.banking.mandate'].create({
  30. 'partner_id': cls.partner.id,
  31. 'partner_bank_id': cls.partner_bank.id,
  32. 'signature_date': '2017-01-01',
  33. })
  34. cls.uom = cls.env.ref('product.product_uom_hour')
  35. cls.product = cls.env['product.product'].create({
  36. 'name': 'Custom Service',
  37. 'type': 'service',
  38. 'uom_id': cls.uom.id,
  39. 'uom_po_id': cls.uom.id,
  40. 'sale_ok': True,
  41. 'taxes_id': [(6, 0, [])],
  42. })
  43. cls.contract_with_mandate = cls.contract2.copy(
  44. {
  45. 'partner_id': cls.partner.id,
  46. 'payment_mode_id': cls.payment_mode.id,
  47. 'mandate_id': cls.mandate.id,
  48. }
  49. )
  50. def test_contract_mandate(self):
  51. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  52. self.assertEqual(new_invoice.mandate_id, self.mandate)
  53. def test_contract_not_mandate(self):
  54. self.contract_with_mandate.mandate_id = False
  55. self.mandate2 = self.mandate.copy(
  56. {'unique_mandate_reference': 'BM0000XX2'}
  57. )
  58. self.mandate2.validate()
  59. self.mandate.state = 'expired'
  60. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  61. self.assertEqual(new_invoice.mandate_id, self.mandate2)
  62. def test_contract_mandate_default(self):
  63. self.payment_mode.mandate_required = False
  64. self.contract_with_mandate.mandate_id = False
  65. new_invoice = self.contract_with_mandate.recurring_create_invoice()
  66. self.assertFalse(new_invoice.mandate_id)