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.

92 lines
3.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # Copyright 2017 Tecnativa - Vicent Cubells
  4. # Copyright 2017 Tecnativa - David Vidal
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. import odoo.tests
  7. from ..hooks import post_init_hook
  8. @odoo.tests.post_install(True)
  9. @odoo.tests.at_install(False)
  10. class TestContractPaymentInit(odoo.tests.HttpCase):
  11. def setUp(self):
  12. super(TestContractPaymentInit, self).setUp()
  13. self.payment_method = self.env['account.payment.method'].create({
  14. 'name': 'Test Payment Method',
  15. 'code': 'Test',
  16. 'payment_type': 'inbound',
  17. })
  18. self.payment_mode = self.env['account.payment.mode'].create({
  19. 'name': 'Test payment mode',
  20. 'active': True,
  21. 'payment_method_id': self.payment_method.id,
  22. 'bank_account_link': 'variable',
  23. })
  24. self.partner = self.env['res.partner'].create({
  25. 'name': 'Test contract partner',
  26. 'customer_payment_mode_id': self.payment_mode,
  27. })
  28. self.product = self.env['product.product'].create({
  29. 'name': 'Custom Service',
  30. 'type': 'service',
  31. 'uom_id': self.env.ref('product.product_uom_hour').id,
  32. 'uom_po_id': self.env.ref('product.product_uom_hour').id,
  33. 'sale_ok': True,
  34. })
  35. self.contract = self.env['account.analytic.account'].create({
  36. 'name': 'Maintenance of Servers',
  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['account.analytic.account'].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. 'recurring_invoices': True,
  64. 'recurring_interval': 1,
  65. 'recurring_invoice_line_ids': [(0, 0, {
  66. 'quantity': 2.0,
  67. 'price_unit': 200.0,
  68. 'name': 'Database Administration 25',
  69. 'product_id': self.product.id,
  70. 'uom_id': self.product.uom_id.id,
  71. })]
  72. })
  73. self.contract.recurring_create_invoice()
  74. new_invoice = self.env['account.invoice'].search([
  75. ('contract_id', '=', self.contract.id)
  76. ])
  77. self.assertEqual(new_invoice.partner_id, self.contract.partner_id)
  78. self.assertEqual(new_invoice.payment_mode_id,
  79. self.contract.payment_mode_id)
  80. self.assertEqual(len(new_invoice.ids), 1)
  81. self.contract.recurring_create_invoice()
  82. self.assertEqual(self.contract.payment_mode_id,
  83. new_invoice.payment_mode_id)