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.

79 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Eficent Business and IT Consulting Services S.L.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from . import abstract_test
  6. _logger = logging.getLogger(__name__)
  7. class AbstractTestForeignCurrency(abstract_test.AbstractTest):
  8. """Common technical tests for all reports."""
  9. def _chart_template_create(self):
  10. super(AbstractTestForeignCurrency, self)._chart_template_create()
  11. # Account for foreign payments
  12. self.account_type_other = self.env['account.account.type'].create(
  13. {'name': 'foreign expenses',
  14. 'type': 'other',
  15. })
  16. act = self.env['account.account.template'].create({
  17. 'code': '0012',
  18. 'name': 'Foreign Expenses',
  19. 'user_type_id': self.account_type_other.id,
  20. 'chart_template_id': self.chart.id,
  21. 'currency_id': self.env.ref('base.EUR').id,
  22. })
  23. self.env['ir.model.data'].create({
  24. 'res_id': act.id,
  25. 'model': act._name,
  26. 'name': 'foreign expenses',
  27. })
  28. return True
  29. def _add_chart_of_accounts(self):
  30. super(AbstractTestForeignCurrency, self)._add_chart_of_accounts()
  31. self.foreign_expense = self.env['account.account'].search(
  32. [('currency_id', '=', self.env.ref('base.EUR').id)], limit=1)
  33. self.foreign_currency_id = self.foreign_expense.currency_id
  34. return True
  35. def _journals_create(self):
  36. super(AbstractTestForeignCurrency, self)._journals_create()
  37. self.journal_foreign_purchases = self.env['account.journal'].create({
  38. 'company_id': self.company.id,
  39. 'name': 'Test journal for purchase',
  40. 'type': 'purchase',
  41. 'code': 'TFORPUR',
  42. 'default_debit_account_id': self.foreign_expense.id,
  43. 'default_credit_account_id': self.foreign_expense.id,
  44. 'currency_id': self.foreign_currency_id.id,
  45. })
  46. return True
  47. def _invoice_create(self):
  48. super(AbstractTestForeignCurrency, self)._invoice_create()
  49. # vendor bill foreign currency
  50. foreign_vendor_invoice_lines = [(0, False, {
  51. 'name': 'Test description #1',
  52. 'account_id': self.revenue.id,
  53. 'quantity': 1.0,
  54. 'price_unit': 100.0,
  55. 'currency_id': self.foreign_currency_id.id,
  56. }), (0, False, {
  57. 'name': 'Test description #2',
  58. 'account_id': self.revenue.id,
  59. 'quantity': 2.0,
  60. 'price_unit': 25.0,
  61. 'currency_id': self.foreign_currency_id.id,
  62. })]
  63. self.foreign_invoice_in = self.env['account.invoice'].create({
  64. 'partner_id': self.partner.id,
  65. 'type': 'in_invoice',
  66. 'invoice_line_ids': foreign_vendor_invoice_lines,
  67. 'account_id': self.partner.property_account_payable_id.id,
  68. 'journal_id': self.journal_foreign_purchases.id,
  69. })
  70. self.foreign_invoice_in.action_invoice_open()
  71. return True