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

5 years ago
5 years ago
  1. # Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # @author: Robin Keunen <robin@coopiteasy.be>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from datetime import timedelta
  6. from odoo import fields
  7. from odoo.tests.common import TransactionCase
  8. from odoo.tools import float_compare
  9. class TestModule(TransactionCase):
  10. def setUp(self):
  11. super(TestModule, self).setUp()
  12. # Get Registry
  13. self.PosOrder = self.env["pos.order"]
  14. self.AccountPayment = self.env["account.payment"]
  15. # Get Object
  16. self.pos_product = self.env.ref("product.product_product_25")
  17. self.pos_template = self.pos_product.product_tmpl_id
  18. self.pricelist = self.env.ref("product.list0")
  19. self.partner = self.env.ref("base.res_partner_12")
  20. # Create a new pos config and open it
  21. self.pos_config = self.env.ref("point_of_sale.pos_config_main").copy()
  22. self.pos_config.open_session_cb()
  23. # Test Section
  24. def test_compute_stock_coverage(self):
  25. self._create_order()
  26. self.pos_template._compute_stock_coverage()
  27. self.assertEquals(1.0, self.pos_template.range_sales)
  28. self.assertEqual(
  29. float_compare(
  30. 0.0714, self.pos_template.daily_sales, precision_digits=2
  31. ),
  32. 0,
  33. )
  34. self.assertEquals(210.0, self.pos_template.stock_coverage)
  35. def _create_order(self):
  36. date = fields.Date.today() - timedelta(days=1)
  37. date_str = fields.Date.to_string(date)
  38. order_data = {
  39. "id": u"0006-001-0010",
  40. "to_invoice": True,
  41. "data": {
  42. "pricelist_id": self.pricelist.id,
  43. "user_id": 1,
  44. "name": "Order 0006-001-0010",
  45. "partner_id": self.partner.id,
  46. "amount_paid": 0.9,
  47. "pos_session_id": self.pos_config.current_session_id.id,
  48. "lines": [
  49. [
  50. 0,
  51. 0,
  52. {
  53. "product_id": self.pos_product.id,
  54. "price_unit": 0.9,
  55. "qty": 1,
  56. "price_subtotal": 0.9,
  57. "price_subtotal_incl": 0.9,
  58. },
  59. ]
  60. ],
  61. "statement_ids": [
  62. [
  63. 0,
  64. 0,
  65. {
  66. "journal_id": self.pos_config.journal_ids[0].id,
  67. "amount": 0.9,
  68. "name": fields.Datetime.now(),
  69. "account_id": self.env.user.partner_id.property_account_receivable_id.id,
  70. "statement_id": self.pos_config.current_session_id.statement_ids[
  71. 0
  72. ].id,
  73. },
  74. ]
  75. ],
  76. "creation_date": date_str,
  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. }
  85. result = self.PosOrder.create_from_ui([order_data])
  86. order = self.PosOrder.browse(result[0])
  87. return order