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.

64 lines
2.3 KiB

  1. from odoo import fields
  2. from odoo.exceptions import ValidationError
  3. from odoo.tests.common import TransactionCase
  4. class TestPos(TransactionCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy({
  8. 'name': 'Block PoS Session with Stock Error',
  9. 'allow_session_closing_with_stock_errors': False,
  10. })
  11. self.product_tracking = self.env.ref(
  12. 'point_of_sale.desk_organizer'
  13. ).copy({
  14. 'name': 'Product with Tracking',
  15. 'tracking': 'serial',
  16. })
  17. def test_session_closing_with_errors(self):
  18. pos_session = self.env['pos.session'].create({
  19. 'config_id': self.pos_config.id,
  20. })
  21. # We create an order that will generate errors
  22. # (the product requires a serial number)
  23. pos_order = self.env['pos.order'].create({
  24. 'session_id': pos_session.id,
  25. 'lines': [(0, 0, {
  26. 'name': 'OL/0001',
  27. 'product_id': self.product_tracking.id,
  28. 'tax_ids': False,
  29. 'qty': 1.0,
  30. 'price_unit': 1000,
  31. 'price_subtotal': 1000,
  32. 'price_subtotal_incl': 1000,
  33. })],
  34. 'amount_total': 1000.0,
  35. 'amount_tax': 0.0,
  36. 'amount_paid': 1000.0,
  37. 'amount_return': 0.0,
  38. })
  39. # Register order payment
  40. pos_order.add_payment({
  41. 'amount': 1000,
  42. 'payment_date': fields.Datetime.now(),
  43. 'statement_id': pos_session.statement_ids[0].id,
  44. 'payment_name': 'PAY',
  45. 'journal': pos_session.statement_ids[0].journal_id.id,
  46. })
  47. # Set ending balance in statement
  48. pos_session.statement_ids[0].write({
  49. 'balance_end_real': pos_session.statement_ids[0].balance_end
  50. })
  51. pos_order.action_pos_order_paid()
  52. # Blocked because we have errors
  53. with self.assertRaises(ValidationError):
  54. pos_session.action_pos_session_close()
  55. # Enable closing with errors
  56. self.pos_config.write({
  57. 'allow_session_closing_with_stock_errors': True,
  58. })
  59. # Should be possible to close now
  60. pos_session.action_pos_session_close()