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.

80 lines
2.9 KiB

  1. # Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import fields
  5. from odoo.tests.common import TransactionCase
  6. class TestModule(TransactionCase):
  7. def setUp(self):
  8. super(TestModule, self).setUp()
  9. # Get Registry
  10. self.PosOrder = self.env['pos.order']
  11. self.AccountPayment = self.env['account.payment']
  12. # Get Object
  13. self.pos_product = self.env.ref('point_of_sale.limon')
  14. self.pricelist = self.env.ref('product.list0')
  15. self.partner = self.env.ref('base.res_partner_12')
  16. # Create a new pos config and open it
  17. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
  18. self.pos_config.open_session_cb()
  19. # Test Section
  20. def test_load_order(self):
  21. order = self._create_order()
  22. orders_data = self.PosOrder.search_done_orders_for_pos(
  23. [], self.pos_config.current_session_id.id)
  24. self.assertEqual(len(orders_data), 1)
  25. self.assertEqual(
  26. orders_data[0]['id'], order.id)
  27. detail_data = order.load_done_order_for_pos()
  28. self.assertEqual(
  29. len(detail_data.get('line_ids', [])), 1,
  30. "Loading order detail failed")
  31. def _create_order(self):
  32. # Create order
  33. order_data = {
  34. 'id': u'0006-001-0010',
  35. 'to_invoice': True,
  36. 'data': {
  37. 'pricelist_id': self.pricelist.id,
  38. 'user_id': 1,
  39. 'name': 'Order 0006-001-0010',
  40. 'partner_id': self.partner.id,
  41. 'amount_paid': 0.9,
  42. 'pos_session_id': self.pos_config.current_session_id.id,
  43. 'lines': [[0, 0, {
  44. 'product_id': self.pos_product.id,
  45. 'price_unit': 0.9,
  46. 'qty': 1,
  47. 'price_subtotal': 0.9,
  48. 'price_subtotal_incl': 0.9,
  49. }]],
  50. 'statement_ids': [[0, 0, {
  51. 'journal_id': self.pos_config.journal_ids[0].id,
  52. 'amount': 0.9,
  53. 'name': fields.Datetime.now(),
  54. 'account_id':
  55. self.env.user.partner_id.property_account_receivable_id.id,
  56. 'statement_id':
  57. self.pos_config.current_session_id.statement_ids[0].id,
  58. }]],
  59. 'creation_date': u'2018-09-27 15:51:03',
  60. 'amount_tax': 0,
  61. 'fiscal_position_id': False,
  62. 'uid': u'00001-001-0001',
  63. 'amount_return': 0,
  64. 'sequence_number': 1,
  65. 'amount_total': 0.9,
  66. }}
  67. result = self.PosOrder.create_from_ui([order_data])
  68. order = self.PosOrder.browse(result[0])
  69. return order