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.

83 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # Copyright 2017 Tecnativa - Vicent Cubells
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp.tests import common
  6. from ..hooks import post_init_hook
  7. class TestContractPaymentInit(common.SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestContractPaymentInit, cls).setUpClass()
  11. cls.payment_method = cls.env.ref(
  12. 'account.account_payment_method_manual_in')
  13. cls.payment_mode = cls.env.ref(
  14. 'account_payment_mode.payment_mode_inbound_ct1')
  15. cls.partner = cls.env['res.partner'].create({
  16. 'name': 'Test contract partner',
  17. 'customer_payment_mode_id': cls.payment_mode,
  18. })
  19. cls.product = cls.env['product.product'].create({
  20. 'name': 'Custom Service',
  21. 'type': 'service',
  22. 'uom_id': cls.env.ref('product.product_uom_hour').id,
  23. 'uom_po_id': cls.env.ref('product.product_uom_hour').id,
  24. 'sale_ok': True,
  25. })
  26. cls.contract = cls.env['account.analytic.account'].create({
  27. 'name': 'Maintenance of Servers',
  28. })
  29. def _contract_payment_mode_id(self, contract_id):
  30. contract = self.env['account.analytic.account'].search([
  31. ('id', '=', contract_id),
  32. ])
  33. return contract.payment_mode_id.id
  34. def test_post_init_hook(self):
  35. contract = self.env['account.analytic.account'].create({
  36. 'name': 'Test contract',
  37. 'partner_id': self.partner.id,
  38. 'payment_mode_id': self.payment_mode.id,
  39. })
  40. self.assertEqual(self._contract_payment_mode_id(contract.id),
  41. self.payment_mode.id)
  42. contract.payment_mode_id = False
  43. self.assertEqual(self._contract_payment_mode_id(contract.id), False)
  44. post_init_hook(self.cr, self.env)
  45. self.assertEqual(self._contract_payment_mode_id(contract.id),
  46. self.payment_mode.id)
  47. def test_contract_and_invoices(self):
  48. self.contract.write({'partner_id': self.partner.id})
  49. self.contract.on_change_partner_id()
  50. self.assertEqual(self.contract.payment_mode_id,
  51. self.contract.partner_id.customer_payment_mode_id)
  52. self.contract.write({
  53. 'recurring_invoices': True,
  54. 'recurring_interval': 1,
  55. 'recurring_invoice_line_ids': [(0, 0, {
  56. 'quantity': 2.0,
  57. 'price_unit': 200.0,
  58. 'name': 'Database Administration 25',
  59. 'product_id': self.product.id,
  60. 'uom_id': self.product.uom_id.id,
  61. })]
  62. })
  63. res = self.contract._prepare_invoice_data(self.contract)
  64. self.assertEqual(res.get('partner_id'), self.contract.partner_id.id)
  65. self.assertEqual(res.get('payment_mode_id'),
  66. self.contract.payment_mode_id.id)
  67. self.contract.recurring_create_invoice()
  68. new_invoice = self.env['account.invoice'].search([
  69. ('contract_id', '=', self.contract.id)
  70. ])
  71. self.assertEqual(len(new_invoice.ids), 1)
  72. self.contract.recurring_create_invoice()
  73. self.assertEqual(self.contract.payment_mode_id,
  74. new_invoice.payment_mode_id)