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.

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