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.

90 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. from odoo.tests import common
  7. from ..hooks import post_init_hook
  8. class TestContractPaymentInit(common.SavepointCase):
  9. @classmethod
  10. def setUpClass(cls):
  11. super(TestContractPaymentInit, cls).setUpClass()
  12. cls.payment_method = cls.env['account.payment.method'].create({
  13. 'name': 'Test Payment Method',
  14. 'code': 'Test',
  15. 'payment_type': 'inbound',
  16. })
  17. cls.payment_mode = cls.env['account.payment.mode'].create({
  18. 'name': 'Test payment mode',
  19. 'active': True,
  20. 'payment_method_id': cls.payment_method.id,
  21. 'bank_account_link': 'variable',
  22. })
  23. cls.partner = cls.env['res.partner'].create({
  24. 'name': 'Test contract partner',
  25. 'customer_payment_mode_id': cls.payment_mode,
  26. })
  27. cls.product = cls.env['product.product'].create({
  28. 'name': 'Custom Service',
  29. 'type': 'service',
  30. 'uom_id': cls.env.ref('product.product_uom_hour').id,
  31. 'uom_po_id': cls.env.ref('product.product_uom_hour').id,
  32. 'sale_ok': True,
  33. })
  34. cls.contract = cls.env['account.analytic.account'].create({
  35. 'name': 'Maintenance of Servers',
  36. })
  37. company = cls.env.ref('base.main_company')
  38. cls.journal = cls.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)