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.

101 lines
3.9 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. self.account_cash_differences_id = self.env['account.account'].create({
  54. 'code': 'test_cash_differences',
  55. 'company_id': self.company.id,
  56. 'name': 'Test Cash Differences',
  57. 'user_type_id': self.env.ref(
  58. 'account.data_account_type_revenue').id
  59. })
  60. def test_pos_invoice(self):
  61. self.config.open_session_cb()
  62. session = self.config.current_session_id
  63. self.assertIsNotNone(session.statement_ids)
  64. cash_statements = session.statement_ids.filtered(
  65. lambda x: x.journal_id.type == 'cash')
  66. self.assertEquals(len(cash_statements), 1)
  67. journal = cash_statements[0].journal_id
  68. journal.profit_account_id = self.account_cash_differences_id
  69. journal.loss_account_id = self.account_cash_differences_id
  70. session.action_pos_session_open()
  71. in_invoice = self.env['cash.invoice.in'].with_context(
  72. active_ids=session.ids, active_model='pos.session'
  73. ).create({
  74. 'invoice_id': self.invoice_in.id,
  75. 'amount': 100.0
  76. })
  77. in_invoice.run()
  78. out_invoice = self.env['cash.invoice.out'].with_context(
  79. active_ids=session.ids, active_model='pos.session'
  80. ).create({
  81. 'invoice_id': self.invoice_out.id,
  82. 'amount': 75.0
  83. })
  84. out_invoice.run()
  85. box = self.env['cash.box.in'].with_context(
  86. active_ids=session.ids, active_model='pos.session'
  87. ).create({
  88. 'name': "Testing",
  89. 'amount': 25.0
  90. })
  91. box.run()
  92. session.action_pos_session_closing_control()
  93. session.action_pos_session_validate()
  94. self.assertEqual(self.invoice_out.residual, 25.)
  95. self.assertEqual(self.invoice_in.residual, 0.)