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.4 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. account = self.env.user.partner_id.property_account_receivable_id
  39. statement = self.pos_config.current_session_id.statement_ids[0]
  40. order_data = {
  41. "id": u"0006-001-0010",
  42. "to_invoice": True,
  43. "data": {
  44. "pricelist_id": self.pricelist.id,
  45. "user_id": 1,
  46. "name": "Order 0006-001-0010",
  47. "partner_id": self.partner.id,
  48. "amount_paid": 0.9,
  49. "pos_session_id": self.pos_config.current_session_id.id,
  50. "lines": [
  51. [
  52. 0,
  53. 0,
  54. {
  55. "product_id": self.pos_product.id,
  56. "price_unit": 0.9,
  57. "qty": 1,
  58. "price_subtotal": 0.9,
  59. "price_subtotal_incl": 0.9,
  60. },
  61. ]
  62. ],
  63. "statement_ids": [
  64. [
  65. 0,
  66. 0,
  67. {
  68. "journal_id": self.pos_config.journal_ids[0].id,
  69. "amount": 0.9,
  70. "name": fields.Datetime.now(),
  71. "account_id": account.id,
  72. "statement_id": statement.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