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.

78 lines
3.0 KiB

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