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.

47 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
  3. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  4. import openerp.tests.common as common
  5. class TestContractRecurringPlans(common.TransactionCase):
  6. def setUp(self):
  7. super(TestContractRecurringPlans, self).setUp()
  8. self.partner = self.env['res.partner'].create({'name': 'Test'})
  9. self.product = self.env.ref('product.product_product_consultant')
  10. self.uom = self.env.ref('product.product_uom_hour')
  11. self.contract = self.env['account.analytic.account'].create({
  12. 'name': 'Test contract',
  13. 'partner_id': self.partner.id,
  14. 'type': 'contract',
  15. 'recurring_invoices': 1,
  16. 'recurring_interval': 1,
  17. 'recurring_invoice_line_ids': [
  18. (0, 0, {'quantity': 2.0,
  19. 'price_unit': 100.0,
  20. 'name': 'Test',
  21. 'product_id': self.product.id,
  22. 'uom_id': self.uom.id})],
  23. })
  24. plan = self.env['account.analytic.plan'].create({'name': 'Test'})
  25. self.analytics = self.env['account.analytic.plan.instance'].create(
  26. {'plan_id': plan.id})
  27. def test_invoice_without_plans(self):
  28. self.contract.recurring_create_invoice()
  29. invoice = self.env['account.invoice'].search(
  30. [('partner_id', '=', self.partner.id)])
  31. self.assertEqual(
  32. invoice.invoice_line[0].account_analytic_id, self.contract)
  33. def test_invoice_with_plans(self):
  34. self.contract.recurring_invoice_line_ids.analytics_id = (
  35. self.analytics.id)
  36. self.contract.recurring_create_invoice()
  37. invoice = self.env['account.invoice'].search(
  38. [('partner_id', '=', self.partner.id)])
  39. self.assertFalse(invoice.invoice_line[0].account_analytic_id)
  40. self.assertEqual(
  41. invoice.invoice_line[0].analytics_id, self.analytics)