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 odoo.tests.common as common
  6. @common.at_install(False)
  7. @common.post_install(True)
  8. class TestContractRecurringDistribution(common.HttpCase):
  9. def setUp(self):
  10. super(TestContractRecurringDistribution, self).setUp()
  11. self.partner = self.env['res.partner'].create({'name': 'Test'})
  12. self.product = self.env['product.product'].create({
  13. 'name': 'Test product',
  14. })
  15. self.account1 = self.env['account.analytic.account'].create({
  16. 'name': 'Test account #1',
  17. })
  18. self.account2 = self.env['account.analytic.account'].create({
  19. 'name': 'Test account #2',
  20. })
  21. self.uom = self.env.ref('product.product_uom_hour')
  22. self.contract = self.env['account.analytic.account'].create({
  23. 'name': 'Test contract',
  24. 'partner_id': self.partner.id,
  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': self.product.id,
  32. 'uom_id': self.uom.id})],
  33. })
  34. self.distribution = self.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': self.account1.id,
  41. }),
  42. (0, 0, {
  43. 'sequence': 20,
  44. 'percent': 25.00,
  45. 'analytic_account_id': self.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)