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.

93 lines
3.6 KiB

  1. # Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  2. # Copyright 2017 Tecnativa - Vicent Cubells
  3. # Copyright 2017 Tecnativa - David Vidal
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. import odoo.tests
  6. from ..hooks import post_init_hook
  7. @odoo.tests.post_install(True)
  8. @odoo.tests.at_install(False)
  9. class TestContractPaymentInit(odoo.tests.HttpCase):
  10. def setUp(self):
  11. super(TestContractPaymentInit, self).setUp()
  12. self.payment_method = self.env['account.payment.method'].create({
  13. 'name': 'Test Payment Method',
  14. 'code': 'Test',
  15. 'payment_type': 'inbound',
  16. })
  17. self.payment_mode = self.env['account.payment.mode'].create({
  18. 'name': 'Test payment mode',
  19. 'active': True,
  20. 'payment_method_id': self.payment_method.id,
  21. 'bank_account_link': 'variable',
  22. })
  23. self.partner = self.env['res.partner'].create({
  24. 'name': 'Test contract partner',
  25. 'customer_payment_mode_id': self.payment_mode,
  26. })
  27. self.product = self.env['product.product'].create({
  28. 'name': 'Custom Service',
  29. 'type': 'service',
  30. 'uom_id': self.env.ref('uom.product_uom_hour').id,
  31. 'uom_po_id': self.env.ref('uom.product_uom_hour').id,
  32. 'sale_ok': True,
  33. })
  34. self.contract = self.env['contract.contract'].create({
  35. 'name': 'Maintenance of Servers',
  36. })
  37. company = self.env.ref('base.main_company')
  38. self.journal = self.env['account.journal'].create({
  39. 'name': 'Sale Journal - Test',
  40. 'code': 'HRTSJ',
  41. 'type': 'sale',
  42. 'company_id': company.id})
  43. def test_post_init_hook(self):
  44. contract = self.env['contract.contract'].create({
  45. 'name': 'Test contract',
  46. 'partner_id': self.partner.id,
  47. 'payment_mode_id': self.payment_mode.id,
  48. })
  49. self.assertEqual(contract.payment_mode_id,
  50. self.payment_mode)
  51. contract.payment_mode_id = False
  52. self.assertEqual(contract.payment_mode_id.id, False)
  53. post_init_hook(self.cr, self.env)
  54. self.assertEqual(contract.payment_mode_id,
  55. self.payment_mode)
  56. def test_contract_and_invoices(self):
  57. self.contract.write({'partner_id': self.partner.id})
  58. self.contract.on_change_partner_id()
  59. self.assertEqual(self.contract.payment_mode_id,
  60. self.contract.partner_id.customer_payment_mode_id)
  61. self.contract.write({
  62. 'contract_line_ids': [(0, 0, {
  63. 'product_id': self.product.id,
  64. 'name': 'Database Administration 25',
  65. 'quantity': 2.0,
  66. 'uom_id': self.product.uom_id.id,
  67. 'price_unit': 200.0,
  68. 'recurring_rule_type': 'monthly',
  69. 'recurring_interval': 1,
  70. 'date_start': '2018-01-01',
  71. 'recurring_next_date': '2018-01-15',
  72. 'is_auto_renew': False,
  73. })]
  74. })
  75. self.contract.recurring_create_invoice()
  76. new_invoice = self.contract._get_related_invoices()
  77. self.assertTrue(new_invoice)
  78. self.assertEqual(new_invoice.partner_id, self.contract.partner_id)
  79. self.assertEqual(new_invoice.payment_mode_id,
  80. self.contract.payment_mode_id)
  81. self.assertEqual(len(new_invoice.ids), 1)
  82. self.contract.recurring_create_invoice()
  83. self.assertEqual(self.contract.payment_mode_id,
  84. new_invoice.payment_mode_id)