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.

106 lines
4.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests import common
  5. class TestPosCashMoveReason(common.TransactionCase):
  6. def setUp(self):
  7. super(TestPosCashMoveReason, self).setUp()
  8. self.pos_session_obj = self.env['pos.session']
  9. self.aml_obj = self.env['account.move.line']
  10. self.cash_in_obj = self.env['cash.box.in']
  11. self.cash_out_obj = self.env['cash.box.out']
  12. self.cash_move_reason_obj = self.env['product.template']
  13. self.main_config = self.env.ref('point_of_sale.pos_config_main')
  14. self.cash_journal = self.env.ref('account.cash_journal')
  15. self.income_account = self.env.ref('account.o_income')
  16. self.expense_account = self.env.ref('account.a_expense')
  17. def test01(self):
  18. # I create one move reason
  19. vals = {'name': 'Miscellaneous income',
  20. 'property_account_income': self.income_account.id,
  21. 'income_pdt': True}
  22. move_reason = self.cash_move_reason_obj.create(vals)
  23. # I set cash control on cash journal
  24. self.cash_journal.cash_control = True
  25. # I create and open a new session
  26. self.session_01 = self.pos_session_obj.create(
  27. {'config_id': self.main_config.id})
  28. ctx = self.env.context.copy()
  29. # context is updated in open_cb
  30. # -> Need to call with old api to give unfrozen context
  31. self.registry['pos.session'].open_cb(
  32. self.cr, self.uid, [self.session_01.id], context=ctx)
  33. ctx['active_ids'] = self.session_01.id
  34. ctx['active_model'] = self.session_01._name
  35. # I put the session in validation control
  36. self.session_01.signal_workflow('cashbox_control')
  37. ctx['active_ids'] = self.session_01.id
  38. ctx['active_model'] = self.session_01._name
  39. # I create a cash in
  40. cash_in = self.cash_in_obj.with_context(ctx).create(
  41. {'name': 'Initialization',
  42. 'product_id': move_reason.id,
  43. 'amount': 500.0})
  44. cash_in.with_context(ctx).run()
  45. # I close the session
  46. self.session_01.signal_workflow('close')
  47. # I get the statement from the session
  48. statement = self.env['account.bank.statement'].search(
  49. [('pos_session_id', '=', self.session_01.id),
  50. ('journal_id', '=', self.cash_journal.id)])
  51. # I get all move lines of this statement
  52. move_line_ids = statement.move_line_ids.ids
  53. move_line = self.env['account.move.line'].search(
  54. [('account_id', '=', self.income_account.id),
  55. ('credit', '=', 500.0),
  56. ('id', 'in', move_line_ids)])
  57. # I check the created move line from the cash in
  58. self.assertEquals(len(move_line.ids), 1)
  59. def test02(self):
  60. # I create one move reason
  61. vals = {'name': 'Miscellaneous expense',
  62. 'property_account_expense': self.expense_account.id,
  63. 'expense_pdt': True}
  64. move_reason = self.cash_move_reason_obj.create(vals)
  65. # I set cash control on cash journal
  66. self.cash_journal.cash_control = True
  67. # I create and open a new session
  68. self.session_01 = self.pos_session_obj.create(
  69. {'config_id': self.main_config.id})
  70. ctx = self.env.context.copy()
  71. # context is updated in open_cb
  72. # -> Need to call with old api to give unfrozen context
  73. self.registry['pos.session'].open_cb(
  74. self.cr, self.uid, [self.session_01.id], context=ctx)
  75. ctx['active_ids'] = self.session_01.id
  76. ctx['active_model'] = self.session_01._name
  77. # I put the session in validation control
  78. self.session_01.signal_workflow('cashbox_control')
  79. ctx['active_ids'] = self.session_01.id
  80. ctx['active_model'] = self.session_01._name
  81. # I create a cash out
  82. cash_out = self.cash_out_obj.with_context(ctx).create(
  83. {'name': 'Miscellaneous expense',
  84. 'product_id': move_reason.id,
  85. 'amount': 500.0})
  86. cash_out.with_context(ctx).run()
  87. # I close the session
  88. self.session_01.signal_workflow('close')
  89. # I get the statement from the session
  90. statement = self.env['account.bank.statement'].search(
  91. [('pos_session_id', '=', self.session_01.id),
  92. ('journal_id', '=', self.cash_journal.id)])
  93. # I get all move lines of this statement
  94. move_line_ids = statement.move_line_ids.ids
  95. move_line = self.env['account.move.line'].search(
  96. [('account_id', '=', self.expense_account.id),
  97. ('debit', '=', 500.0),
  98. ('id', 'in', move_line_ids)])
  99. # I check the created move line from the cash in
  100. self.assertEquals(len(move_line.ids), 1)