test_pos_multiple_receivable_accounts.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.addons.point_of_sale.tests.common import TestPoSCommon
  6. @odoo.tests.tagged('post_install', '-at_install')
  7. class TestPoSMultipleReceivableAccounts(TestPoSCommon):
  8. """ Test for invoiced orders with customers having receivable account different from default
  9. Thus, for this test, there are two receivable accounts involved and are set in the
  10. customers.
  11. self.customer -> self.receivable_account
  12. self.other_customer -> self.other_receivable_account
  13. ADDITIONALLY, this tests different sales account on the products.
  14. NOTE That both receivable accounts above are different from the pos receivable account.
  15. """
  16. def setUp(self):
  17. super(TestPoSMultipleReceivableAccounts, self).setUp()
  18. self.config = self.basic_config
  19. self.product1 = self.create_product(
  20. 'Product 1',
  21. self.categ_basic,
  22. lst_price=10.99,
  23. standard_price=5.0,
  24. tax_ids=self.taxes['tax7'].ids,
  25. )
  26. self.product2 = self.create_product(
  27. 'Product 2',
  28. self.categ_basic,
  29. lst_price=19.99,
  30. standard_price=10.0,
  31. tax_ids=self.taxes['tax10'].ids,
  32. sale_account=self.other_sale_account,
  33. )
  34. self.product3 = self.create_product(
  35. 'Product 3',
  36. self.categ_basic,
  37. lst_price=30.99,
  38. standard_price=15.0,
  39. tax_ids=self.taxes['tax_group_7_10'].ids,
  40. )
  41. self.adjust_inventory([self.product1, self.product2, self.product3], [100, 50, 50])
  42. def test_01_invoiced_order_from_other_customer(self):
  43. """
  44. Orders
  45. ======
  46. +---------+----------+-----------+----------+-----+---------+--------------------------+--------+
  47. | order | payments | invoiced? | product | qty | untaxed | tax | total |
  48. +---------+----------+-----------+----------+-----+---------+--------------------------+--------+
  49. | order 1 | cash | no | product1 | 10 | 109.9 | 7.69 [7%] | 117.59 |
  50. | | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.9 |
  51. | | | | product3 | 10 | 281.73 | 19.72 [7%] + 28.17 [10%] | 329.62 |
  52. +---------+----------+-----------+----------+-----+---------+--------------------------+--------+
  53. | order 2 | bank | no | product1 | 5 | 54.95 | 3.85 [7%] | 58.80 |
  54. | | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
  55. +---------+----------+-----------+----------+-----+---------+--------------------------+--------+
  56. | order 3 | bank | yes | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
  57. | | | | product3 | 5 | 140.86 | 9.86 [7%] + 14.09 [10%] | 164.81 |
  58. +---------+----------+-----------+----------+-----+---------+--------------------------+--------+
  59. Expected Result
  60. ===============
  61. +---------------------+---------+
  62. | account | balance |
  63. +---------------------+---------+
  64. | sale_account | -164.85 |
  65. | sale_account | -281.73 |
  66. | other_sale_account | -272.59 |
  67. | tax 7% | -31.26 |
  68. | tax 10% | -55.43 |
  69. | pos receivable cash | 647.11 |
  70. | pos receivable bank | 423.51 |
  71. | other receivable | -264.76 |
  72. +---------------------+---------+
  73. | Total balance | 0.00 |
  74. +---------------------+---------+
  75. """
  76. def _before_closing_cb():
  77. # check values before closing the session
  78. self.assertEqual(3, self.pos_session.order_count)
  79. orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
  80. self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
  81. # check if there is one invoiced order
  82. self.assertEqual(len(self.pos_session.order_ids.filtered(lambda order: order.state == 'invoiced')), 1, 'There should only be one invoiced order.')
  83. self._run_test({
  84. 'payment_methods': self.cash_pm1 | self.bank_pm1,
  85. 'orders': [
  86. {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'uid': '00100-010-0001'},
  87. {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'payments': [(self.bank_pm1, 158.75)], 'uid': '00100-010-0002'},
  88. {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 264.76)], 'is_invoiced': True, 'customer': self.other_customer, 'uid': '09876-098-0987'},
  89. ],
  90. 'before_closing_cb': _before_closing_cb,
  91. 'journal_entries_before_closing': {
  92. '09876-098-0987': {
  93. 'invoice': {
  94. 'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account,
  95. 'line_ids': [
  96. {'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False},
  97. {'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 140.86, 'reconciled': False},
  98. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 264.76, 'credit': 0, 'reconciled': True},
  99. ]
  100. },
  101. 'payments': [
  102. ((self.bank_pm1, 264.76), {
  103. 'line_ids': [
  104. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 264.76, 'reconciled': True},
  105. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 264.76, 'credit': 0, 'reconciled': False},
  106. ]
  107. }),
  108. ],
  109. }
  110. },
  111. 'journal_entries_after_closing': {
  112. 'session_journal_entry': {
  113. 'line_ids': [
  114. {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 31.26, 'reconciled': False},
  115. {'account_id': self.tax_received_account.id, 'partner_id': False, 'debit': 0, 'credit': 55.43, 'reconciled': False},
  116. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 164.85, 'reconciled': False},
  117. {'account_id': self.other_sale_account.id, 'partner_id': False, 'debit': 0, 'credit': 272.59, 'reconciled': False},
  118. {'account_id': self.sales_account.id, 'partner_id': False, 'debit': 0, 'credit': 281.73, 'reconciled': False},
  119. {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': True},
  120. {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': True},
  121. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 264.76, 'reconciled': True},
  122. ],
  123. },
  124. 'cash_statement': [
  125. ((647.11, ), {
  126. 'line_ids': [
  127. {'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False},
  128. {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True},
  129. ]
  130. }),
  131. ],
  132. 'bank_payments': [
  133. ((423.51, ), {
  134. 'line_ids': [
  135. {'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': False},
  136. {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True},
  137. ]
  138. }),
  139. ],
  140. },
  141. })
  142. def test_02_all_orders_invoiced_mixed_customers(self):
  143. """
  144. Orders
  145. ======
  146. +---------+----------+---------------------+----------+-----+---------+--------------------------+--------+
  147. | order | payments | invoiced? | product | qty | untaxed | tax | total |
  148. +---------+----------+---------------------+----------+-----+---------+--------------------------+--------+
  149. | order 1 | cash | yes, other_customer | product1 | 10 | 109.90 | 7.69 [7%] | 117.59 |
  150. | | | | product2 | 10 | 181.73 | 18.17 [10%] | 199.90 |
  151. | | | | product3 | 10 | 281.73 | 19.72 [7%] + 28.17 [10%] | 329.62 |
  152. +---------+----------+---------------------+----------+-----+---------+--------------------------+--------+
  153. | order 2 | bank | yes, customer | product1 | 5 | 54.95 | 3.85 [7%] | 58.80 |
  154. | | | | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
  155. +---------+----------+---------------------+----------+-----+---------+--------------------------+--------+
  156. | order 3 | bank | yes, other customer | product2 | 5 | 90.86 | 9.09 [10%] | 99.95 |
  157. | | | | product3 | 5 | 140.86 | 9.86 [7%] + 14.09 [10%] | 164.81 |
  158. +---------+----------+---------------------+----------+-----+---------+--------------------------+--------+
  159. Expected Result
  160. ===============
  161. +----------------------+---------+
  162. | account | balance |
  163. +----------------------+---------+
  164. | pos receivable cash | 647.11 |
  165. | pos receivable bank | 423.51 |
  166. | received bank | -423.51 |
  167. | received cash | -647.11 |
  168. +----------------------+---------+
  169. | Total balance | 0.00 |
  170. +----------------------+---------+
  171. """
  172. def _before_closing_cb():
  173. # check values before closing the session
  174. self.assertEqual(3, self.pos_session.order_count)
  175. orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
  176. self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
  177. # check if there is one invoiced order
  178. self.assertEqual(len(self.pos_session.order_ids.filtered(lambda order: order.state == 'invoiced')), 3, 'All orders should be invoiced.')
  179. self._run_test({
  180. 'payment_methods': self.cash_pm1 | self.bank_pm1,
  181. 'orders': [
  182. {'pos_order_lines_ui_args': [(self.product1, 10), (self.product2, 10), (self.product3, 10)], 'is_invoiced': True, 'customer': self.other_customer, 'uid': '09876-098-0987'},
  183. {'pos_order_lines_ui_args': [(self.product1, 5), (self.product2, 5)], 'payments': [(self.bank_pm1, 158.75)], 'is_invoiced': True, 'customer': self.customer, 'uid': '09876-098-0988'},
  184. {'pos_order_lines_ui_args': [(self.product2, 5), (self.product3, 5)], 'payments': [(self.bank_pm1, 264.76)], 'is_invoiced': True, 'customer': self.other_customer, 'uid': '09876-098-0989'},
  185. ],
  186. 'before_closing_cb': _before_closing_cb,
  187. 'journal_entries_before_closing': {
  188. '09876-098-0987': {
  189. 'invoice': {
  190. 'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account,
  191. 'line_ids': [
  192. {'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 109.90, 'reconciled': False},
  193. {'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 181.73, 'reconciled': False},
  194. {'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 281.73, 'reconciled': False},
  195. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 647.11, 'credit': 0, 'reconciled': True},
  196. ]
  197. },
  198. 'payments': [
  199. ((self.cash_pm1, 647.11), {
  200. 'line_ids': [
  201. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 647.11, 'reconciled': True},
  202. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False},
  203. ]
  204. }),
  205. ],
  206. },
  207. '09876-098-0988': {
  208. 'invoice': {
  209. 'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.c1_receivable,
  210. 'line_ids': [
  211. {'account_id': self.sales_account.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 54.95, 'reconciled': False},
  212. {'account_id': self.other_sale_account.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False},
  213. {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 158.75, 'credit': 0, 'reconciled': True},
  214. ]
  215. },
  216. 'payments': [
  217. ((self.bank_pm1, 158.75), {
  218. 'line_ids': [
  219. {'account_id': self.c1_receivable.id, 'partner_id': self.customer.id, 'debit': 0, 'credit': 158.75, 'reconciled': True},
  220. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 158.75, 'credit': 0, 'reconciled': False},
  221. ]
  222. }),
  223. ],
  224. },
  225. '09876-098-0989': {
  226. 'invoice': {
  227. 'line_ids_predicate': lambda line: line.account_id in self.other_sale_account | self.sales_account | self.other_receivable_account,
  228. 'line_ids': [
  229. {'account_id': self.other_sale_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 90.86, 'reconciled': False},
  230. {'account_id': self.sales_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 140.86, 'reconciled': False},
  231. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 264.76, 'credit': 0, 'reconciled': True},
  232. ]
  233. },
  234. 'payments': [
  235. ((self.bank_pm1, 264.76), {
  236. 'line_ids': [
  237. {'account_id': self.other_receivable_account.id, 'partner_id': self.other_customer.id, 'debit': 0, 'credit': 264.76, 'reconciled': True},
  238. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 264.76, 'credit': 0, 'reconciled': False},
  239. ]
  240. }),
  241. ],
  242. },
  243. },
  244. 'journal_entries_after_closing': {
  245. 'session_journal_entry': {
  246. 'line_ids': [
  247. {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': True},
  248. {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': True},
  249. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True},
  250. {'account_id': self.pos_receivable_account.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True},
  251. ],
  252. },
  253. 'cash_statement': [
  254. ((647.11, ), {
  255. 'line_ids': [
  256. {'account_id': self.cash_pm1.journal_id.default_account_id.id, 'partner_id': False, 'debit': 647.11, 'credit': 0, 'reconciled': False},
  257. {'account_id': self.cash_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 647.11, 'reconciled': True},
  258. ]
  259. }),
  260. ],
  261. 'bank_payments': [
  262. ((423.51, ), {
  263. 'line_ids': [
  264. {'account_id': self.bank_pm1.outstanding_account_id.id, 'partner_id': False, 'debit': 423.51, 'credit': 0, 'reconciled': False},
  265. {'account_id': self.bank_pm1.receivable_account_id.id, 'partner_id': False, 'debit': 0, 'credit': 423.51, 'reconciled': True},
  266. ]
  267. }),
  268. ],
  269. },
  270. })