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.

68 lines
2.5 KiB

  1. # Copyright 2019 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import fields
  4. from odoo.tests.common import TransactionCase
  5. class TestModule(TransactionCase):
  6. def setUp(self):
  7. super(TestModule, self).setUp()
  8. self.PosOrder = self.env['pos.order']
  9. self.pos_product = self.env.ref('point_of_sale.whiteboard_pen')
  10. self.pricelist = self.env.ref('product.list0')
  11. # Create a new pos config and open it
  12. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
  13. self.pos_config.open_session_cb()
  14. def test_margin(self):
  15. self.pos_product.list_price = 1.8
  16. self.pos_product.standard_price = 0.5
  17. order = self._create_order()
  18. self.assertEqual(
  19. order.margin, 10 * (1.8 - 0.5),
  20. "Bad computation of margin")
  21. def _create_order(self):
  22. # Create order
  23. order_data = {
  24. 'id': u'0006-001-0010',
  25. 'to_invoice': False,
  26. 'data': {
  27. 'pricelist_id': self.pricelist.id,
  28. 'user_id': 1,
  29. 'name': 'Order 0006-001-0010',
  30. 'partner_id': False,
  31. 'amount_paid': 0.9,
  32. 'pos_session_id': self.pos_config.current_session_id.id,
  33. 'lines': [[0, 0, {
  34. 'product_id': self.pos_product.id,
  35. 'price_unit': self.pos_product.list_price,
  36. 'qty': 10,
  37. 'price_subtotal': 18.0,
  38. 'price_subtotal_incl': 18.0,
  39. }]],
  40. 'statement_ids': [[0, 0, {
  41. 'journal_id': self.pos_config.journal_ids[0].id,
  42. 'amount': 18.0,
  43. 'name': fields.Datetime.now(),
  44. 'account_id':
  45. self.env.user.partner_id.property_account_receivable_id.id,
  46. 'statement_id':
  47. self.pos_config.current_session_id.statement_ids[0].id,
  48. }]],
  49. 'creation_date': u'2018-09-27 15:51:03',
  50. 'amount_tax': 0,
  51. 'fiscal_position_id': False,
  52. 'uid': u'00001-001-0001',
  53. 'amount_return': 0,
  54. 'sequence_number': 1,
  55. 'amount_total': 18.0,
  56. }}
  57. result = self.PosOrder.create_from_ui([order_data])
  58. order = self.PosOrder.browse(result[0])
  59. return order