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.

86 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Creu Blanca <https://creublanca.es/>
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo.tests import common
  5. class TestSessionPayInvoice(common.TransactionCase):
  6. def setUp(self):
  7. super(TestSessionPayInvoice, self).setUp()
  8. self.company = self.env.ref('base.main_company')
  9. partner = self.env.ref('base.partner_demo')
  10. self.invoice_out = self.env['account.invoice'].create({
  11. 'company_id': self.company.id,
  12. 'partner_id': partner.id,
  13. 'date_invoice': '2016-03-12',
  14. 'type': 'out_invoice',
  15. })
  16. account = self.env['account.account'].create({
  17. 'code': 'test_cash_pay_invoice',
  18. 'company_id': self.company.id,
  19. 'name': 'Test',
  20. 'user_type_id': self.env.ref(
  21. 'account.data_account_type_revenue').id
  22. })
  23. self.env['account.invoice.line'].create({
  24. 'product_id': self.env.ref('product.product_delivery_02').id,
  25. 'invoice_id': self.invoice_out.id,
  26. 'account_id': account.id,
  27. 'name': 'Producto de prueba',
  28. 'quantity': 1.0,
  29. 'price_unit': 100.0,
  30. })
  31. self.invoice_out._onchange_invoice_line_ids()
  32. self.invoice_out.action_invoice_open()
  33. self.invoice_out.number = '2999/99999'
  34. self.invoice_in = self.env['account.invoice'].create({
  35. 'partner_id': partner.id,
  36. 'company_id': self.company.id,
  37. 'type': 'in_invoice',
  38. 'date_invoice': '2016-03-12',
  39. })
  40. self.env['account.invoice.line'].create({
  41. 'product_id': self.env.ref('product.product_delivery_02').id,
  42. 'invoice_id': self.invoice_in.id,
  43. 'name': 'Producto de prueba',
  44. 'account_id': account.id,
  45. 'quantity': 1.0,
  46. 'price_unit': 100.0,
  47. })
  48. self.invoice_in._onchange_invoice_line_ids()
  49. self.invoice_in.action_invoice_open()
  50. self.invoice_in.number = '2999/99999'
  51. self.config = self.env.ref('point_of_sale.pos_config_main')
  52. self.config.cash_control = True
  53. def test_pos_invoice(self):
  54. self.config.open_session_cb()
  55. session = self.config.current_session_id
  56. self.assertIsNotNone(session.statement_ids)
  57. session.action_pos_session_open()
  58. in_invoice = self.env['cash.invoice.in'].with_context(
  59. active_ids=session.ids, active_model='pos.session'
  60. ).create({
  61. 'invoice_id': self.invoice_in.id,
  62. 'amount': 100.0
  63. })
  64. in_invoice.run()
  65. out_invoice = self.env['cash.invoice.out'].with_context(
  66. active_ids=session.ids, active_model='pos.session'
  67. ).create({
  68. 'invoice_id': self.invoice_out.id,
  69. 'amount': 75.0
  70. })
  71. out_invoice.run()
  72. box = self.env['cash.box.in'].with_context(
  73. active_ids=session.ids, active_model='pos.session'
  74. ).create({
  75. 'name': "Testing",
  76. 'amount': 25.0
  77. })
  78. box.run()
  79. session.action_pos_session_closing_control()
  80. session.action_pos_session_closing_control()
  81. self.assertEqual(self.invoice_out.residual, 25.)
  82. self.assertEqual(self.invoice_in.residual, 0.)