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.

110 lines
3.5 KiB

  1. # Copyright 2019 Tecnativa - Vicent Cubells
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import fields, models, api
  4. class AccountBankStatementImportPaypalMap(models.Model):
  5. _name = 'account.bank.statement.import.paypal.map'
  6. _description = 'Account Bank Statement Import Paypal Map'
  7. name = fields.Char(
  8. required=True,
  9. )
  10. map_line_ids = fields.One2many(
  11. comodel_name='account.bank.statement.import.paypal.map.line',
  12. inverse_name='map_parent_id',
  13. string="Map lines",
  14. required=True,
  15. copy=True,
  16. )
  17. float_thousands_sep = fields.Selection(
  18. [('dot', 'dot (.)'),
  19. ('comma', 'comma (,)'),
  20. ('none', 'none'),
  21. ],
  22. string='Thousands separator',
  23. # forward compatibility: this was the value assumed
  24. # before the field was added.
  25. default='dot',
  26. required=True
  27. )
  28. float_decimal_sep = fields.Selection(
  29. [('dot', 'dot (.)'),
  30. ('comma', 'comma (,)'),
  31. ('none', 'none'),
  32. ],
  33. string='Decimals separator',
  34. # forward compatibility: this was the value assumed
  35. # before the field was added.
  36. default='comma',
  37. required=True
  38. )
  39. @api.onchange('float_thousands_sep')
  40. def onchange_thousands_separator(self):
  41. if 'dot' == self.float_thousands_sep == self.float_decimal_sep:
  42. self.float_decimal_sep = 'comma'
  43. elif 'comma' == self.float_thousands_sep == self.float_decimal_sep:
  44. self.float_decimal_sep = 'dot'
  45. @api.onchange('float_decimal_sep')
  46. def onchange_decimal_separator(self):
  47. if 'dot' == self.float_thousands_sep == self.float_decimal_sep:
  48. self.float_thousands_sep = 'comma'
  49. elif 'comma' == self.float_thousands_sep == self.float_decimal_sep:
  50. self.float_thousands_sep = 'dot'
  51. def _get_separators(self):
  52. separators = {'dot': '.',
  53. 'comma': ',',
  54. 'none': '',
  55. }
  56. return (separators[self.float_thousands_sep],
  57. separators[self.float_decimal_sep])
  58. class AccountBankStatementImportPaypalMapLine(models.Model):
  59. _name = 'account.bank.statement.import.paypal.map.line'
  60. _description = 'Account Bank Statement Import Paypal Map Line'
  61. _order = "sequence asc, id asc"
  62. sequence = fields.Integer(
  63. string="Field number",
  64. required=True,
  65. )
  66. name = fields.Char(
  67. string="Header Name",
  68. required=True,
  69. )
  70. map_parent_id = fields.Many2one(
  71. comodel_name='account.bank.statement.import.paypal.map',
  72. required=True,
  73. ondelete='cascade',
  74. )
  75. field_to_assign = fields.Selection(
  76. selection=[
  77. ('date', 'Date'),
  78. ('time', 'Time'),
  79. ('description', 'Description'),
  80. ('currency', 'Currency'),
  81. ('amount', 'Gross'),
  82. ('commission', 'Fee'),
  83. ('balance', 'Balance'),
  84. ('transaction_id', 'Transaction ID'),
  85. ('email', 'From Email Address'),
  86. ('partner_name', 'Name'),
  87. ('bank_name', 'Bank Name'),
  88. ('bank_account', 'Bank Account'),
  89. ('invoice_number', 'Invoice ID'),
  90. ('origin_transaction_id', 'Origin Transaction ID'),
  91. ],
  92. string="Statement Field to Assign",
  93. )
  94. date_format = fields.Selection(
  95. selection=[
  96. ('%d/%m/%Y', 'i.e. 15/12/2019'),
  97. ('%m/%d/%Y', 'i.e. 12/15/2019'),
  98. ],
  99. string="Date Format",
  100. )