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.

91 lines
3.5 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('product.product_uom_hour').id,
  31. 'uom_po_id': self.env.ref('product.product_uom_hour').id,
  32. 'sale_ok': True,
  33. })
  34. self.contract = self.env['account.analytic.account'].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['account.analytic.account'].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. 'recurring_invoices': True,
  63. 'recurring_interval': 1,
  64. 'recurring_invoice_line_ids': [(0, 0, {
  65. 'quantity': 2.0,
  66. 'price_unit': 200.0,
  67. 'name': 'Database Administration 25',
  68. 'product_id': self.product.id,
  69. 'uom_id': self.product.uom_id.id,
  70. })]
  71. })
  72. self.contract.recurring_create_invoice()
  73. new_invoice = self.env['account.invoice'].search([
  74. ('contract_id', '=', self.contract.id)
  75. ])
  76. self.assertEqual(new_invoice.partner_id, self.contract.partner_id)
  77. self.assertEqual(new_invoice.payment_mode_id,
  78. self.contract.payment_mode_id)
  79. self.assertEqual(len(new_invoice.ids), 1)
  80. self.contract.recurring_create_invoice()
  81. self.assertEqual(self.contract.payment_mode_id,
  82. new_invoice.payment_mode_id)