test_pos_other_currency_config.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo
  4. from odoo import tools
  5. from odoo.tests.common import Form
  6. from odoo.addons.point_of_sale.tests.common import TestPoSCommon
  7. @odoo.tests.tagged('post_install', '-at_install')
  8. class TestPoSOtherCurrencyConfig(TestPoSCommon):
  9. """ Test PoS with basic configuration
  10. """
  11. def setUp(self):
  12. super(TestPoSOtherCurrencyConfig, self).setUp()
  13. self.config = self.other_currency_config
  14. self.product1 = self.create_product('Product 1', self.categ_basic, 10.0, 5)
  15. self.product2 = self.create_product('Product 2', self.categ_basic, 20.0, 10)
  16. self.product3 = self.create_product('Product 3', self.categ_basic, 30.0, 15)
  17. self.product4 = self.create_product('Product 4', self.categ_anglo, 100, 50)
  18. self.product5 = self.create_product('Product 5', self.categ_anglo, 200, 70)
  19. self.product6 = self.create_product('Product 6', self.categ_anglo, 45.3, 10.73)
  20. self.product7 = self.create_product('Product 7', self.categ_basic, 7, 7, tax_ids=self.taxes['tax7'].ids)
  21. self.adjust_inventory(
  22. [self.product1, self.product2, self.product3, self.product4, self.product5, self.product6, self.product7],
  23. [100, 50, 50, 100, 100, 100, 100]
  24. )
  25. # change the price of product2 to 12.99 fixed. No need to convert.
  26. pricelist_item = self.env['product.pricelist.item'].create({
  27. 'product_tmpl_id': self.product2.product_tmpl_id.id,
  28. 'fixed_price': 12.99,
  29. })
  30. self.config.pricelist_id.write({'item_ids': [(6, 0, (self.config.pricelist_id.item_ids | pricelist_item).ids)]})
  31. self.output_account = self.categ_anglo.property_stock_account_output_categ_id
  32. self.expense_account = self.categ_anglo.property_account_expense_categ_id
  33. def test_01_check_product_cost(self):
  34. # Product price should be half of the original price because currency rate is 0.5.
  35. # (see `self._create_other_currency_config` method)
  36. # Except for product2 where the price is specified in the pricelist.
  37. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product1, 1), 5.00)
  38. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product2, 1), 12.99)
  39. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product3, 1), 15.00)
  40. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product4, 1), 50)
  41. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product5, 1), 100)
  42. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product6, 1), 22.65)
  43. self.assertAlmostEqual(self.config.pricelist_id._get_product_price(self.product7, 1), 3.50)
  44. def test_02_orders_without_invoice(self):
  45. """ orders without invoice
  46. Orders
  47. ======
  48. +---------+----------+-----------+----------+-----+-------+
  49. | order | payments | invoiced? | product | qty | total |
  50. +---------+----------+-----------+----------+-----+-------+
  51. | order 1 | cash | no | product1 | 10 | 50 |
  52. | | | | product2 | 10 | 129.9 |
  53. | | | | product3 | 10 | 150 |
  54. +---------+----------+-----------+----------+-----+-------+
  55. | order 2 | cash | no | product1 | 5 | 25 |
  56. | | | | product2 | 5 | 64.95 |
  57. +---------+----------+-----------+----------+-----+-------+
  58. | order 3 | bank | no | product2 | 5 | 64.95 |
  59. | | | | product3 | 5 | 75 |
  60. +---------+----------+-----------+----------+-----+-------+
  61. Expected Result
  62. ===============
  63. +---------------------+---------+-----------------+
  64. | account | balance | amount_currency |
  65. +---------------------+---------+-----------------+
  66. | sale_account | -1119.6 | -559.80 |
  67. | pos receivable bank | 279.9 | 139.95 |
  68. | pos receivable cash | 839.7 | 419.85 |
  69. +---------------------+---------+-----------------+
  70. | Total balance | 0.0 | 0.00 |
  71. +---------------------+---------+-----------------+
  72. """
  73. def _before_closing_cb():
  74. # check values before closing the session
  75. self.assertEqual(3, self.pos_session.order_count)
  76. orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
  77. self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
  78. self._run_test({
  79. 'payment_methods': self.cash_pm2 | self.bank_pm2,
  80. 'orders': [
  81. {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uid': '00100-010-0001'},
  82. {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'uid': '00100-010-0002'},
  83. {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm2, 139.95)], 'uid': '00100-010-0003'},
  84. ],
  85. 'before_closing_cb': _before_closing_cb,
  86. 'journal_entries_before_closing': {},
  87. 'journal_entries_after_closing': {
  88. 'session_journal_entry': {
  89. 'line_ids': [
  90. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 1119.6, 'reconciled': False, 'amount_currency': -559.80},
  91. {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': True, 'amount_currency': 139.95},
  92. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': True, 'amount_currency': 419.85},
  93. ],
  94. },
  95. 'cash_statement': [
  96. ((419.85, ), {
  97. 'line_ids': [
  98. {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': False, 'amount_currency': 419.85},
  99. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 839.7, 'reconciled': True, 'amount_currency': -419.85},
  100. ]
  101. }),
  102. ],
  103. 'bank_payments': [
  104. ((139.95, ), {
  105. 'line_ids': [
  106. {'account_id': self.bank_pm2.outstanding_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
  107. {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
  108. ]
  109. }),
  110. ],
  111. },
  112. })
  113. def test_03_orders_with_invoice(self):
  114. """ orders with invoice
  115. Orders
  116. ======
  117. +---------+----------+---------------+----------+-----+-------+
  118. | order | payments | invoiced? | product | qty | total |
  119. +---------+----------+---------------+----------+-----+-------+
  120. | order 1 | cash | no | product1 | 10 | 50 |
  121. | | | | product2 | 10 | 129.9 |
  122. | | | | product3 | 10 | 150 |
  123. +---------+----------+---------------+----------+-----+-------+
  124. | order 2 | cash | yes, customer | product1 | 5 | 25 |
  125. | | | | product2 | 5 | 64.95 |
  126. +---------+----------+---------------+----------+-----+-------+
  127. | order 3 | bank | yes, customer | product2 | 5 | 64.95 |
  128. | | | | product3 | 5 | 75 |
  129. +---------+----------+---------------+----------+-----+-------+
  130. Expected Result
  131. ===============
  132. +---------------------+---------+-----------------+
  133. | account | balance | amount_currency |
  134. +---------------------+---------+-----------------+
  135. | sale_account | -659.8 | -329.90 |
  136. | pos receivable bank | 279.9 | 139.95 |
  137. | pos receivable cash | 839.7 | 419.85 |
  138. | invoice receivable | -179.9 | -89.95 |
  139. | invoice receivable | -279.9 | -139.95 |
  140. +---------------------+---------+-----------------+
  141. | Total balance | 0.0 | 0.00 |
  142. +---------------------+---------+-----------------+
  143. """
  144. def _before_closing_cb():
  145. # check values before closing the session
  146. self.assertEqual(3, self.pos_session.order_count)
  147. orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
  148. self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
  149. self._run_test({
  150. 'payment_methods': self.cash_pm2 | self.bank_pm2,
  151. 'orders': [
  152. {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uid': '00100-010-0001'},
  153. {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'is_invoiced': True, 'customer': self.customer, 'uid': '00100-010-0002'},
  154. {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm2, 139.95)], 'is_invoiced': True, 'customer': self.customer, 'uid': '00100-010-0003'},
  155. ],
  156. 'before_closing_cb': _before_closing_cb,
  157. 'journal_entries_before_closing': {
  158. '00100-010-0002': {
  159. 'payments': [
  160. ((self.cash_pm2, 89.95), {
  161. 'line_ids': [
  162. {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 179.90, 'reconciled': True, 'amount_currency': -89.95},
  163. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 179.90, 'credit': 0, 'reconciled': False, 'amount_currency': 89.95},
  164. ]
  165. }),
  166. ],
  167. },
  168. '00100-010-0003': {
  169. 'payments': [
  170. ((self.bank_pm2, 139.95), {
  171. 'line_ids': [
  172. {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
  173. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
  174. ]
  175. }),
  176. ],
  177. },
  178. },
  179. 'journal_entries_after_closing': {
  180. 'session_journal_entry': {
  181. 'line_ids': [
  182. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 659.8, 'reconciled': False, 'amount_currency': -329.90},
  183. {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': True, 'amount_currency': 139.95},
  184. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': True, 'amount_currency': 419.85},
  185. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 179.90, 'reconciled': True, 'amount_currency': -89.95},
  186. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
  187. ],
  188. },
  189. 'cash_statement': [
  190. ((419.85, ), {
  191. 'line_ids': [
  192. {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 839.7, 'credit': 0, 'reconciled': False, 'amount_currency': 419.85},
  193. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 839.7, 'reconciled': True, 'amount_currency': -419.85},
  194. ]
  195. }),
  196. ],
  197. 'bank_payments': [
  198. ((139.95, ), {
  199. 'line_ids': [
  200. {'account_id': self.bank_pm2.outstanding_account_id.id, 'partner_id': False, 'debit': 279.9, 'credit': 0, 'reconciled': False, 'amount_currency': 139.95},
  201. {'account_id': self.bank_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 279.9, 'reconciled': True, 'amount_currency': -139.95},
  202. ]
  203. }),
  204. ],
  205. },
  206. })
  207. def test_04_anglo_saxon_products(self):
  208. """
  209. ======
  210. Orders
  211. ======
  212. +---------+----------+-----------+----------+-----+----------+------------+
  213. | order | payments | invoiced? | product | qty | total | total cost |
  214. | | | | | | | |
  215. +---------+----------+-----------+----------+-----+----------+------------+
  216. | order 1 | cash | no | product4 | 7 | 700 | 350 |
  217. | | | | product5 | 7 | 1400 | 490 |
  218. +---------+----------+-----------+----------+-----+----------+------------+
  219. | order 2 | cash | no | product5 | 6 | 1200 | 420 |
  220. | | | | product4 | 6 | 600 | 300 |
  221. | | | | product6 | 49 | 2219.7 | 525.77 |
  222. +---------+----------+-----------+----------+-----+----------+------------+
  223. | order 3 | cash | no | product5 | 2 | 400 | 140 |
  224. | | | | product6 | 13 | 588.9 | 139.49 |
  225. +---------+----------+-----------+----------+-----+----------+------------+
  226. | order 4 | cash | no | product6 | 1 | 45.3 | 10.73 |
  227. +---------+----------+-----------+----------+-----+----------+------------+
  228. ===============
  229. Expected Result
  230. ===============
  231. +---------------------+------------+-----------------+
  232. | account | balance | amount_currency |
  233. +---------------------+------------+-----------------+
  234. | sale_account | -7153.90 | -3576.95 |
  235. | pos_receivable-cash | 7153.90 | 3576.95 |
  236. | expense_account | 2375.99 | 2375.99 |
  237. | output_account | -2375.99 | -2375.99 |
  238. +---------------------+------------+-----------------+
  239. | Total balance | 0.00 | 0.00 |
  240. +---------------------+------------+-----------------+
  241. """
  242. self._run_test({
  243. 'payment_methods': self.cash_pm2,
  244. 'orders': [
  245. {'pos_order_lines_ui_args': [(self.product4, 7), (self.product5, 7)], 'uid': '00100-010-0001'},
  246. {'pos_order_lines_ui_args': [(self.product5, 6), (self.product4, 6), (self.product6, 49)], 'uid': '00100-010-0002'},
  247. {'pos_order_lines_ui_args': [(self.product5, 2), (self.product6, 13)], 'uid': '00100-010-0003'},
  248. {'pos_order_lines_ui_args': [(self.product6, 1)], 'uid': '00100-010-0004'},
  249. ],
  250. 'journal_entries_before_closing': {},
  251. 'journal_entries_after_closing': {
  252. 'session_journal_entry': {
  253. 'line_ids': [
  254. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 7153.90, 'reconciled': False, 'amount_currency': -3576.95},
  255. {'account_id': self.expense_account.id, 'partner_id': False, 'debit': 2375.99, 'credit': 0, 'reconciled': False, 'amount_currency': 2375.99},
  256. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 7153.90, 'credit': 0, 'reconciled': True, 'amount_currency': 3576.95},
  257. {'account_id': self.output_account.id, 'partner_id': False, 'debit': 0, 'credit': 2375.99, 'reconciled': True, 'amount_currency': -2375.99},
  258. ],
  259. },
  260. 'cash_statement': [
  261. ((3576.95, ), {
  262. 'line_ids': [
  263. {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 7153.90, 'credit': 0, 'reconciled': False, 'amount_currency': 3576.95},
  264. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 7153.90, 'reconciled': True, 'amount_currency': -3576.95},
  265. ]
  266. }),
  267. ],
  268. 'bank_payments': [],
  269. },
  270. })
  271. def test_05_tax_base_amount(self):
  272. self._run_test({
  273. 'payment_methods': self.cash_pm2,
  274. 'orders': [
  275. {'pos_order_lines_ui_args': [(self.product7, 7)], 'uid': '00100-010-0001'},
  276. ],
  277. 'journal_entries_before_closing': {},
  278. 'journal_entries_after_closing': {
  279. 'session_journal_entry': {
  280. 'line_ids': [
  281. {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 3.43, 'reconciled': False, 'amount_currency': -1.715, 'tax_base_amount': 49},
  282. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 49, 'reconciled': False, 'amount_currency': -24.5, 'tax_base_amount': 0},
  283. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 52.43, 'credit': 0, 'reconciled': True, 'amount_currency': 26.215, 'tax_base_amount': 0},
  284. ],
  285. },
  286. 'cash_statement': [
  287. ((26.215, ), {
  288. 'line_ids': [
  289. {'account_id': self.cash_pm2.journal_id.default_account_id.id, 'partner_id': False, 'debit': 52.43, 'credit': 0, 'reconciled': False, 'amount_currency': 26.215},
  290. {'account_id': self.cash_pm2.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 52.43, 'reconciled': True, 'amount_currency': -26.215},
  291. ]
  292. }),
  293. ],
  294. 'bank_payments': [],
  295. },
  296. })