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.

100 lines
3.9 KiB

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