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.

85 lines
3.3 KiB

  1. # Copyright (C) 2017: Opener B.V. (https://opener.amsterdam)
  2. # @author: Stefan Rijnhart <stefan@opener.am>
  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 TestPosPickingLoad(TransactionCase):
  7. def test_pos_picking_load(self):
  8. product = self.env.ref('product.product_product_24')
  9. pricelist = self.env.ref('product.list0')
  10. # Create a Sale order and confirm it to generate a picking to load
  11. sale_order = self.env['sale.order'].create({
  12. 'partner_id': self.env.ref('base.res_partner_1').id,
  13. 'order_line': [(0, 0, {
  14. 'product_id': product.id,
  15. 'price_unit': 6,
  16. 'product_uom_qty': 2,
  17. 'qty_delivered_method': 'stock_move',
  18. })],
  19. })
  20. sale_order.action_confirm()
  21. sale_order.picking_ids.picking_type_id.write({
  22. 'available_in_pos': True})
  23. # Configure Point of sale
  24. config = self.env.ref('point_of_sale.pos_config_main').copy()
  25. config.write({
  26. 'picking_type_id': sale_order.picking_ids.picking_type_id.id})
  27. # Open a new session
  28. config.open_session_cb()
  29. session = self.env['pos.session'].search([
  30. ('config_id', '=', config.id)])[0]
  31. date_now = fields.Datetime.now()
  32. # Create a pos order
  33. self.env['pos.order'].create_from_ui([{
  34. 'to_invoice': False,
  35. 'data': {
  36. 'pricelist_id': pricelist.id,
  37. 'user_id': self.env.user.id,
  38. 'creation_date': date_now,
  39. 'fiscal_position_id': False,
  40. 'name': 'Order 00017-002-0003',
  41. 'partner_id': sale_order.partner_id.id,
  42. 'amount_paid': 12,
  43. 'pos_session_id': session.id,
  44. 'lines': [[0, 0, {
  45. 'product_id': product.id,
  46. 'price_unit': 6,
  47. 'name': product.name,
  48. 'discount': 0,
  49. 'qty': 2,
  50. 'price_subtotal': 12,
  51. 'price_subtotal_incl': 12,
  52. 'tax_ids': [[6, False, []]],
  53. }]],
  54. 'statement_ids': [[0, 0, {
  55. 'journal_id': False,
  56. 'amount': 12,
  57. 'name': date_now,
  58. 'account_id': config.journal_ids[
  59. 0].default_debit_account_id.id,
  60. 'statement_id': session.statement_ids[0].id,
  61. }]],
  62. 'amount_tax': 0,
  63. 'origin_picking_id': sale_order.picking_ids.id,
  64. 'uid': '00017-002-0003',
  65. 'amount_return': 0,
  66. 'sequence_number': 3,
  67. 'amount_total': 12,
  68. },
  69. 'id': '00017-002-0003',
  70. }])
  71. pos_order = self.env['pos.order'].search(
  72. [('origin_picking_id', 'in', sale_order.picking_ids.ids)])
  73. self.assertTrue(pos_order)
  74. self.assertEqual(pos_order.origin_picking_id.state, 'cancel')
  75. self.assertEqual(
  76. pos_order.picking_id.group_id,
  77. pos_order.origin_picking_id.group_id)
  78. self.assertEqual(
  79. sale_order.invoice_status, 'invoiced')