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.

85 lines
2.9 KiB

  1. # Copyright 2019-2020 Brainbean Apps (https://brainbeanapps.com)
  2. # Copyright 2019-2020 Dataplug (https://dataplug.io)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from datetime import datetime, timedelta
  5. from dateutil.relativedelta import relativedelta
  6. from pytz import timezone
  7. from random import randrange
  8. from odoo import api, fields, models
  9. class OnlineBankStatementProviderDummy(models.Model):
  10. _inherit = 'online.bank.statement.provider'
  11. @api.multi
  12. def _obtain_statement_data(self, date_since, date_until):
  13. self.ensure_one()
  14. if self.service != 'dummy':
  15. return super()._obtain_statement_data(
  16. date_since,
  17. date_until,
  18. ) # pragma: no cover
  19. if self.env.context.get('crash', False):
  20. exception = self.env.context.get(
  21. 'exception',
  22. Exception('Expected')
  23. )
  24. raise exception
  25. line_step_options = self.env.context.get('step', {
  26. 'minutes': 5,
  27. })
  28. line_step = relativedelta(**line_step_options)
  29. expand_by = self.env.context.get('expand_by', 0)
  30. data_since = self.env.context.get('data_since', date_since)
  31. data_until = self.env.context.get('data_until', date_until)
  32. data_since -= expand_by * line_step
  33. data_until += expand_by * line_step
  34. balance_start = self.env.context.get(
  35. 'balance_start',
  36. randrange(-10000, 10000, 1) * 0.1
  37. )
  38. balance = balance_start
  39. tz = self.env.context.get('tz')
  40. if tz:
  41. tz = timezone(tz)
  42. timestamp_mode = self.env.context.get('timestamp_mode')
  43. lines = []
  44. date = data_since
  45. while date < data_until:
  46. amount = self.env.context.get(
  47. 'amount',
  48. randrange(-100, 100, 1) * 0.1
  49. )
  50. transaction_date = date.replace(tzinfo=tz)
  51. if timestamp_mode == 'date':
  52. transaction_date = transaction_date.date()
  53. elif timestamp_mode == 'str':
  54. transaction_date = fields.Datetime.to_string(transaction_date)
  55. lines.append({
  56. 'name': 'payment',
  57. 'amount': amount,
  58. 'date': transaction_date,
  59. 'unique_import_id': str(int(
  60. (date - datetime(1970, 1, 1)) / timedelta(seconds=1)
  61. )),
  62. 'partner_name': 'John Doe',
  63. 'account_number': 'XX00 0000 0000 0000',
  64. })
  65. balance += amount
  66. date += line_step
  67. balance_end = balance
  68. statement = {}
  69. if self.env.context.get('balance', True):
  70. statement.update({
  71. 'balance_start': balance_start,
  72. 'balance_end_real': balance_end,
  73. })
  74. return lines, statement