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.

96 lines
3.4 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. 'available_pricelist_ids': [(6, 0, self.pricelist.ids)],
  32. 'pricelist_id': self.pricelist.id,
  33. })
  34. self.pos_config.open_session_cb()
  35. # Test Section
  36. def test_load_order(self):
  37. order = self._create_order()
  38. orders_data = self.PosOrder.search_done_orders_for_pos(
  39. [], self.pos_config.current_session_id.id)
  40. self.assertEqual(len(orders_data), 1)
  41. self.assertEqual(
  42. orders_data[0]['id'], order.id)
  43. detail_data = order.load_done_order_for_pos()
  44. self.assertEqual(
  45. len(detail_data.get('line_ids', [])), 1,
  46. "Loading order detail failed")
  47. def _create_order(self):
  48. # Create order
  49. order_data = {
  50. 'id': u'0006-001-0010',
  51. 'to_invoice': True,
  52. 'data': {
  53. 'pricelist_id': self.pricelist.id,
  54. 'user_id': 1,
  55. 'name': 'Order 0006-001-0010',
  56. 'partner_id': self.partner.id,
  57. 'amount_paid': 0.9,
  58. 'pos_session_id': self.pos_config.current_session_id.id,
  59. 'lines': [[0, 0, {
  60. 'product_id': self.pos_product.id,
  61. 'price_unit': 0.9,
  62. 'qty': 1,
  63. 'price_subtotal': 0.9,
  64. 'price_subtotal_incl': 0.9,
  65. }]],
  66. 'statement_ids': [[0, 0, {
  67. 'journal_id': self.pos_config.journal_ids[0].id,
  68. 'amount': 0.9,
  69. 'name': fields.Datetime.now(),
  70. 'account_id':
  71. self.env.user.partner_id.property_account_receivable_id.id,
  72. 'statement_id':
  73. self.pos_config.current_session_id.statement_ids[0].id,
  74. }]],
  75. 'creation_date': u'2018-09-27 15:51:03',
  76. 'amount_tax': 0,
  77. 'fiscal_position_id': False,
  78. 'uid': u'00001-001-0001',
  79. 'amount_return': 0,
  80. 'sequence_number': 1,
  81. 'amount_total': 0.9,
  82. }}
  83. result = self.PosOrder.create_from_ui([order_data])
  84. order = self.PosOrder.browse(result[0])
  85. return order