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.

99 lines
4.5 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. self.income_reason = self.env.ref('pos_cash_move_reason.income_reason')
  18. self.expense_reason = self.env.ref(
  19. 'pos_cash_move_reason.expense_reason')
  20. def test01(self):
  21. # I set cash control on cash journal
  22. self.cash_journal.cash_control = True
  23. # I create and open a new session
  24. self.session_01 = self.pos_session_obj.create(
  25. {'config_id': self.main_config.id})
  26. ctx = self.env.context.copy()
  27. # context is updated in open_cb
  28. # -> Need to call with old api to give unfrozen context
  29. self.registry['pos.session'].open_cb(
  30. self.cr, self.uid, [self.session_01.id], context=ctx)
  31. ctx['active_ids'] = self.session_01.id
  32. ctx['active_model'] = self.session_01._name
  33. # I put the session in validation control
  34. self.session_01.signal_workflow('cashbox_control')
  35. ctx['active_ids'] = self.session_01.id
  36. ctx['active_model'] = self.session_01._name
  37. # I create a cash in
  38. cash_in = self.cash_in_obj.with_context(ctx).create(
  39. {'name': 'Initialization',
  40. 'product_id': self.income_reason.id,
  41. 'amount': 500.0})
  42. cash_in.with_context(ctx).run()
  43. # I close the session
  44. self.session_01.signal_workflow('close')
  45. # I get the statement from the session
  46. statement = self.env['account.bank.statement'].search(
  47. [('pos_session_id', '=', self.session_01.id),
  48. ('journal_id', '=', self.cash_journal.id)])
  49. # I get all move lines of this statement
  50. move_line_ids = statement.move_line_ids.ids
  51. move_line = self.env['account.move.line'].search(
  52. [('account_id', '=', self.income_account.id),
  53. ('credit', '=', 500.0),
  54. ('id', 'in', move_line_ids)])
  55. # I check the created move line from the cash in
  56. self.assertEquals(len(move_line.ids), 1)
  57. def test02(self):
  58. # I set cash control on cash journal
  59. self.cash_journal.cash_control = True
  60. # I create and open a new session
  61. self.session_01 = self.pos_session_obj.create(
  62. {'config_id': self.main_config.id})
  63. ctx = self.env.context.copy()
  64. # context is updated in open_cb
  65. # -> Need to call with old api to give unfrozen context
  66. self.registry['pos.session'].open_cb(
  67. self.cr, self.uid, [self.session_01.id], context=ctx)
  68. ctx['active_ids'] = self.session_01.id
  69. ctx['active_model'] = self.session_01._name
  70. # I put the session in validation control
  71. self.session_01.signal_workflow('cashbox_control')
  72. ctx['active_ids'] = self.session_01.id
  73. ctx['active_model'] = self.session_01._name
  74. # I create a cash out
  75. cash_out = self.cash_out_obj.with_context(ctx).create(
  76. {'name': 'Miscellaneous expense',
  77. 'product_id': self.expense_reason.id,
  78. 'amount': 500.0})
  79. cash_out.with_context(ctx).run()
  80. # I close the session
  81. self.session_01.signal_workflow('close')
  82. # I get the statement from the session
  83. statement = self.env['account.bank.statement'].search(
  84. [('pos_session_id', '=', self.session_01.id),
  85. ('journal_id', '=', self.cash_journal.id)])
  86. # I get all move lines of this statement
  87. move_line_ids = statement.move_line_ids.ids
  88. move_line = self.env['account.move.line'].search(
  89. [('account_id', '=', self.expense_account.id),
  90. ('debit', '=', 500.0),
  91. ('id', 'in', move_line_ids)])
  92. # I check the created move line from the cash in
  93. self.assertEquals(len(move_line.ids), 1)