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.

188 lines
6.0 KiB

  1. # Copyright 2019 ForgeFlow, S.L.
  2. # Copyright 2020 CorporateHub (https://corporatehub.eu)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class AccountBankStatementImportSheetMapping(models.Model):
  6. _name = 'account.bank.statement.import.sheet.mapping'
  7. _description = 'Account Bank Statement Import Sheet Mapping'
  8. name = fields.Char(
  9. required=True,
  10. )
  11. float_thousands_sep = fields.Selection(
  12. string='Thousands Separator',
  13. selection=[
  14. ('dot', 'dot (.)'),
  15. ('comma', 'comma (,)'),
  16. ('none', 'none'),
  17. ],
  18. default='dot',
  19. )
  20. float_decimal_sep = fields.Selection(
  21. string='Decimals Separator',
  22. selection=[
  23. ('dot', 'dot (.)'),
  24. ('comma', 'comma (,)'),
  25. ('none', 'none'),
  26. ],
  27. default='comma',
  28. )
  29. file_encoding = fields.Selection(
  30. string='Encoding',
  31. selection=[
  32. ('utf-8', 'UTF-8'),
  33. ('utf-8-sig', 'UTF-8 (with BOM)'),
  34. ('utf-16', 'UTF-16'),
  35. ('utf-16-sig', 'UTF-16 (with BOM)'),
  36. ('windows-1252', 'Western (Windows-1252)'),
  37. ('iso-8859-1', 'Western (Latin-1 / ISO 8859-1)'),
  38. ('iso-8859-2', 'Central European (Latin-2 / ISO 8859-2)'),
  39. ('iso-8859-4', 'Baltic (Latin-4 / ISO 8859-4)'),
  40. ('big5', 'Traditional Chinese (big5)'),
  41. ('gb18030', 'Unified Chinese (gb18030)'),
  42. ('shift_jis', 'Japanese (Shift JIS)'),
  43. ('windows-1251', 'Cyrillic (Windows-1251)'),
  44. ('koi8_r', 'Cyrillic (KOI8-R)'),
  45. ('koi8_u', 'Cyrillic (KOI8-U)'),
  46. ],
  47. default='utf-8',
  48. )
  49. delimiter = fields.Selection(
  50. string='Delimiter',
  51. selection=[
  52. ('dot', 'dot (.)'),
  53. ('comma', 'comma (,)'),
  54. ('semicolon', 'semicolon (;)'),
  55. ('tab', 'tab'),
  56. ('space', 'space'),
  57. ('n/a', 'N/A'),
  58. ],
  59. default='comma',
  60. )
  61. quotechar = fields.Char(
  62. string='Text qualifier',
  63. size=1,
  64. default='"',
  65. )
  66. timestamp_format = fields.Char(
  67. string='Timestamp Format',
  68. required=True,
  69. )
  70. timestamp_column = fields.Char(
  71. string='Timestamp column',
  72. required=True,
  73. )
  74. currency_column = fields.Char(
  75. string='Currency column',
  76. help=(
  77. 'In case statement is multi-currency, column to get currency of '
  78. 'transaction from'
  79. ),
  80. )
  81. amount_column = fields.Char(
  82. string='Amount column',
  83. required=True,
  84. help='Amount of transaction in journal\'s currency',
  85. )
  86. balance_column = fields.Char(
  87. string='Balance column',
  88. help='Balance after transaction in journal\'s currency',
  89. )
  90. original_currency_column = fields.Char(
  91. string='Original currency column',
  92. help=(
  93. 'In case statement provides original currency for transactions '
  94. 'with automatic currency conversion, column to get original '
  95. 'currency of transaction from'
  96. ),
  97. )
  98. original_amount_column = fields.Char(
  99. string='Original amount column',
  100. help=(
  101. 'In case statement provides original currency for transactions '
  102. 'with automatic currency conversion, column to get original '
  103. 'transaction amount in original transaction currency from'
  104. ),
  105. )
  106. debit_credit_column = fields.Char(
  107. string='Debit/credit column',
  108. help=(
  109. 'Some statement formats use absolute amount value and indicate sign'
  110. 'of the transaction by specifying if it was a debit or a credit one'
  111. ),
  112. )
  113. debit_value = fields.Char(
  114. string='Debit value',
  115. help='Value of debit/credit column that indicates if it\'s a debit',
  116. default='D',
  117. )
  118. credit_value = fields.Char(
  119. string='Credit value',
  120. help='Value of debit/credit column that indicates if it\'s a credit',
  121. default='C',
  122. )
  123. transaction_id_column = fields.Char(
  124. string='Unique transaction ID column',
  125. )
  126. description_column = fields.Char(
  127. string='Description column',
  128. )
  129. notes_column = fields.Char(
  130. string='Notes column',
  131. )
  132. reference_column = fields.Char(
  133. string='Reference column',
  134. )
  135. partner_name_column = fields.Char(
  136. string='Partner Name column',
  137. )
  138. bank_name_column = fields.Char(
  139. string='Bank Name column',
  140. help='Partner\'s bank',
  141. )
  142. bank_account_column = fields.Char(
  143. string='Bank Account column',
  144. help='Partner\'s bank account',
  145. )
  146. @api.onchange('float_thousands_sep')
  147. def onchange_thousands_separator(self):
  148. if 'dot' == self.float_thousands_sep == self.float_decimal_sep:
  149. self.float_decimal_sep = 'comma'
  150. elif 'comma' == self.float_thousands_sep == self.float_decimal_sep:
  151. self.float_decimal_sep = 'dot'
  152. @api.onchange('float_decimal_sep')
  153. def onchange_decimal_separator(self):
  154. if 'dot' == self.float_thousands_sep == self.float_decimal_sep:
  155. self.float_thousands_sep = 'comma'
  156. elif 'comma' == self.float_thousands_sep == self.float_decimal_sep:
  157. self.float_thousands_sep = 'dot'
  158. @api.multi
  159. def _get_float_separators(self):
  160. self.ensure_one()
  161. separators = {
  162. 'dot': '.',
  163. 'comma': ',',
  164. 'none': '',
  165. }
  166. return (separators[self.float_thousands_sep],
  167. separators[self.float_decimal_sep])
  168. @api.model
  169. def _decode_column_delimiter_character(self, delimiter):
  170. return ({
  171. 'dot': '.',
  172. 'comma': ',',
  173. 'semicolon': ';',
  174. 'tab': '\t',
  175. 'space': ' ',
  176. }).get(delimiter)
  177. @api.multi
  178. def _get_column_delimiter_character(self):
  179. return self._decode_column_delimiter_character(self.delimiter)