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.

104 lines
3.7 KiB

  1. # Copyright 2019 Akretion (https://www.akretion.com).
  2. # @author Pierrick Brun <pierrick.brun@akretion.com>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  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. self.PosOrder = self.env["pos.order"]
  10. self.pos_product = self.env.ref("point_of_sale.whiteboard_pen")
  11. self.pricelist = self.env.ref("product.list0")
  12. # Create a new pos config and open it
  13. self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
  14. self.pos_config.open_session_cb()
  15. def test_mail_before_order(self):
  16. order = self._create_order(email="test_mail@example.org.tst")
  17. self.assertSent(order)
  18. def test_mail_after_order(self):
  19. order = self._create_order()
  20. self.env["pos.order"].send_mail_receipt(
  21. order.pos_reference,
  22. "test_mail@example.org.tst",
  23. "<p>Receipt's HTML</p>",
  24. force=False,
  25. )
  26. self.assertSent(order)
  27. self.env["pos.order"].send_mail_receipt(
  28. order.pos_reference,
  29. "test_mail@example.org.tst",
  30. "<p>Receipt's HTML</p>",
  31. force=False,
  32. )
  33. self.assertSent(order)
  34. def assertSent(self, order):
  35. mail = self.env["mail.mail"].search(
  36. [("model", "=", "pos.order"), ("res_id", "=", order.id)]
  37. )
  38. self.assertEqual(1, len(mail))
  39. self.assertEqual("test_mail@example.org.tst", mail.email_to)
  40. self.assertEqual(1, len(mail.attachment_ids))
  41. def _create_order(self, email=False):
  42. # Create order
  43. account = self.env.user.partner_id.property_account_receivable_id
  44. statement_ids = self.pos_config.current_session_id.statement_ids
  45. order_data = {
  46. "id": u"0006-001-0010",
  47. "to_invoice": False,
  48. "data": {
  49. "pricelist_id": self.pricelist.id,
  50. "user_id": 1,
  51. "name": "Order 0006-001-0010",
  52. "partner_id": False,
  53. "amount_paid": 0.9,
  54. "pos_session_id": self.pos_config.current_session_id.id,
  55. "lines": [
  56. [
  57. 0,
  58. 0,
  59. {
  60. "product_id": self.pos_product.id,
  61. "price_unit": self.pos_product.list_price,
  62. "qty": 10,
  63. "price_subtotal": 18.0,
  64. "price_subtotal_incl": 18.0,
  65. },
  66. ]
  67. ],
  68. "statement_ids": [
  69. [
  70. 0,
  71. 0,
  72. {
  73. "journal_id": self.pos_config.journal_ids[0].id,
  74. "amount": 18.0,
  75. "name": fields.Datetime.now(),
  76. "account_id": account.id,
  77. "statement_id": statement_ids[0].id,
  78. },
  79. ]
  80. ],
  81. "creation_date": u"2018-09-27 15:51:03",
  82. "amount_tax": 0,
  83. "fiscal_position_id": False,
  84. "uid": u"00001-001-0001",
  85. "amount_return": 0,
  86. "sequence_number": 1,
  87. "amount_total": 18.0,
  88. },
  89. }
  90. if email:
  91. order_data["data"]["email"] = email
  92. order_data["data"]["body_from_ui"] = "<p>Receipt's HTML</p>"
  93. result = self.PosOrder.create_from_ui([order_data])
  94. order = self.PosOrder.browse(result[0])
  95. return order