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.

80 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests import common
  5. class TestContractMandate(common.SavepointCase):
  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 = cls.env['account.analytic.account'].create({
  44. 'name': 'Test contract',
  45. 'partner_id': cls.partner.id,
  46. 'recurring_invoices': True,
  47. 'recurring_interval': 1,
  48. 'recurring_invoice_line_ids': [(0, 0, {
  49. 'quantity': 2.0,
  50. 'price_unit': 200.0,
  51. 'name': 'Test contract line',
  52. 'product_id': cls.product.id,
  53. 'uom_id': cls.product.uom_id.id,
  54. })],
  55. 'payment_mode_id': cls.payment_mode.id,
  56. 'mandate_id': cls.mandate.id,
  57. })
  58. def test_contract_mandate(self):
  59. new_invoice = self.contract.recurring_create_invoice()
  60. self.assertEqual(new_invoice.mandate_id, self.mandate)
  61. def test_contract_not_mandate(self):
  62. self.contract.mandate_id = False
  63. self.mandate2 = self.mandate.copy({
  64. 'unique_mandate_reference': 'BM0000XX2',
  65. })
  66. self.mandate2.validate()
  67. self.mandate.state = 'expired'
  68. new_invoice = self.contract.recurring_create_invoice()
  69. self.assertEqual(new_invoice.mandate_id, self.mandate2)
  70. def test_contract_mandate_default(self):
  71. self.payment_mode.mandate_required = False
  72. self.contract.mandate_id = False
  73. new_invoice = self.contract.recurring_create_invoice()
  74. self.assertFalse(new_invoice.mandate_id)