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.

69 lines
2.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Tecnativa - Pedro M. Baeza
  3. # Copyright 2017 Tecnativa - Vicent Cubells
  4. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  5. import openerp.tests.common as common
  6. class TestContractRecurringDistribution(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestContractRecurringDistribution, cls).setUpClass()
  10. cls.partner = cls.env['res.partner'].create({'name': 'Test'})
  11. cls.product = cls.env['product.product'].create({
  12. 'name': 'Test product',
  13. })
  14. cls.account1 = cls.env['account.analytic.account'].create({
  15. 'name': 'Test account #1',
  16. })
  17. cls.account2 = cls.env['account.analytic.account'].create({
  18. 'name': 'Test account #2',
  19. })
  20. cls.uom = cls.env.ref('product.product_uom_hour')
  21. cls.contract = cls.env['account.analytic.account'].create({
  22. 'name': 'Test contract',
  23. 'partner_id': cls.partner.id,
  24. 'type': 'contract',
  25. 'recurring_invoices': 1,
  26. 'recurring_interval': 1,
  27. 'recurring_invoice_line_ids': [
  28. (0, 0, {'quantity': 2.0,
  29. 'price_unit': 100.0,
  30. 'name': 'Test',
  31. 'product_id': cls.product.id,
  32. 'uom_id': cls.uom.id})],
  33. })
  34. cls.distribution = cls.env['account.analytic.distribution'].create({
  35. 'name': 'Test distribution',
  36. 'rule_ids': [
  37. (0, 0, {
  38. 'sequence': 10,
  39. 'percent': 75.00,
  40. 'analytic_account_id': cls.account1.id,
  41. }),
  42. (0, 0, {
  43. 'sequence': 20,
  44. 'percent': 25.00,
  45. 'analytic_account_id': cls.account2.id,
  46. }),
  47. ]
  48. })
  49. def test_invoice_without_distribution(self):
  50. self.contract.recurring_create_invoice()
  51. invoice = self.env['account.invoice'].search(
  52. [('partner_id', '=', self.partner.id)])
  53. self.assertEqual(
  54. invoice.invoice_line_ids[0].account_analytic_id, self.contract)
  55. def test_invoice_with_distribution(self):
  56. self.contract.recurring_invoice_line_ids.analytic_distribution_id = (
  57. self.distribution.id)
  58. self.contract.recurring_create_invoice()
  59. invoice = self.env['account.invoice'].search(
  60. [('partner_id', '=', self.partner.id)])
  61. self.assertFalse(invoice.invoice_line_ids[0].account_analytic_id)
  62. self.assertEqual(
  63. invoice.invoice_line_ids[0].analytic_distribution_id,
  64. self.distribution)