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.

68 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
  3. # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
  4. from odoo.tests.common import TransactionCase
  5. class TestContractShowInvoice(TransactionCase):
  6. def setUp(self):
  7. super(TestContractShowInvoice, self).setUp()
  8. self.analytic_account = self.env['account.analytic.account'].create({
  9. 'name': 'Test contract show invoice',
  10. })
  11. self.invoice = self.env['account.invoice'].create(
  12. {'partner_id': self.env.ref('base.res_partner_2').id,
  13. 'type': 'out_invoice',
  14. })
  15. self.invoice.journal_id.update_posted = True
  16. self.invoice._onchange_partner_id()
  17. self.a_sale = self.env['account.account'].search([
  18. ('user_type_id', '=',
  19. self.env.ref('account.data_account_type_revenue').id)
  20. ], limit=1)
  21. self.invoice_line = self.env['account.invoice.line'].create(
  22. {'product_id': self.env.ref('product.product_product_2').id,
  23. 'quantity': 1.0,
  24. 'invoice_id': self.invoice.id,
  25. 'account_analytic_id': self.analytic_account.id,
  26. 'account_id': self.a_sale.id,
  27. 'price_unit': 50.0,
  28. 'name': 'Invoice line with analytic account',
  29. 'invoice_line_tax_ids': [(4, self.env['account.tax'].search(
  30. [('type_tax_use', '=', 'sale')], limit=1).id, 0)]
  31. })
  32. self.invoice.compute_taxes()
  33. self.invoice.action_invoice_open()
  34. def test_invoice_two_line(self):
  35. self.assertEqual(
  36. self.analytic_account.total_invoiced,
  37. self.invoice_line.price_subtotal,
  38. msg="Amount invoiced is different from single invoice line wich "
  39. "has analytic account")
  40. self.invoice.action_invoice_cancel()
  41. self.invoice.action_invoice_draft()
  42. self.invoice_line1 = self.env['account.invoice.line'].create(
  43. {'product_id': self.env.ref('product.product_product_2').id,
  44. 'quantity': 2.0,
  45. 'invoice_id': self.invoice.id,
  46. 'account_analytic_id': False,
  47. 'account_id': self.a_sale.id,
  48. 'price_unit': 100.0,
  49. 'name': 'Invoice line without analytic account',
  50. 'invoice_line_tax_ids': [(4, self.env['account.tax'].search(
  51. [('type_tax_use', '=', 'sale')], limit=1).id, 0)]
  52. })
  53. self.invoice.compute_taxes()
  54. self.invoice.action_invoice_open()
  55. self.assertFalse(self.invoice_line1.account_analytic_id,
  56. msg="Invoice line has analytic account")
  57. self.assertEqual(len(self.invoice.analytic_account_ids), 1,
  58. msg="Invoice lines with analytic account are more "
  59. "than one")
  60. self.assertEqual(
  61. self.analytic_account.total_invoiced,
  62. self.invoice_line.price_subtotal,
  63. msg="Amount invoiced is different from invoice lines wich "
  64. "has analytic account")