test_account_invoice_merge.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2009-2017 Noviat.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.exceptions import Warning as UserError
  6. class TestAccountInvoiceMerge(TransactionCase):
  7. def setUp(self):
  8. super(TestAccountInvoiceMerge, self).setUp()
  9. self.wiz_model = self.env['invoice.merge']
  10. self.wiz_context = {'active_model': 'account.invoice'}
  11. self.invoice_model = self.env['account.invoice']
  12. self.account_payable = self.env.ref('account.a_pay')
  13. self.partner_1 = self.env.ref('base.res_partner_1')
  14. self.partner_2 = self.env.ref('base.res_partner_2')
  15. self.supplier_invoice_1 = self.invoice_model.create(
  16. {'journal_id': self.env.ref('account.expenses_journal').id,
  17. 'type': 'in_invoice',
  18. 'partner_id': self.partner_1.id,
  19. 'account_id': self.account_payable.id,
  20. 'invoice_line': [(0, 0, {'name': 'Inv 1 - Line 1',
  21. 'price_unit': 100.0})],
  22. })
  23. self.supplier_invoice_2 = self.invoice_model.create(
  24. {'journal_id': self.env.ref('account.expenses_journal').id,
  25. 'type': 'in_invoice',
  26. 'partner_id': self.partner_1.id,
  27. 'account_id': self.account_payable.id,
  28. 'invoice_line': [(0, 0, {'name': 'Inv 2 - Line 1',
  29. 'price_unit': 150.0})],
  30. })
  31. self.supplier_invoice_3 = self.invoice_model.create(
  32. {'journal_id': self.env.ref('account.expenses_journal').id,
  33. 'type': 'in_invoice',
  34. 'partner_id': self.partner_2.id,
  35. 'account_id': self.account_payable.id,
  36. 'invoice_line': [(0, 0, {'name': 'Inv 3 - Line 1',
  37. 'price_unit': 50.0})],
  38. })
  39. def test_invoice_merge(self):
  40. invoices = self.supplier_invoice_1 + self.supplier_invoice_2
  41. invoices_info, invoice_lines_info = invoices.do_merge()
  42. for k in invoices_info:
  43. new_inv = self.invoice_model.browse(k)
  44. self.assertEqual(new_inv.amount_total, 250.0)
  45. new_inv_line_ids = invoice_lines_info[k].values()
  46. self.assertEqual(
  47. len(new_inv_line_ids), len(new_inv.invoice_line._ids),
  48. "Incorrect Invoice Line Mapping")
  49. def test_invoice_merge_wizard(self):
  50. invoices = self.supplier_invoice_1 + self.supplier_invoice_2
  51. ctx = dict(self.wiz_context, active_ids=invoices._ids)
  52. wiz = self.wiz_model.with_context(ctx).create({})
  53. act = wiz.merge_invoices()
  54. self.assertEqual(
  55. len(act['domain'][0][2]), 3, "Error in invoice.merge wizard")
  56. def test_dirty_check(self):
  57. invoices = self.supplier_invoice_1 + self.supplier_invoice_3
  58. ctx = dict(self.wiz_context, active_ids=invoices._ids)
  59. wiz = self.wiz_model.with_context(ctx).create({})
  60. with self.assertRaises(UserError):
  61. wiz._dirty_check()