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.

271 lines
13 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 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 TestPosPaymentEntriesGlobalization(common.TransactionCase):
  6. def setUp(self):
  7. super(TestPosPaymentEntriesGlobalization, self).setUp()
  8. self.move_line_obj = self.env['account.move.line']
  9. self.pos_session_obj = self.env['pos.session']
  10. self.pos_order_obj = self.env['pos.order']
  11. self.main_config = self.env.ref('point_of_sale.pos_config_main')
  12. self.payment_method_01 = self.env.ref('account.cash_journal')
  13. self.payment_method_02 = self.env.ref('account.bank_journal')
  14. self.payment_method_02.default_debit_account_id.reconcile = True
  15. self.payment_method_03 = self.env.ref('account.check_journal')
  16. self.payment_method_03.default_debit_account_id.reconcile = True
  17. self.income_account = self.env.ref('account.o_income')
  18. self.income_account_02 = self.income_account.copy()
  19. self.misc_journal = self.env.ref('account.miscellaneous_journal')
  20. self.misc_journal_02 = self.misc_journal.copy()
  21. self.product_01 = self.env.ref('point_of_sale.perrier_50cl')
  22. def open_session(self):
  23. # I create and open a new session
  24. session = 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, [session.id], context=ctx)
  31. return session
  32. def create_order(self, amount, session):
  33. # I create a new order
  34. order_vals = {
  35. 'session_id': session.id,
  36. 'lines': [(0, 0, {'product_id': self.product_01.id,
  37. 'price_unit': amount,
  38. })]
  39. }
  40. return self.pos_order_obj.create(order_vals)
  41. def test_globalization_0(self):
  42. session = self.open_session()
  43. self.payment_method_02.pos_payment_globalization = True
  44. self.payment_method_02.pos_payment_globalization_account =\
  45. self.income_account
  46. self.payment_method_02.pos_payment_globalization_journal =\
  47. self.misc_journal
  48. # I create a new order
  49. order_01 = self.create_order(100, session)
  50. # I pay the created order
  51. payment_data = {'amount': 100,
  52. 'journal': self.payment_method_02.id}
  53. self.pos_order_obj.add_payment(order_01.id, payment_data)
  54. if order_01.test_paid():
  55. order_01.signal_workflow('paid')
  56. # I create a new order
  57. order_02 = self.create_order(100, session)
  58. # I pay the created order
  59. payment_data = {'amount': 100,
  60. 'journal': self.payment_method_02.id}
  61. self.pos_order_obj.add_payment(order_02.id, payment_data)
  62. if order_02.test_paid():
  63. order_02.signal_workflow('paid')
  64. # I close the session
  65. session.signal_workflow('close')
  66. move_line = self.move_line_obj.search(
  67. [('account_id', '=', self.income_account.id),
  68. ('journal_id', '=', self.misc_journal.id)])
  69. # I check that there is only one move line
  70. self.assertEqual(len(move_line.ids), 1)
  71. self.assertAlmostEqual(move_line.debit, 200, 2)
  72. domain = [('move_id', '=', move_line.move_id.id),
  73. ('id', '!=', move_line.id)]
  74. reverse_lines = self.move_line_obj.search(domain)
  75. # I ensure that the move contains reverse lines
  76. self.assertEqual(len(reverse_lines), 2)
  77. # I ensure reverse lines are reconciled
  78. not_reconcile_reverse_lines = reverse_lines.filtered(
  79. lambda r: not r.reconcile_ref)
  80. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  81. def test_globalization_1(self):
  82. session = self.open_session()
  83. self.payment_method_02.pos_payment_globalization = True
  84. self.payment_method_02.pos_payment_globalization_account =\
  85. self.income_account
  86. self.payment_method_02.pos_payment_globalization_journal =\
  87. self.misc_journal
  88. self.payment_method_03.pos_payment_globalization = True
  89. self.payment_method_03.pos_payment_globalization_account =\
  90. self.income_account_02
  91. self.payment_method_03.pos_payment_globalization_journal =\
  92. self.misc_journal
  93. # I create a new order
  94. order_01 = self.create_order(100, session)
  95. # I pay the created order
  96. payment_data = {'amount': 100,
  97. 'journal': self.payment_method_02.id}
  98. self.pos_order_obj.add_payment(order_01.id, payment_data)
  99. if order_01.test_paid():
  100. order_01.signal_workflow('paid')
  101. # I create a new order
  102. order_02 = self.create_order(100, session)
  103. # I pay the created order
  104. payment_data = {'amount': 100,
  105. 'journal': self.payment_method_03.id}
  106. self.pos_order_obj.add_payment(order_02.id, payment_data)
  107. if order_02.test_paid():
  108. order_02.signal_workflow('paid')
  109. # I close the session
  110. session.signal_workflow('close')
  111. # I check the first globalization account
  112. move_line = self.move_line_obj.search(
  113. [('account_id', '=', self.income_account.id),
  114. ('journal_id', '=', self.misc_journal.id)])
  115. # I check that there is only one move line
  116. self.assertEqual(len(move_line.ids), 1)
  117. self.assertAlmostEqual(move_line.debit, 100, 2)
  118. domain = [('move_id', '=', move_line.move_id.id),
  119. ('id', '!=', move_line.id)]
  120. reverse_lines = self.move_line_obj.search(domain)
  121. # I ensure that the move contains reverse lines
  122. self.assertEqual(len(reverse_lines), 1)
  123. # I ensure reverse lines are reconciled
  124. not_reconcile_reverse_lines = reverse_lines.filtered(
  125. lambda r: not r.reconcile_ref)
  126. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  127. # I check the second globalization account
  128. move_line = self.move_line_obj.search(
  129. [('account_id', '=', self.income_account_02.id),
  130. ('journal_id', '=', self.misc_journal.id)])
  131. # I check that there is only one move line
  132. self.assertEqual(len(move_line.ids), 1)
  133. self.assertAlmostEqual(move_line.debit, 100, 2)
  134. domain = [('move_id', '=', move_line.move_id.id),
  135. ('id', '!=', move_line.id)]
  136. reverse_lines = self.move_line_obj.search(domain)
  137. # I ensure that the move contains reverse lines
  138. self.assertEqual(len(reverse_lines), 1)
  139. # I ensure reverse lines are reconciled
  140. not_reconcile_reverse_lines = reverse_lines.filtered(
  141. lambda r: not r.reconcile_ref)
  142. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  143. def test_globalization_2(self):
  144. session = self.open_session()
  145. self.payment_method_02.pos_payment_globalization = True
  146. self.payment_method_02.pos_payment_globalization_account =\
  147. self.income_account
  148. self.payment_method_02.pos_payment_globalization_journal =\
  149. self.misc_journal
  150. self.payment_method_03.pos_payment_globalization = True
  151. self.payment_method_03.pos_payment_globalization_account =\
  152. self.income_account_02
  153. self.payment_method_03.pos_payment_globalization_journal =\
  154. self.misc_journal
  155. # I create a new order
  156. order_01 = self.create_order(200, session)
  157. # I pay the created order
  158. payment_data = {'amount': 100,
  159. 'journal': self.payment_method_02.id}
  160. self.pos_order_obj.add_payment(order_01.id, payment_data)
  161. payment_data = {'amount': 100,
  162. 'journal': self.payment_method_03.id}
  163. self.pos_order_obj.add_payment(order_01.id, payment_data)
  164. if order_01.test_paid():
  165. order_01.signal_workflow('paid')
  166. # I close the session
  167. session.signal_workflow('close')
  168. # I check the first globalization account
  169. move_line = self.move_line_obj.search(
  170. [('account_id', '=', self.income_account.id),
  171. ('journal_id', '=', self.misc_journal.id)])
  172. # I check that there is only one move line
  173. self.assertEqual(len(move_line.ids), 1)
  174. self.assertAlmostEqual(move_line.debit, 100, 2)
  175. domain = [('move_id', '=', move_line.move_id.id),
  176. ('id', '!=', move_line.id)]
  177. reverse_lines = self.move_line_obj.search(domain)
  178. # I ensure that the move contains reverse lines
  179. self.assertEqual(len(reverse_lines), 1)
  180. # I ensure reverse lines are reconciled
  181. not_reconcile_reverse_lines = reverse_lines.filtered(
  182. lambda r: not r.reconcile_ref)
  183. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  184. # I check the second globalization account
  185. move_line = self.move_line_obj.search(
  186. [('account_id', '=', self.income_account_02.id),
  187. ('journal_id', '=', self.misc_journal.id)])
  188. # I check that there is only one move line
  189. self.assertEqual(len(move_line.ids), 1)
  190. self.assertAlmostEqual(move_line.debit, 100, 2)
  191. domain = [('move_id', '=', move_line.move_id.id),
  192. ('id', '!=', move_line.id)]
  193. reverse_lines = self.move_line_obj.search(domain)
  194. # I ensure that the move contains reverse lines
  195. self.assertEqual(len(reverse_lines), 1)
  196. # I ensure reverse lines are reconciled
  197. not_reconcile_reverse_lines = reverse_lines.filtered(
  198. lambda r: not r.reconcile_ref)
  199. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  200. def test_globalization_3(self):
  201. session = self.open_session()
  202. self.payment_method_02.pos_payment_globalization = True
  203. self.payment_method_02.pos_payment_globalization_account =\
  204. self.income_account
  205. self.payment_method_02.pos_payment_globalization_journal =\
  206. self.misc_journal
  207. self.payment_method_03.pos_payment_globalization = True
  208. self.payment_method_03.pos_payment_globalization_account =\
  209. self.income_account
  210. self.payment_method_03.pos_payment_globalization_journal =\
  211. self.misc_journal_02
  212. # I create a new order
  213. order_01 = self.create_order(100, session)
  214. # I pay the created order
  215. payment_data = {'amount': 100,
  216. 'journal': self.payment_method_02.id}
  217. self.pos_order_obj.add_payment(order_01.id, payment_data)
  218. if order_01.test_paid():
  219. order_01.signal_workflow('paid')
  220. # I create a new order
  221. order_02 = self.create_order(100, session)
  222. # I pay the created order
  223. payment_data = {'amount': 100,
  224. 'journal': self.payment_method_03.id}
  225. self.pos_order_obj.add_payment(order_02.id, payment_data)
  226. if order_02.test_paid():
  227. order_02.signal_workflow('paid')
  228. # I close the session
  229. session.signal_workflow('close')
  230. # I check the first globalization journal
  231. move_line = self.move_line_obj.search(
  232. [('account_id', '=', self.income_account.id),
  233. ('journal_id', '=', self.misc_journal.id)])
  234. # I check that there is only one move line
  235. self.assertEqual(len(move_line.ids), 1)
  236. self.assertAlmostEqual(move_line.debit, 100, 2)
  237. domain = [('move_id', '=', move_line.move_id.id),
  238. ('id', '!=', move_line.id)]
  239. reverse_lines = self.move_line_obj.search(domain)
  240. # I ensure that the move contains reverse lines
  241. self.assertEqual(len(reverse_lines), 1)
  242. # I ensure reverse lines are reconciled
  243. not_reconcile_reverse_lines = reverse_lines.filtered(
  244. lambda r: not r.reconcile_ref)
  245. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  246. # I check the second globalization journal
  247. move_line = self.move_line_obj.search(
  248. [('account_id', '=', self.income_account.id),
  249. ('journal_id', '=', self.misc_journal_02.id)])
  250. # I check that there is only one move line
  251. self.assertEqual(len(move_line.ids), 1)
  252. self.assertAlmostEqual(move_line.debit, 100, 2)
  253. domain = [('move_id', '=', move_line.move_id.id),
  254. ('id', '!=', move_line.id)]
  255. reverse_lines = self.move_line_obj.search(domain)
  256. # I ensure that the move contains reverse lines
  257. self.assertEqual(len(reverse_lines), 1)
  258. # I ensure reverse lines are reconciled
  259. not_reconcile_reverse_lines = reverse_lines.filtered(
  260. lambda r: not r.reconcile_ref)
  261. self.assertEqual(len(not_reconcile_reverse_lines), 0)