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.

366 lines
15 KiB

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