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.

367 lines
15 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 odoo.tests.common import SavepointCase
  5. class TestPosPaymentEntriesGlobalization(SavepointCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestPosPaymentEntriesGlobalization, cls).setUpClass()
  9. cls.move_line_obj = cls.env['account.move.line']
  10. cls.pos_order_obj = cls.env['pos.order']
  11. cls.main_config = cls.env.ref('point_of_sale.pos_config_main')
  12. cls.account_type = cls.env['account.account.type']
  13. cls.account_account = cls.env['account.account']
  14. cls.payment_method = cls.env['account.journal']
  15. cls.product_01 = cls.env.ref(
  16. 'point_of_sale.product_product_consumable')
  17. cls.pos_config = cls.env.ref('point_of_sale.pos_config_main')
  18. cls.customer_01 = cls.env.ref('base.res_partner_2')
  19. cls.pos_session_obj = cls.env['pos.session']
  20. # MODELS
  21. cls.account_type = cls.account_type.create({
  22. 'name': 'Bank and Cash',
  23. 'type': 'liquidity',
  24. 'include_initial_balance': True
  25. })
  26. cls.income_account = cls.account_account.create({
  27. 'code': 'X11006',
  28. 'name': 'Other Income',
  29. 'user_type_id': cls.account_type.id,
  30. })
  31. cls.income_account_02 = cls.income_account.copy()
  32. cls.account_account = cls.account_account.create({
  33. 'code': 'Test X1014',
  34. 'name': 'Bank Current Account - (test)',
  35. 'user_type_id': cls.account_type.id,
  36. 'reconcile': True
  37. })
  38. cls.payment_method_02 = cls.payment_method.create({
  39. 'name': 'Bank - Test',
  40. 'code': 'TBNK',
  41. 'type': 'bank',
  42. 'default_debit_account_id': cls.account_account.id,
  43. 'default_credit_account_id': cls.account_account.id
  44. })
  45. # next line
  46. cls.payment_method_03 = cls.payment_method.create({
  47. 'name': 'Checks Journal - (test)',
  48. 'code': 'TBNK',
  49. 'type': 'bank',
  50. 'default_debit_account_id': cls.account_account.id,
  51. 'default_credit_account_id': cls.account_account.id
  52. })
  53. cls.misc_journal = cls.payment_method.create({
  54. 'name': 'Miscellaneous Journal - (test)',
  55. 'code': 'TMIS',
  56. 'type': 'general'
  57. })
  58. cls.misc_journal_02 = cls.misc_journal.copy()
  59. def create_order(self, amount, session):
  60. # I create a new order
  61. order_vals = {
  62. 'session_id': session.id,
  63. 'partner_id': self.customer_01.id,
  64. 'lines': [(0, 0, {'product_id': self.product_01.id,
  65. 'price_unit': amount})]
  66. }
  67. return self.pos_order_obj.create(order_vals)
  68. def test_globalization_0(self):
  69. # add payment method
  70. self.main_config.write(
  71. {'journal_ids': [(6, 0, [self.payment_method_02.id])]})
  72. # Create and open a new session
  73. self.session = self.pos_session_obj.create(
  74. {'config_id': self.main_config.id})
  75. self.session.action_pos_session_open()
  76. # config pos payment globalization
  77. self.payment_method_02.pos_payment_globalization = True
  78. self.payment_method_02.pos_payment_globalization_account = \
  79. self.income_account
  80. self.payment_method_02.pos_payment_globalization_journal = \
  81. self.misc_journal
  82. # I create a new orders
  83. order_01 = self.create_order(100, self.session)
  84. order_02 = self.create_order(100, self.session)
  85. # I pay the created order
  86. payment_data1 = {'amount': 100,
  87. 'journal': self.payment_method_02.id,
  88. 'partner_id': order_01.partner_id.id}
  89. payment_data2 = {'amount': 100,
  90. 'journal': self.payment_method_02.id,
  91. 'partner_id': order_02.partner_id.id}
  92. # add payment to orders and pay
  93. order_01.add_payment(payment_data1)
  94. if order_01.test_paid():
  95. order_01.action_pos_order_paid()
  96. order_02.add_payment(payment_data2)
  97. if order_02.test_paid():
  98. order_02.action_pos_order_paid()
  99. # close session
  100. self.session.action_pos_session_closing_control()
  101. move_line = self.move_line_obj.search(
  102. [('account_id', '=', self.income_account.id),
  103. ('journal_id', '=', self.misc_journal.id)])
  104. # I check that there is only one move line
  105. self.assertEqual(len(move_line.ids), 1)
  106. self.assertAlmostEqual(move_line.debit, 200, 2)
  107. domain = [('move_id', '=', move_line.move_id.id),
  108. ('id', '!=', move_line.id)]
  109. reverse_lines = self.move_line_obj.search(domain)
  110. # I ensure that the move contains reverse lines
  111. self.assertEqual(len(reverse_lines), 2)
  112. # I ensure reverse lines are reconciled
  113. not_reconcile_reverse_lines = reverse_lines.filtered(
  114. lambda r: not r.reconciled)
  115. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  116. def test_globalization_1(self):
  117. # add payment method
  118. self.main_config.write(
  119. {'journal_ids': [(6, 0, [self.payment_method_02.id,
  120. self.payment_method_03.id])]
  121. })
  122. # Create and open a new session
  123. self.session = self.pos_session_obj.create(
  124. {'config_id': self.main_config.id})
  125. self.session.action_pos_session_open()
  126. self.payment_method_02.pos_payment_globalization = True
  127. self.payment_method_02.pos_payment_globalization_account = \
  128. self.income_account
  129. self.payment_method_02.pos_payment_globalization_journal = \
  130. self.misc_journal
  131. self.payment_method_03.pos_payment_globalization = True
  132. self.payment_method_03.pos_payment_globalization_account = \
  133. self.income_account_02
  134. self.payment_method_03.pos_payment_globalization_journal = \
  135. self.misc_journal
  136. # I create a new order
  137. order_01 = self.create_order(100, self.session)
  138. order_02 = self.create_order(100, self.session)
  139. # I pay the created order
  140. payment_data1 = {'amount': 100,
  141. 'journal': self.payment_method_02.id,
  142. 'partner_id': order_01.partner_id.id}
  143. payment_data2 = {'amount': 100,
  144. 'journal': self.payment_method_03.id,
  145. 'partner_id': order_02.partner_id.id}
  146. # add payment to orders and pay
  147. order_01.add_payment(payment_data1)
  148. if order_01.test_paid():
  149. order_01.action_pos_order_paid()
  150. order_02.add_payment(payment_data2)
  151. if order_02.test_paid():
  152. order_02.action_pos_order_paid()
  153. # close session
  154. self.session.action_pos_session_closing_control()
  155. # I check the first globalization account
  156. move_line = self.move_line_obj.search(
  157. [('account_id', '=', self.income_account.id),
  158. ('journal_id', '=', self.misc_journal.id)])
  159. # I check that there is only one move line
  160. self.assertEqual(len(move_line.ids), 1)
  161. self.assertAlmostEqual(move_line.debit, 100, 2)
  162. domain = [('move_id', '=', move_line.move_id.id),
  163. ('id', '!=', move_line.id)]
  164. reverse_lines = self.move_line_obj.search(domain)
  165. # I ensure that the move contains reverse lines
  166. self.assertEqual(len(reverse_lines), 1)
  167. # I ensure reverse lines are reconciled
  168. not_reconcile_reverse_lines = reverse_lines.filtered(
  169. lambda r: not r.reconciled)
  170. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  171. # I check the second globalization account
  172. move_line = self.move_line_obj.search(
  173. [('account_id', '=', self.income_account_02.id),
  174. ('journal_id', '=', self.misc_journal.id)])
  175. # I check that there is only one move line
  176. self.assertEqual(len(move_line.ids), 1)
  177. self.assertAlmostEqual(move_line.debit, 100, 2)
  178. domain = [('move_id', '=', move_line.move_id.id),
  179. ('id', '!=', move_line.id)]
  180. reverse_lines = self.move_line_obj.search(domain)
  181. # I ensure that the move contains reverse lines
  182. self.assertEqual(len(reverse_lines), 1)
  183. # I ensure reverse lines are reconciled
  184. not_reconcile_reverse_lines = reverse_lines.filtered(
  185. lambda r: not r.reconciled)
  186. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  187. def test_globalization_2(self):
  188. # add payment method
  189. self.main_config.write({'journal_ids': [(6, 0, [
  190. self.payment_method_02.id, self.payment_method_03.id])]})
  191. # Create and open a new session
  192. self.session = self.pos_session_obj.create(
  193. {'config_id': self.main_config.id})
  194. self.session.action_pos_session_open()
  195. self.payment_method_02.pos_payment_globalization = True
  196. self.payment_method_02.pos_payment_globalization_account = \
  197. self.income_account
  198. self.payment_method_02.pos_payment_globalization_journal = \
  199. self.misc_journal
  200. self.payment_method_03.pos_payment_globalization = True
  201. self.payment_method_03.pos_payment_globalization_account = \
  202. self.income_account_02
  203. self.payment_method_03.pos_payment_globalization_journal = \
  204. self.misc_journal
  205. # create orders
  206. order_01 = self.create_order(100, self.session)
  207. order_02 = self.create_order(100, self.session)
  208. # I pay the created order
  209. payment_data1 = {'amount': 100,
  210. 'journal': self.payment_method_02.id,
  211. 'partner_id': order_01.partner_id.id}
  212. payment_data2 = {'amount': 100,
  213. 'journal': self.payment_method_03.id,
  214. 'partner_id': order_02.partner_id.id}
  215. order_01.add_payment(payment_data1)
  216. if order_01.test_paid():
  217. order_01.action_pos_order_paid()
  218. order_02.add_payment(payment_data2)
  219. if order_02.test_paid():
  220. order_02.action_pos_order_paid()
  221. # close session
  222. self.session.action_pos_session_closing_control()
  223. # I check the first globalization account
  224. move_line = self.move_line_obj.search(
  225. [('account_id', '=', self.income_account.id),
  226. ('journal_id', '=', self.misc_journal.id)])
  227. # I check that there is only one move line
  228. self.assertEqual(len(move_line.ids), 1)
  229. self.assertAlmostEqual(move_line.debit, 100, 2)
  230. domain = [('move_id', '=', move_line.move_id.id),
  231. ('id', '!=', move_line.id)]
  232. reverse_lines = self.move_line_obj.search(domain)
  233. # I ensure that the move contains reverse lines
  234. self.assertEqual(len(reverse_lines), 1)
  235. # I ensure reverse lines are reconciled
  236. not_reconcile_reverse_lines = reverse_lines.filtered(
  237. lambda r: not r.reconciled)
  238. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  239. # I check the second globalization account
  240. move_line = self.move_line_obj.search(
  241. [('account_id', '=', self.income_account_02.id),
  242. ('journal_id', '=', self.misc_journal.id)])
  243. # I check that there is only one move line
  244. self.assertEqual(len(move_line.ids), 1)
  245. self.assertAlmostEqual(move_line.debit, 100, 2)
  246. domain = [('move_id', '=', move_line.move_id.id),
  247. ('id', '!=', move_line.id)]
  248. reverse_lines = self.move_line_obj.search(domain)
  249. # I ensure that the move contains reverse lines
  250. self.assertEqual(len(reverse_lines), 1)
  251. # I ensure reverse lines are reconciled
  252. not_reconcile_reverse_lines = reverse_lines.filtered(
  253. lambda r: not r.reconciled)
  254. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  255. def test_globalization_3(self):
  256. # add payment method
  257. self.main_config.write(
  258. {'journal_ids': [(6, 0, [self.payment_method_02.id,
  259. self.payment_method_03.id])]})
  260. # Create and open a new session
  261. self.session = self.pos_session_obj.create(
  262. {'config_id': self.main_config.id})
  263. self.session.action_pos_session_open()
  264. self.payment_method_02.pos_payment_globalization = True
  265. self.payment_method_02.pos_payment_globalization_account =\
  266. self.income_account
  267. self.payment_method_02.pos_payment_globalization_journal =\
  268. self.misc_journal
  269. self.payment_method_03.pos_payment_globalization = True
  270. self.payment_method_03.pos_payment_globalization_account =\
  271. self.income_account
  272. self.payment_method_03.pos_payment_globalization_journal =\
  273. self.misc_journal_02
  274. # I create orders
  275. order_01 = self.create_order(100, self.session)
  276. order_02 = self.create_order(100, self.session)
  277. # I pay the created orders
  278. payment_data1 = {'amount': 100,
  279. 'journal': self.payment_method_02.id,
  280. 'partner_id': order_02.partner_id.id}
  281. payment_data2 = {'amount': 100,
  282. 'journal': self.payment_method_03.id,
  283. 'partner_id': order_02.partner_id.id}
  284. order_01.add_payment(payment_data1)
  285. if order_01.test_paid():
  286. order_01.action_pos_order_paid()
  287. order_02.add_payment(payment_data2)
  288. if order_02.test_paid():
  289. order_02.action_pos_order_paid()
  290. # close session
  291. self.session.action_pos_session_closing_control()
  292. # I check the first globalization journal
  293. move_line = self.move_line_obj.search(
  294. [('account_id', '=', self.income_account.id),
  295. ('journal_id', '=', self.misc_journal.id)])
  296. # I check that there is only one move line
  297. self.assertEqual(len(move_line.ids), 1)
  298. self.assertAlmostEqual(move_line.debit, 100, 2)
  299. domain = [('move_id', '=', move_line.move_id.id),
  300. ('id', '!=', move_line.id)]
  301. reverse_lines = self.move_line_obj.search(domain)
  302. # I ensure that the move contains reverse lines
  303. self.assertEqual(len(reverse_lines), 1)
  304. # I ensure reverse lines are reconciled
  305. not_reconcile_reverse_lines = reverse_lines.filtered(
  306. lambda r: not r.reconciled)
  307. self.assertEqual(len(not_reconcile_reverse_lines), 0)
  308. # I check the second globalization journal
  309. move_line = self.move_line_obj.search(
  310. [('account_id', '=', self.income_account.id),
  311. ('journal_id', '=', self.misc_journal_02.id)])
  312. # I check that there is only one move line
  313. self.assertEqual(len(move_line.ids), 1)
  314. self.assertAlmostEqual(move_line.debit, 100, 2)
  315. domain = [('move_id', '=', move_line.move_id.id),
  316. ('id', '!=', move_line.id)]
  317. reverse_lines = self.move_line_obj.search(domain)
  318. # I ensure that the move contains reverse lines
  319. self.assertEqual(len(reverse_lines), 1)
  320. # I ensure reverse lines are reconciled
  321. not_reconcile_reverse_lines = reverse_lines.filtered(
  322. lambda r: not r.reconciled)
  323. self.assertEqual(len(not_reconcile_reverse_lines), 0)