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.

102 lines
3.8 KiB

  1. # Copyright (C) 2013 - Today: GRAP (http://www.grap.coop)
  2. # @author: Julien WESTE
  3. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from odoo import fields
  6. from odoo.tests.common import TransactionCase
  7. from odoo.exceptions import Warning as UserError
  8. class TestModule(TransactionCase):
  9. def setUp(self):
  10. super(TestModule, self).setUp()
  11. # Get Registry
  12. self.PosOrder = self.env['pos.order']
  13. self.AccountPayment = self.env['account.payment']
  14. # Get Object
  15. self.pos_product = self.env.ref('point_of_sale.whiteboard_pen')
  16. self.pricelist = self.env.ref('product.list0')
  17. self.partner = self.env.ref('base.res_partner_12')
  18. # Create a new pos config and open it
  19. self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy()
  20. self.pos_config.open_session_cb()
  21. # Test Section
  22. def test_order_invoice(self):
  23. order = self._create_order()
  24. # Check if invoice is correctly set
  25. self.assertEquals(order.invoice_id.pos_pending_payment, True)
  26. # Try to register payment should fail on this invoice should fail
  27. with self.assertRaises(UserError):
  28. payment = self.register_payment(order.invoice_id)
  29. payment.post()
  30. # Try to register a payment not linked to this invoice should be ok
  31. payment = self.register_payment()
  32. payment.post()
  33. # Once closed check if the invoice is correctly set
  34. self.pos_config.current_session_id.action_pos_session_closing_control()
  35. self.assertEquals(order.invoice_id.pos_pending_payment, False)
  36. # Private Section
  37. def register_payment(self, invoice_id=False):
  38. journal = self.pos_config.journal_ids[0]
  39. return self.AccountPayment.create({
  40. 'invoice_ids': invoice_id and [(4, invoice_id.id, None)] or False,
  41. 'payment_type': 'inbound',
  42. 'partner_type': 'customer',
  43. 'payment_date': fields.Datetime.now(),
  44. 'partner_id': self.partner.id,
  45. 'amount': 0.9,
  46. 'journal_id': journal.id,
  47. 'payment_method_id': journal.inbound_payment_method_ids[0].id,
  48. })
  49. def _create_order(self):
  50. # Create order
  51. order_data = {
  52. 'id': u'0006-001-0010',
  53. 'to_invoice': True,
  54. 'data': {
  55. 'pricelist_id': self.pricelist.id,
  56. 'user_id': 1,
  57. 'name': 'Order 0006-001-0010',
  58. 'partner_id': self.partner.id,
  59. 'amount_paid': 0.9,
  60. 'pos_session_id': self.pos_config.current_session_id.id,
  61. 'lines': [[0, 0, {
  62. 'product_id': self.pos_product.id,
  63. 'price_unit': 0.9,
  64. 'qty': 1,
  65. 'price_subtotal': 0.9,
  66. 'price_subtotal_incl': 0.9,
  67. }]],
  68. 'statement_ids': [[0, 0, {
  69. 'journal_id': self.pos_config.journal_ids[0].id,
  70. 'amount': 0.9,
  71. 'name': fields.Datetime.now(),
  72. 'account_id':
  73. self.env.user.partner_id.property_account_receivable_id.id,
  74. 'statement_id':
  75. self.pos_config.current_session_id.statement_ids[0].id,
  76. }]],
  77. 'creation_date': u'2018-09-27 15:51:03',
  78. 'amount_tax': 0,
  79. 'fiscal_position_id': False,
  80. 'uid': u'00001-001-0001',
  81. 'amount_return': 0,
  82. 'sequence_number': 1,
  83. 'amount_total': 0.9,
  84. }}
  85. result = self.PosOrder.create_from_ui([order_data])
  86. order = self.PosOrder.browse(result[0])
  87. return order