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.

93 lines
3.3 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["product.product"].create({
  14. "name": "Test POS Product",
  15. })
  16. self.pricelist = self.env["product.pricelist"].create({
  17. "name": "Test pricelist",
  18. "currency_id": self.env.user.company_id.currency_id.id,
  19. "item_ids": [(0, 0, {
  20. "applied_on": "3_global",
  21. "compute_price": "formula",
  22. "base": "list_price",
  23. })]
  24. })
  25. self.partner = self.env["res.partner"].create({
  26. "name": "Mr. Odoo",
  27. "property_product_pricelist": self.pricelist.id,
  28. })
  29. # Create a new pos config and open it
  30. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
  31. self.pos_config.open_session_cb()
  32. # Test Section
  33. def test_load_order(self):
  34. order = self._create_order()
  35. orders_data = self.PosOrder.search_done_orders_for_pos(
  36. [], self.pos_config.current_session_id.id)
  37. self.assertEqual(len(orders_data), 1)
  38. self.assertEqual(
  39. orders_data[0]['id'], order.id)
  40. detail_data = order.load_done_order_for_pos()
  41. self.assertEqual(
  42. len(detail_data.get('line_ids', [])), 1,
  43. "Loading order detail failed")
  44. def _create_order(self):
  45. # Create order
  46. order_data = {
  47. 'id': u'0006-001-0010',
  48. 'to_invoice': True,
  49. 'data': {
  50. 'pricelist_id': self.pricelist.id,
  51. 'user_id': 1,
  52. 'name': 'Order 0006-001-0010',
  53. 'partner_id': self.partner.id,
  54. 'amount_paid': 0.9,
  55. 'pos_session_id': self.pos_config.current_session_id.id,
  56. 'lines': [[0, 0, {
  57. 'product_id': self.pos_product.id,
  58. 'price_unit': 0.9,
  59. 'qty': 1,
  60. 'price_subtotal': 0.9,
  61. 'price_subtotal_incl': 0.9,
  62. }]],
  63. 'statement_ids': [[0, 0, {
  64. 'journal_id': self.pos_config.journal_ids[0].id,
  65. 'amount': 0.9,
  66. 'name': fields.Datetime.now(),
  67. 'account_id':
  68. self.env.user.partner_id.property_account_receivable_id.id,
  69. 'statement_id':
  70. self.pos_config.current_session_id.statement_ids[0].id,
  71. }]],
  72. 'creation_date': u'2018-09-27 15:51:03',
  73. 'amount_tax': 0,
  74. 'fiscal_position_id': False,
  75. 'uid': u'00001-001-0001',
  76. 'amount_return': 0,
  77. 'sequence_number': 1,
  78. 'amount_total': 0.9,
  79. }}
  80. result = self.PosOrder.create_from_ui([order_data])
  81. order = self.PosOrder.browse(result[0])
  82. return order