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.

81 lines
3.0 KiB

  1. # Copyright 2018 Tecnativa - David Vidal
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. @common.at_install(False)
  5. @common.post_install(True)
  6. class TestPointOfSaleStockPickingInvoiceLink(common.HttpCase):
  7. def setUp(self):
  8. super(TestPointOfSaleStockPickingInvoiceLink, self).setUp()
  9. self.partner = self.env['res.partner'].create({
  10. 'name': 'Mr. Odoo',
  11. })
  12. self.product_1 = self.env['product.product'].create({
  13. 'name': 'Test variant 1',
  14. 'standard_price': 1.0,
  15. 'type': 'product',
  16. })
  17. self.product_2 = self.env['product.product'].create({
  18. 'name': 'Test variant 1',
  19. 'standard_price': 1.0,
  20. 'type': 'product',
  21. })
  22. self.pricelist = self.env['product.pricelist'].create({
  23. 'name': 'Test pricelist',
  24. 'item_ids': [(0, 0, {
  25. 'applied_on': '3_global',
  26. 'compute_price': 'formula',
  27. 'base': 'list_price',
  28. })]
  29. })
  30. self.PosOrder = self.env['pos.order']
  31. self.pos_config = self.env.ref('point_of_sale.pos_config_main')
  32. self.pos_config.write({
  33. 'available_pricelist_ids': [(6, 0, self.pricelist.ids)],
  34. 'pricelist_id': self.pricelist.id,
  35. })
  36. def test_stock_picking_invoice_link(self):
  37. """The picking is created and the lines are related to their moves"""
  38. self.pos_config.open_session_cb()
  39. pos_order = self.PosOrder.create({
  40. 'session_id': self.pos_config.current_session_id.id,
  41. 'partner_id': self.partner.id,
  42. 'pricelist_id': self.partner.property_product_pricelist.id,
  43. 'lines': [
  44. (0, 0, {
  45. 'name': "POSLINE/0001",
  46. 'product_id': self.product_1.id,
  47. 'price_unit': 450,
  48. 'qty': 2.0,
  49. }),
  50. (0, 0, {
  51. 'name': "POSLINE/0002",
  52. 'product_id': self.product_2.id,
  53. 'price_unit': 450,
  54. 'qty': 2.0,
  55. }),
  56. (0, 0, {
  57. 'name': "POSLINE/0003",
  58. 'product_id': self.product_1.id,
  59. 'price_unit': 450,
  60. 'qty': 2.0,
  61. }),
  62. ],
  63. })
  64. context_make_payment = {
  65. "active_ids": [pos_order.id],
  66. "active_id": pos_order.id,
  67. }
  68. pos_make_payment = self.env['pos.make.payment'].with_context(
  69. context_make_payment).create({'amount': 950})
  70. context_payment = {'active_id': pos_order.id}
  71. pos_make_payment.with_context(context_payment).check()
  72. pos_order.create_picking()
  73. res = pos_order.action_pos_order_invoice()
  74. invoice = self.env['account.invoice'].browse(res['res_id'])
  75. self.assertTrue(invoice.picking_ids)
  76. for line in invoice.invoice_line_ids:
  77. self.assertEqual(len(line.move_line_ids), 1)