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