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.

75 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 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 TestPosAnalyticConfig(common.TransactionCase):
  6. def setUp(self):
  7. super(TestPosAnalyticConfig, self).setUp()
  8. self.pos_order_obj = self.env['pos.order']
  9. self.pos_conig_obj = self.env['pos.config']
  10. self.pos_session_obj = self.env['pos.session']
  11. self.aml_obj = self.env['account.move.line']
  12. self.inv_line_obj = self.env['account.invoice.line']
  13. self.main_config = self.env.ref('point_of_sale.pos_config_main')
  14. self.aa_01 = self.env.ref('account.analytic_root')
  15. self.customer_01 = self.env.ref('base.res_partner_2')
  16. self.product_01 =\
  17. self.env.ref('point_of_sale.perrier_50cl')
  18. self.payment_method_01 = self.env.ref('account.bank_journal')
  19. self.aml_analytic_domain =\
  20. [('product_id', '=', self.product_01.id),
  21. ('analytic_account_id', '=', self.aa_01.id)]
  22. self.inv_analytic_domain =\
  23. [('product_id', '=', self.product_01.id),
  24. ('account_analytic_id', '=', self.aa_01.id)]
  25. def common_test(self):
  26. self.main_config.account_analytic_id = self.aa_01
  27. # I create and open a new session
  28. self.session_01 = self.pos_session_obj.create(
  29. {'config_id': self.main_config.id})
  30. ctx = self.env.context.copy()
  31. # context is updated in open_cb
  32. # -> Need to call with old api to give unfrozen context
  33. self.registry['pos.session'].open_cb(
  34. self.cr, self.uid, [self.session_01.id], context=ctx)
  35. # I create a new order
  36. order_vals = {
  37. 'session_id': self.session_01.id,
  38. 'partner_id': self.customer_01.id,
  39. 'lines': [(0, 0, {'product_id': self.product_01.id,
  40. 'price_unit': 10.0,
  41. })]
  42. }
  43. self.order_01 = self.pos_order_obj.create(order_vals)
  44. # I pay the created order
  45. payment_data = {'amount': 10,
  46. 'journal': self.payment_method_01.id}
  47. self.pos_order_obj.add_payment(self.order_01.id, payment_data)
  48. if self.order_01.test_paid():
  49. self.order_01.signal_workflow('paid')
  50. def test_order_simple_receipt(self):
  51. self.common_test()
  52. aml = self.aml_obj.search(self.aml_analytic_domain)
  53. # I check that there isn't lines with the analytic account in this test
  54. self.assertEqual(len(aml.ids), 0)
  55. self.session_01.signal_workflow('close')
  56. # I check that there is a journal item with the config analytic account
  57. aml = self.aml_obj.search(self.aml_analytic_domain)
  58. self.assertEqual(len(aml.ids), 1)
  59. def test_order_invoice(self):
  60. self.common_test()
  61. lines = self.inv_line_obj.search(self.inv_analytic_domain)
  62. self.order_01.action_invoice()
  63. # I check that there isn't lines with the analytic account in this test
  64. self.assertEqual(len(lines.ids), 0)
  65. lines = self.inv_line_obj.search(self.inv_analytic_domain)
  66. # I check that there is an invoice line
  67. # with the config analytic account
  68. self.assertEqual(len(lines.ids), 1)