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.

94 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. 'partner_id': self.partner.id,
  37. })
  38. company = self.env.ref('base.main_company')
  39. self.journal = self.env['account.journal'].create({
  40. 'name': 'Sale Journal - Test',
  41. 'code': 'HRTSJ',
  42. 'type': 'sale',
  43. 'company_id': company.id})
  44. def test_post_init_hook(self):
  45. contract = self.env['contract.contract'].create({
  46. 'name': 'Test contract',
  47. 'partner_id': self.partner.id,
  48. 'payment_mode_id': self.payment_mode.id,
  49. })
  50. self.assertEqual(contract.payment_mode_id,
  51. self.payment_mode)
  52. contract.payment_mode_id = False
  53. self.assertEqual(contract.payment_mode_id.id, False)
  54. post_init_hook(self.cr, self.env)
  55. self.assertEqual(contract.payment_mode_id,
  56. self.payment_mode)
  57. def test_contract_and_invoices(self):
  58. self.contract.write({'partner_id': self.partner.id})
  59. self.contract.on_change_partner_id()
  60. self.assertEqual(self.contract.payment_mode_id,
  61. self.contract.partner_id.customer_payment_mode_id)
  62. self.contract.write({
  63. 'contract_line_ids': [(0, 0, {
  64. 'product_id': self.product.id,
  65. 'name': 'Database Administration 25',
  66. 'quantity': 2.0,
  67. 'uom_id': self.product.uom_id.id,
  68. 'price_unit': 200.0,
  69. 'recurring_rule_type': 'monthly',
  70. 'recurring_interval': 1,
  71. 'date_start': '2018-01-01',
  72. 'recurring_next_date': '2018-01-15',
  73. 'is_auto_renew': False,
  74. })]
  75. })
  76. self.contract.recurring_create_invoice()
  77. new_invoice = self.contract._get_related_invoices()
  78. self.assertTrue(new_invoice)
  79. self.assertEqual(new_invoice.partner_id, self.contract.partner_id)
  80. self.assertEqual(new_invoice.payment_mode_id,
  81. self.contract.payment_mode_id)
  82. self.assertEqual(len(new_invoice.ids), 1)
  83. self.contract.recurring_create_invoice()
  84. self.assertEqual(self.contract.payment_mode_id,
  85. new_invoice.payment_mode_id)