Merge lp:~julie-w/unifield-server/US-4703 into lp:unifield-server
- US-4703
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 5399 |
Proposed branch: | lp:~julie-w/unifield-server/US-4703 |
Merge into: | lp:unifield-server |
Diff against target: |
840 lines (+324/-346) 2 files modified
bin/addons/vertical_integration/report/hq_report_oca.py (+314/-345) bin/addons/vertical_integration/wizard/wizard_hq_report_oca.py (+10/-1) |
To merge this branch: | bzr merge lp:~julie-w/unifield-server/US-4703 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+357934@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/addons/vertical_integration/report/hq_report_oca.py' | |||
2 | --- bin/addons/vertical_integration/report/hq_report_oca.py 2017-02-13 16:32:30 +0000 | |||
3 | +++ bin/addons/vertical_integration/report/hq_report_oca.py 2019-06-07 09:34:36 +0000 | |||
4 | @@ -28,13 +28,11 @@ | |||
5 | 28 | import os | 28 | import os |
6 | 29 | from osv import osv | 29 | from osv import osv |
7 | 30 | from tools.translate import _ | 30 | from tools.translate import _ |
8 | 31 | from time import strptime | ||
9 | 31 | 32 | ||
10 | 32 | from report import report_sxw | 33 | from report import report_sxw |
11 | 33 | 34 | ||
12 | 34 | 35 | ||
13 | 35 | ZERO_CELL_CONTENT = "0.0" | ||
14 | 36 | |||
15 | 37 | |||
16 | 38 | class hq_report_oca(report_sxw.report_sxw): | 36 | class hq_report_oca(report_sxw.report_sxw): |
17 | 39 | 37 | ||
18 | 40 | def __init__(self, name, table, rml=False, parser=report_sxw.rml_parse, header='external', store=False): | 38 | def __init__(self, name, table, rml=False, parser=report_sxw.rml_parse, header='external', store=False): |
19 | @@ -45,7 +43,28 @@ | |||
20 | 45 | return st.encode('utf8') | 43 | return st.encode('utf8') |
21 | 46 | return st | 44 | return st |
22 | 47 | 45 | ||
24 | 48 | def translate_country(self, cr, uid, pool, browse_instance, context={}): | 46 | def translate_account(self, cr, uid, pool, browse_account, context=None): |
25 | 47 | """ | ||
26 | 48 | Returns the "HQ System Account Code" of the account in parameter if it exists, else returns the standard account code | ||
27 | 49 | """ | ||
28 | 50 | if context is None: | ||
29 | 51 | context = {} | ||
30 | 52 | mapping_obj = pool.get('account.export.mapping') | ||
31 | 53 | if browse_account: | ||
32 | 54 | mapping_ids = mapping_obj.search(cr, uid, [('account_id', '=', browse_account.id)], context=context) | ||
33 | 55 | if len(mapping_ids) > 0: | ||
34 | 56 | mapping = mapping_obj.browse(cr, uid, mapping_ids[0], fields_to_fetch=['mapping_value'], context=context) | ||
35 | 57 | return mapping.mapping_value | ||
36 | 58 | else: | ||
37 | 59 | return browse_account.code | ||
38 | 60 | return "" | ||
39 | 61 | |||
40 | 62 | def translate_country(self, cr, uid, pool, browse_instance, context=None): | ||
41 | 63 | """ | ||
42 | 64 | Returns the "HQ System Country Code" of the instance in parameter if it exists, else returns 0 | ||
43 | 65 | """ | ||
44 | 66 | if context is None: | ||
45 | 67 | context = {} | ||
46 | 49 | mapping_obj = pool.get('country.export.mapping') | 68 | mapping_obj = pool.get('country.export.mapping') |
47 | 50 | if browse_instance: | 69 | if browse_instance: |
48 | 51 | mapping_ids = mapping_obj.search(cr, uid, [('instance_id', '=', browse_instance.id)], context=context) | 70 | mapping_ids = mapping_obj.search(cr, uid, [('instance_id', '=', browse_instance.id)], context=context) |
49 | @@ -54,69 +73,69 @@ | |||
50 | 54 | return mapping.mapping_value | 73 | return mapping.mapping_value |
51 | 55 | return "0" | 74 | return "0" |
52 | 56 | 75 | ||
70 | 57 | def create_counterpart(self, cr, uid, line): | 76 | def create_subtotal(self, cr, uid, line_key, line_debit, counterpart_date, period, department_info, field_activity, context=None): |
71 | 58 | """ third report: up balances """ | 77 | if context is None: |
72 | 59 | # method to create counterpart line | 78 | context = {} |
73 | 60 | return line[:2] + \ | 79 | pool = pooler.get_pool(cr.dbname) |
74 | 61 | ["20750", | 80 | curr_obj = pool.get('res.currency') |
75 | 62 | "0", # before US-274/7 was expat EMP identification line[3] | 81 | rate_obj = pool.get('res.currency.rate') |
59 | 63 | "0", | ||
60 | 64 | line[5], # expat employee name or "0" | ||
61 | 65 | line[6], | ||
62 | 66 | line[7], | ||
63 | 67 | line[9], | ||
64 | 68 | line[8]] + line[10:] | ||
65 | 69 | |||
66 | 70 | def create_subtotal(self, cr, uid, line_key, | ||
67 | 71 | line_debit, line_functional_debit, line_functional_debit_no_ccy_adj, | ||
68 | 72 | counterpart_date, country_code, sequence_number): | ||
69 | 73 | """ third report: up balances """ | ||
76 | 74 | # method to create subtotal + counterpart line | 82 | # method to create subtotal + counterpart line |
85 | 75 | if len(line_key) > 2 and line_debit != 0.0 and line_functional_debit != 0.0: | 83 | period_code = period.code or "" |
86 | 76 | # US-118: func debit with no FXA currency adjustement entries | 84 | if len(line_key) > 1 and line_debit != 0.0: |
87 | 77 | # compute subtotal line inverted rate with no FXA entry: | 85 | currency = curr_obj.browse(cr, uid, line_key[1], context=context) |
88 | 78 | # no booking amount but funct one then cause a wrong balance | 86 | # rate at the first day of the selected period |
89 | 79 | # for ccy inverted rate computation | 87 | rate = 0 |
90 | 80 | rate = round(1 / (line_debit / line_functional_debit_no_ccy_adj), 8) | 88 | rate_ids = rate_obj.search(cr, uid, [('currency_id', '=', currency.id), ('name', '<=', period.date_start)], |
91 | 81 | return [["01", | 89 | order='name DESC', limit=1, context=context) |
92 | 82 | country_code, | 90 | if rate_ids: |
93 | 91 | rate = rate_obj.browse(cr, uid, rate_ids[0], fields_to_fetch=['rate'], context=context).rate | ||
94 | 92 | # Description for the line | ||
95 | 93 | if line_key[0] == "1000 0000": | ||
96 | 94 | description = "Mvts_BANK_" + period_code + "_" + currency.name | ||
97 | 95 | elif line_key[0] == "1000 0001": | ||
98 | 96 | description = "Mvts_CASH_" + period_code + "_" + currency.name | ||
99 | 97 | else: | ||
100 | 98 | mapping_obj = pool.get('account.export.mapping') | ||
101 | 99 | account_values = "" | ||
102 | 100 | mapping_ids = mapping_obj.search(cr, uid, [('mapping_value', '=', line_key[0])], context=context) | ||
103 | 101 | for mapping in mapping_obj.browse(cr, uid, mapping_ids, fields_to_fetch=['account_id'], context=context): | ||
104 | 102 | if account_values != "": | ||
105 | 103 | account_values += "-" | ||
106 | 104 | account_values += mapping.account_id.code | ||
107 | 105 | description = "Mvts_" + account_values + period_code + "_" + currency.name | ||
108 | 106 | |||
109 | 107 | return [["", | ||
110 | 108 | "", | ||
111 | 109 | "", | ||
112 | 110 | description, | ||
113 | 111 | "", | ||
114 | 112 | counterpart_date, | ||
115 | 113 | counterpart_date, | ||
116 | 114 | period_code, | ||
117 | 83 | line_key[0], | 115 | line_key[0], |
122 | 84 | "0", | 116 | "", |
123 | 85 | "0", | 117 | department_info, |
124 | 86 | counterpart_date, | 118 | "", |
125 | 87 | line_key[1], | 119 | "", |
126 | 120 | "", | ||
127 | 88 | rate, | 121 | rate, |
152 | 89 | line_debit > 0 and round(line_debit, 2) or "", | 122 | line_debit > 0 and round(line_debit, 2) or "0.00", |
153 | 90 | line_debit < 0 and round(-line_debit, 2) or "", | 123 | line_debit > 0 and "0.00" or round(-line_debit, 2), |
154 | 91 | sequence_number, | 124 | currency.name, |
155 | 92 | "Subtotal - " + line_key[0] + " - " + line_key[1] + " - " + line_key[2], | 125 | field_activity]] |
132 | 93 | "", | ||
133 | 94 | "0", | ||
134 | 95 | counterpart_date, | ||
135 | 96 | "0"] | ||
136 | 97 | ,["01", | ||
137 | 98 | country_code, | ||
138 | 99 | "20750", | ||
139 | 100 | "0", | ||
140 | 101 | "0", | ||
141 | 102 | counterpart_date, | ||
142 | 103 | line_key[1], | ||
143 | 104 | rate, | ||
144 | 105 | line_debit < 0 and round(-line_debit, 2) or "", | ||
145 | 106 | line_debit > 0 and round(line_debit, 2) or "", | ||
146 | 107 | sequence_number, | ||
147 | 108 | "Automatic counterpart for " + line_key[0] + " - " + line_key[1] + " - " + line_key[2], | ||
148 | 109 | "", | ||
149 | 110 | "0", | ||
150 | 111 | counterpart_date, | ||
151 | 112 | "0"]] | ||
156 | 113 | 126 | ||
157 | 114 | def create(self, cr, uid, ids, data, context=None): | 127 | def create(self, cr, uid, ids, data, context=None): |
158 | 115 | if context is None: | 128 | if context is None: |
159 | 116 | context = {} | 129 | context = {} |
161 | 117 | # US-2303 Data should always be in English whatever the language settings | 130 | # data should always be in English whatever the language settings |
162 | 118 | context.update({'lang': 'en_MF'}) | 131 | context.update({'lang': 'en_MF'}) |
163 | 119 | pool = pooler.get_pool(cr.dbname) | 132 | pool = pooler.get_pool(cr.dbname) |
164 | 133 | rate_obj = pool.get('res.currency.rate') | ||
165 | 134 | period_obj = pool.get('account.period') | ||
166 | 135 | inst_obj = pool.get('msf.instance') | ||
167 | 136 | aml_obj = pool.get('account.move.line') | ||
168 | 137 | aal_obj = pool.get('account.analytic.line') | ||
169 | 138 | rates = {} # store the rates already computed | ||
170 | 120 | 139 | ||
171 | 121 | first_header = ['Proprietary Instance', | 140 | first_header = ['Proprietary Instance', |
172 | 122 | 'Journal Code', | 141 | 'Journal Code', |
173 | @@ -127,6 +146,7 @@ | |||
174 | 127 | 'Posting Date', | 146 | 'Posting Date', |
175 | 128 | 'Period', | 147 | 'Period', |
176 | 129 | 'G/L Account', | 148 | 'G/L Account', |
177 | 149 | 'Unifield Account', | ||
178 | 130 | 'Destination', | 150 | 'Destination', |
179 | 131 | 'Cost Centre', | 151 | 'Cost Centre', |
180 | 132 | 'Funding Pool', | 152 | 'Funding Pool', |
181 | @@ -136,38 +156,49 @@ | |||
182 | 136 | 'Booking Currency', | 156 | 'Booking Currency', |
183 | 137 | 'Functional Debit', | 157 | 'Functional Debit', |
184 | 138 | 'Functional Credit', | 158 | 'Functional Credit', |
187 | 139 | 'Functional Currency', | 159 | 'Functional Currency'] |
188 | 140 | 'Exchange Rate'] | 160 | |
189 | 161 | second_header = ['Proprietary Instance', | ||
190 | 162 | 'Journal Code', | ||
191 | 163 | 'Entry Sequence', | ||
192 | 164 | 'Description', | ||
193 | 165 | 'Reference', | ||
194 | 166 | 'Document Date', | ||
195 | 167 | 'Posting Date', | ||
196 | 168 | 'Period', | ||
197 | 169 | 'G/L Account', | ||
198 | 170 | 'Destination', | ||
199 | 171 | 'Department', | ||
200 | 172 | 'Cost Centre', | ||
201 | 173 | 'Third Parties', | ||
202 | 174 | 'Employee Id', | ||
203 | 175 | 'Exchange rate', | ||
204 | 176 | 'Booking Debit', | ||
205 | 177 | 'Booking Credit', | ||
206 | 178 | 'Booking Currency', | ||
207 | 179 | 'Field Activity'] | ||
208 | 180 | |||
209 | 181 | period = period_obj.browse(cr, uid, data['form']['period_id'], context=context) | ||
210 | 182 | |||
211 | 183 | # list the journal types for which the rate used will always be 1 | ||
212 | 184 | # i.e. REVAL, Curr. Adjustment, and Accrual | ||
213 | 185 | no_rate_journal_types = ['revaluation', 'cur_adj', 'accrual'] | ||
214 | 186 | no_rate_analytic_journal_types = ['revaluation', 'cur_adj', 'general'] # Analytic Accrual Journals have the type General | ||
215 | 141 | 187 | ||
216 | 142 | # Initialize lists: one for the first report... | 188 | # Initialize lists: one for the first report... |
217 | 143 | first_result_lines = [] | 189 | first_result_lines = [] |
219 | 144 | # ...one for the second report... | 190 | # ...and subdivisions for the second report. |
220 | 145 | second_result_lines = [] | 191 | second_result_lines = [] |
224 | 146 | # ...and subdivisions for the third report. | 192 | main_lines = {} |
222 | 147 | third_report = [] | ||
223 | 148 | account_lines = [] | ||
225 | 149 | account_lines_debit = {} | 193 | account_lines_debit = {} |
240 | 150 | account_lines_functional_debit = {} | 194 | # Get department code filled in through the country code mapping |
241 | 151 | rate_req = "SELECT rate FROM res_currency_rate WHERE currency_id = %s AND name <= %s ORDER BY name desc LIMIT 1" | 195 | department_info = "" |
242 | 152 | # US-118: func debit with no FXA currency adjustement entries | 196 | field_activity = "" # always empty |
243 | 153 | account_lines_functional_debit_no_ccy_adj = {} | 197 | parent_instance = False |
230 | 154 | journal_exclude_subtotal_ids = pool.get('account.journal').search(cr, | ||
231 | 155 | uid, [('type', 'in', ('cur_adj', 'revaluation'))], context=context) | ||
232 | 156 | # General variables | ||
233 | 157 | period = pool.get('account.period').browse(cr, uid, data['form']['period_id']) | ||
234 | 158 | period_name = period and period.code or "0" | ||
235 | 159 | counterpart_date = period and period.date_stop and \ | ||
236 | 160 | datetime.datetime.strptime(period.date_stop, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "" | ||
237 | 161 | integration_ref = "0" | ||
238 | 162 | country_code = "0" | ||
239 | 163 | move_prefix = "0" | ||
244 | 164 | if len(data['form']['instance_ids']) > 0: | 198 | if len(data['form']['instance_ids']) > 0: |
246 | 165 | parent_instance = pool.get('msf.instance').browse(cr, uid, data['form']['instance_ids'][0], context=context) | 199 | parent_instance = inst_obj.browse(cr, uid, data['form']['instance_ids'][0], context=context) |
247 | 166 | if parent_instance: | 200 | if parent_instance: |
252 | 167 | country_code = self.translate_country(cr, uid, pool, parent_instance) | 201 | department_info = self.translate_country(cr, uid, pool, parent_instance, context=context) |
249 | 168 | if period and period.date_start: | ||
250 | 169 | integration_ref = parent_instance.code[:2] + period.date_start[5:7] | ||
251 | 170 | move_prefix = parent_instance.move_prefix[:2] | ||
253 | 171 | 202 | ||
254 | 172 | # UFTP-375: Add export all/previous functionality | 203 | # UFTP-375: Add export all/previous functionality |
255 | 173 | selection = data['form'].get('selection', False) | 204 | selection = data['form'].get('selection', False) |
256 | @@ -181,66 +212,30 @@ | |||
257 | 181 | else: | 212 | else: |
258 | 182 | raise osv.except_osv(_('Error'), _('Wrong value for selection: %s.') % (selection,)) | 213 | raise osv.except_osv(_('Error'), _('Wrong value for selection: %s.') % (selection,)) |
259 | 183 | 214 | ||
272 | 184 | last_processed_journal = False | 215 | move_line_ids = aml_obj.search(cr, uid, [('period_id', '=', data['form']['period_id']), |
273 | 185 | move_line_ids = pool.get('account.move.line').search(cr, uid, [('period_id', '=', data['form']['period_id']), | 216 | ('instance_id', 'in', data['form']['instance_ids']), |
274 | 186 | ('instance_id', 'in', data['form']['instance_ids']), | 217 | ('account_id.is_analytic_addicted', '=', False), |
275 | 187 | ('account_id.is_analytic_addicted', '=', False), | 218 | ('journal_id.type', 'not in', ['migration', 'hq']), |
276 | 188 | ('journal_id.type', 'not in', ['hq', 'migration']), | 219 | ('exported', 'in', to_export)], |
277 | 189 | ('exported', 'in', to_export)], context=context) | 220 | context=context) |
266 | 190 | # US-274/2: remove 'Inkind', 'OD-Extra Accounting' entries from both | ||
267 | 191 | # in Upbalances and Upexpenses files | ||
268 | 192 | exclude_jn_type_for_balance_and_expense_report = ( | ||
269 | 193 | 'inkind', | ||
270 | 194 | 'extra', | ||
271 | 195 | ) | ||
278 | 196 | 221 | ||
279 | 197 | nb_move_line = len(move_line_ids) | 222 | nb_move_line = len(move_line_ids) |
280 | 198 | move_line_count = 0 | 223 | move_line_count = 0 |
281 | 199 | |||
282 | 200 | if 'background_id' in context: | 224 | if 'background_id' in context: |
283 | 201 | bg_id = context['background_id'] | 225 | bg_id = context['background_id'] |
284 | 202 | else: | 226 | else: |
285 | 203 | bg_id = None | 227 | bg_id = None |
286 | 204 | 228 | ||
289 | 205 | # assume that this for loop is about 40% of the total treatment | 229 | move_share = 0.4 # 40% of the total process |
288 | 206 | move_share = 0.4 | ||
290 | 207 | 230 | ||
292 | 208 | for move_line in pool.get('account.move.line').browse(cr, uid, move_line_ids, context=context): | 231 | for move_line in aml_obj.browse(cr, uid, move_line_ids, context=context): |
293 | 232 | if move_line.move_id.state != 'posted': # only posted move lines are kept | ||
294 | 233 | move_line_count += 1 | ||
295 | 234 | continue | ||
296 | 209 | journal = move_line.journal_id | 235 | journal = move_line.journal_id |
297 | 210 | if journal: | ||
298 | 211 | last_processed_journal = journal | ||
299 | 212 | account = move_line.account_id | 236 | account = move_line.account_id |
300 | 213 | currency = move_line.currency_id | 237 | currency = move_line.currency_id |
331 | 214 | func_currency = move_line.functional_currency_id | 238 | # For the first report: |
302 | 215 | rate = ZERO_CELL_CONTENT | ||
303 | 216 | |||
304 | 217 | is_cur_adj_entry = move_line.journal_id \ | ||
305 | 218 | and move_line.journal_id.type == 'cur_adj' or False | ||
306 | 219 | is_rev_entry = move_line.journal_id \ | ||
307 | 220 | and move_line.journal_id.type == 'revaluation' or False | ||
308 | 221 | |||
309 | 222 | if currency and func_currency: | ||
310 | 223 | # US-274/9: accrual account (always refer to previous period) | ||
311 | 224 | # base on doc date instead posting in this case | ||
312 | 225 | # - 1st period accruals: doc date and posting same period | ||
313 | 226 | # - next accruals: doc date previous period (accrual of) | ||
314 | 227 | move_line_date = move_line.journal_id \ | ||
315 | 228 | and move_line.journal_id.type == 'accrual' \ | ||
316 | 229 | and move_line.document_date or move_line.date | ||
317 | 230 | |||
318 | 231 | if move_line.journal_id.type == 'correction' and move_line.source_date: | ||
319 | 232 | # US-1525 For the Correction entries display the rate of the entry period corrected | ||
320 | 233 | move_line_date = move_line.source_date | ||
321 | 234 | cr.execute(rate_req, (move_line.functional_currency_id.id, move_line_date)) | ||
322 | 235 | if cr.rowcount: | ||
323 | 236 | func_rate = cr.fetchall()[0][0] | ||
324 | 237 | cr.execute(rate_req, (currency.id, move_line_date)) | ||
325 | 238 | if cr.rowcount: | ||
326 | 239 | curr_rate = cr.fetchall()[0][0] | ||
327 | 240 | if func_rate != 0.00: | ||
328 | 241 | rate = round(1 / (curr_rate / func_rate), 8) | ||
329 | 242 | |||
330 | 243 | # For first report: as it | ||
332 | 244 | formatted_data = [move_line.instance_id and move_line.instance_id.code or "", | 239 | formatted_data = [move_line.instance_id and move_line.instance_id.code or "", |
333 | 245 | journal and journal.code or "", | 240 | journal and journal.code or "", |
334 | 246 | move_line.move_id and move_line.move_id.name or "", | 241 | move_line.move_id and move_line.move_id.name or "", |
335 | @@ -249,6 +244,7 @@ | |||
336 | 249 | datetime.datetime.strptime(move_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), | 244 | datetime.datetime.strptime(move_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), |
337 | 250 | datetime.datetime.strptime(move_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), | 245 | datetime.datetime.strptime(move_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), |
338 | 251 | move_line.period_id and move_line.period_id.code or "", | 246 | move_line.period_id and move_line.period_id.code or "", |
339 | 247 | self.translate_account(cr, uid, pool, account, context=context), | ||
340 | 252 | account and account.code + " " + account.name, | 248 | account and account.code + " " + account.name, |
341 | 253 | "", | 249 | "", |
342 | 254 | "", | 250 | "", |
343 | @@ -259,79 +255,74 @@ | |||
344 | 259 | currency and currency.name or "", | 255 | currency and currency.name or "", |
345 | 260 | round(move_line.debit, 2), | 256 | round(move_line.debit, 2), |
346 | 261 | round(move_line.credit, 2), | 257 | round(move_line.credit, 2), |
349 | 262 | func_currency and func_currency.name or "", | 258 | move_line.functional_currency_id and move_line.functional_currency_id.name or ""] |
348 | 263 | rate] | ||
350 | 264 | first_result_lines.append(formatted_data) | 259 | first_result_lines.append(formatted_data) |
404 | 265 | if is_cur_adj_entry or is_rev_entry: | 260 | |
405 | 266 | # US-788/1 and US-478/3: FXA/REV raw data override | 261 | # For the second report: |
406 | 267 | # without impacting formatted_data for other files | 262 | # exclude In-kind Donations and OD-Extra Accounting entries from the "formatted data" file |
407 | 268 | # US-788/1: always display booking as func | 263 | if move_line.journal_id.type not in ['inkind', 'extra']: |
408 | 269 | # US-478/3 always rate of 1 | 264 | if not account.shrink_entries_for_hq: |
409 | 270 | first_result_lines[-1][13] = first_result_lines[-1][16] # US-788/1 | 265 | # data for the "Employee Id" column |
410 | 271 | first_result_lines[-1][14] = first_result_lines[-1][17] # US-788/1 | 266 | employee_id = '' |
411 | 272 | first_result_lines[-1][15] = first_result_lines[-1][18] # US-788/1 | 267 | if move_line.employee_id and move_line.employee_id.employee_type == 'ex': # expat staff |
412 | 273 | first_result_lines[-1][-1] = 1. # US-478/3 | 268 | employee_id = move_line.employee_id.identification_id or '' |
413 | 274 | 269 | # data for the columns: Exchange rate, Booking Debit, Booking Credit, Booking Currency | |
414 | 275 | # For third report: add to corresponding sub | 270 | exchange_rate = 0 |
415 | 276 | if journal and journal.type not in ( | 271 | booking_amounts = [round(move_line.debit_currency, 2), round(move_line.credit_currency, 2)] |
416 | 277 | exclude_jn_type_for_balance_and_expense_report): # US-274/2 | 272 | booking_curr = formatted_data[16:17] |
417 | 278 | if not account.shrink_entries_for_hq or is_rev_entry or is_cur_adj_entry: | 273 | if move_line.journal_id.type in no_rate_journal_types: |
418 | 279 | # US-478/1: or is_rev_entry, no shrink for rev journal entries | 274 | # use 1 as exchange rate and display the functional values in the "booking" columns |
419 | 280 | expat_identification = "0" | 275 | exchange_rate = 1 |
420 | 281 | expat_employee = "0" | 276 | booking_amounts = [round(move_line.debit, 2), round(move_line.credit, 2)] |
421 | 282 | # Expat employees are the only third party in this report | 277 | booking_curr = formatted_data[19:20] |
422 | 283 | if move_line.partner_txt and move_line.employee_id and move_line.employee_id.employee_type == 'ex': | 278 | # automatic corrections |
423 | 284 | if account.code == '15640': # US-274/7 | 279 | elif move_line.journal_id.type == 'correction' and (move_line.corrected_line_id or move_line.reversal_line_id): |
424 | 285 | expat_identification = move_line.employee_id.identification_id | 280 | # If there are several levels of correction use the last one |
425 | 286 | expat_employee = move_line.partner_txt | 281 | corr_aml = move_line.corrected_line_id or move_line.reversal_line_id # JI corrected or reversed |
426 | 287 | 282 | initial_id = -1 | |
427 | 288 | # US-274/1: for FXA/REV entries output fonctional amount in balance | 283 | final_id = -2 |
428 | 289 | # report | 284 | while initial_id != final_id: |
429 | 290 | if is_cur_adj_entry or is_rev_entry: | 285 | initial_id = corr_aml.id |
430 | 291 | output_debit = move_line.debit | 286 | # check if the corrected line corrects another line |
431 | 292 | output_credit = move_line.credit | 287 | corr_aml = corr_aml.corrected_line_id or corr_aml |
432 | 293 | output_rate = 1. | 288 | final_id = corr_aml.id |
433 | 294 | output_curr = func_currency and func_currency.name or "0" | 289 | # rate of the original corrected entry |
434 | 295 | else: | 290 | if currency.id not in rates: |
435 | 296 | output_debit = move_line.debit_currency | 291 | rates[currency.id] = {} |
436 | 297 | output_credit = move_line.credit_currency | 292 | if corr_aml.date not in rates[currency.id]: |
437 | 298 | output_rate = rate | 293 | rate = 0 |
438 | 299 | output_curr = currency and currency.name or "0" | 294 | rate_ids = rate_obj.search(cr, uid, [('currency_id', '=', currency.id), ('name', '<=', corr_aml.date)], |
439 | 300 | 295 | order='name DESC', limit=1, context=context) | |
440 | 301 | other_formatted_data = ["01", | 296 | if rate_ids: |
441 | 302 | country_code, | 297 | rate = rate_obj.browse(cr, uid, rate_ids[0], fields_to_fetch=['rate'], context=context).rate |
442 | 303 | account and account.code or "0", | 298 | rates[currency.id][corr_aml.date] = rate |
443 | 304 | expat_identification, | 299 | exchange_rate = rates[currency.id][corr_aml.date] |
444 | 305 | "0", | 300 | # other lines |
445 | 306 | move_line.date and datetime.datetime.strptime(move_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "0", | 301 | elif currency: |
446 | 307 | output_curr, | 302 | # rate of the period selected |
447 | 308 | output_rate, | 303 | if currency.id not in rates: |
448 | 309 | output_debit != 0.0 and round(output_debit, 2) or "", | 304 | rates[currency.id] = {} |
449 | 310 | output_credit != 0.0 and round(output_credit, 2) or "", | 305 | if period.date_start not in rates[currency.id]: |
450 | 311 | move_line.move_id and move_line.move_id.name or "0", | 306 | rate = 0 |
451 | 312 | move_line.name or "0", | 307 | rate_ids = rate_obj.search(cr, uid, [('currency_id', '=', currency.id), ('name', '<=', period.date_start)], |
452 | 313 | move_line.ref or "", | 308 | order='name DESC', limit=1, context=context) |
453 | 314 | expat_employee, | 309 | if rate_ids: |
454 | 315 | move_line.document_date and datetime.datetime.strptime(move_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "0", | 310 | rate = rate_obj.browse(cr, uid, rate_ids[0], fields_to_fetch=['rate'], context=context).rate |
455 | 316 | move_line.ref or "0"] | 311 | rates[currency.id][period.date_start] = rate |
456 | 317 | account_lines.append(other_formatted_data) | 312 | exchange_rate = rates[currency.id][period.date_start] |
457 | 313 | |||
458 | 314 | if (journal.code, journal.id, currency.id) not in main_lines: | ||
459 | 315 | main_lines[(journal.code, journal.id, currency.id)] = [] | ||
460 | 316 | main_lines[(journal.code, journal.id, currency.id)].append(formatted_data[:9] + [formatted_data[10]] + | ||
461 | 317 | [department_info] + [formatted_data[11]] + | ||
462 | 318 | [formatted_data[13]] + [employee_id] + | ||
463 | 319 | [exchange_rate] + booking_amounts + | ||
464 | 320 | booking_curr + [field_activity]) | ||
465 | 318 | else: | 321 | else: |
482 | 319 | if (account.code, currency.name, period_name) not in account_lines_debit: | 322 | translated_account_code = self.translate_account(cr, uid, pool, account, context=context) |
483 | 320 | account_lines_debit[(account.code, currency.name, period_name)] = 0.0 | 323 | if (translated_account_code, currency.id) not in account_lines_debit: |
484 | 321 | account_lines_functional_debit[(account.code, currency.name, period_name)] = 0.0 | 324 | account_lines_debit[(translated_account_code, currency.id)] = 0.0 |
485 | 322 | account_lines_functional_debit_no_ccy_adj[(account.code, currency.name, period_name)] = 0.0 | 325 | account_lines_debit[(translated_account_code, currency.id)] += (move_line.debit_currency - move_line.credit_currency) |
470 | 323 | |||
471 | 324 | account_lines_debit[(account.code, currency.name, period_name)] += (move_line.debit_currency - move_line.credit_currency) | ||
472 | 325 | funct_balance = (move_line.debit - move_line.credit) | ||
473 | 326 | account_lines_functional_debit[(account.code, currency.name, period_name)] += funct_balance | ||
474 | 327 | |||
475 | 328 | # US-118: func debit with no FXA currency adjustement entries | ||
476 | 329 | # compute subtotal line inverted rate with no FXA entry: | ||
477 | 330 | # no booking amount but funct one then cause a wrong balance | ||
478 | 331 | # for ccy inverted rate computation | ||
479 | 332 | if not journal_exclude_subtotal_ids or \ | ||
480 | 333 | move_line.journal_id.id not in journal_exclude_subtotal_ids: | ||
481 | 334 | account_lines_functional_debit_no_ccy_adj[(account.code, currency.name, period_name)] += funct_balance | ||
486 | 335 | 326 | ||
487 | 336 | move_line_count += 1 | 327 | move_line_count += 1 |
488 | 337 | if move_line_count % 30 == 0: | 328 | if move_line_count % 30 == 0: |
489 | @@ -343,124 +334,113 @@ | |||
490 | 343 | self.shared_update_percent(cr, uid, pool, [bg_id], | 334 | self.shared_update_percent(cr, uid, pool, [bg_id], |
491 | 344 | share=move_share, finished=True) | 335 | share=move_share, finished=True) |
492 | 345 | 336 | ||
502 | 346 | # UFTP-375: Do not include FREE1 and FREE2 analytic lines | 337 | analytic_line_ids = aal_obj.search(cr, uid, [('period_id', '=', data['form']['period_id']), |
503 | 347 | # US-817: search period from JI (VI from HQ so AJI always with its JI) | 338 | ('instance_id', 'in', data['form']['instance_ids']), |
504 | 348 | # (AJI period_id is a field function always deduced from date since UTP-943) | 339 | ('journal_id.type', 'not in', ['migration', 'hq', 'engagement']), |
505 | 349 | analytic_line_ids = pool.get('account.analytic.line').search(cr, uid, [('period_id', '=', data['form']['period_id']), | 340 | ('account_id.category', 'not in', ['FREE1', 'FREE2']), |
506 | 350 | ('instance_id', 'in', data['form']['instance_ids']), | 341 | ('exported', 'in', to_export)], context=context) |
498 | 351 | ('journal_id.type', 'not in', ['hq', 'engagement', 'migration']), | ||
499 | 352 | ('account_id.category', 'not in', ['FREE1', 'FREE2']), | ||
500 | 353 | ('exported', 'in', to_export)], context=context) | ||
501 | 354 | |||
507 | 355 | nb_analytic_line = len(analytic_line_ids) | 342 | nb_analytic_line = len(analytic_line_ids) |
508 | 356 | analytic_line_count = 0 | 343 | analytic_line_count = 0 |
509 | 357 | 344 | ||
512 | 358 | # assume that this for loop is about 50% of the total treatment | 345 | analytic_share = 0.5 # 50% of the total process |
511 | 359 | analytic_share = 0.5 | ||
513 | 360 | 346 | ||
518 | 361 | for analytic_line in pool.get('account.analytic.line').browse(cr, uid, analytic_line_ids, context=context): | 347 | for analytic_line in aal_obj.browse(cr, uid, analytic_line_ids, context=context): |
519 | 362 | journal = analytic_line.move_id and analytic_line.move_id.journal_id or False | 348 | # restrict to analytic lines coming from posted move lines |
520 | 363 | if journal: | 349 | if analytic_line.move_state != 'posted': |
521 | 364 | last_processed_journal = journal | 350 | analytic_line_count += 1 |
522 | 351 | continue | ||
523 | 352 | journal = analytic_line.move_id and analytic_line.move_id.journal_id | ||
524 | 365 | account = analytic_line.general_account_id | 353 | account = analytic_line.general_account_id |
525 | 366 | currency = analytic_line.currency_id | 354 | currency = analytic_line.currency_id |
556 | 367 | func_currency = analytic_line.move_id.functional_currency_id | 355 | cost_center_code = analytic_line.cost_center_id and analytic_line.cost_center_id.code or "" |
527 | 368 | rate = "" | ||
528 | 369 | |||
529 | 370 | # US-478 - US-274/9 accrual account always refer to previous period | ||
530 | 371 | # base on doc date instead posting in this case | ||
531 | 372 | # - 1st period accruals: doc date and posting same period | ||
532 | 373 | # - next accruals: doc date previous period (accrual of) | ||
533 | 374 | ldate = analytic_line.date | ||
534 | 375 | if analytic_line.move_id: | ||
535 | 376 | if analytic_line.move_id.journal_id.type == 'accrual': | ||
536 | 377 | ldate = analytic_line.document_date or analytic_line.date | ||
537 | 378 | elif analytic_line.journal_id \ | ||
538 | 379 | and analytic_line.journal_id.code == 'ACC': | ||
539 | 380 | # sync border case no JI for the AJI | ||
540 | 381 | ldate = analytic_line.document_date or analytic_line.date | ||
541 | 382 | |||
542 | 383 | if func_currency: | ||
543 | 384 | if analytic_line.journal_id.type == 'correction' and analytic_line.source_date: | ||
544 | 385 | # US-1525 For the Correction entries display the rate of the entry period corrected | ||
545 | 386 | ldate = analytic_line.source_date | ||
546 | 387 | cr.execute(rate_req, (currency.id, ldate)) | ||
547 | 388 | if cr.rowcount: | ||
548 | 389 | rate = round(1 / cr.fetchall()[0][0], 8) | ||
549 | 390 | |||
550 | 391 | is_analytic_cur_adj_entry = analytic_line.journal_id \ | ||
551 | 392 | and analytic_line.journal_id.type == 'cur_adj' or False | ||
552 | 393 | is_analytic_rev_entry = analytic_line.journal_id \ | ||
553 | 394 | and analytic_line.journal_id.type == 'revaluation' or False | ||
554 | 395 | |||
555 | 396 | # US-1375: cancel US-817 | ||
557 | 397 | aji_period_id = analytic_line and analytic_line.period_id or False | 356 | aji_period_id = analytic_line and analytic_line.period_id or False |
558 | 398 | 357 | ||
560 | 399 | # For first report: as is | 358 | # For the first report: |
561 | 400 | formatted_data = [analytic_line.instance_id and analytic_line.instance_id.code or "", | 359 | formatted_data = [analytic_line.instance_id and analytic_line.instance_id.code or "", |
562 | 401 | analytic_line.journal_id and analytic_line.journal_id.code or "", | 360 | analytic_line.journal_id and analytic_line.journal_id.code or "", |
564 | 402 | analytic_line.entry_sequence or "", | 361 | analytic_line.entry_sequence or analytic_line.move_id and analytic_line.move_id.move_id and analytic_line.move_id.move_id.name or "", |
565 | 403 | analytic_line.name or "", | 362 | analytic_line.name or "", |
566 | 404 | analytic_line.ref or "", | 363 | analytic_line.ref or "", |
567 | 405 | datetime.datetime.strptime(analytic_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), | 364 | datetime.datetime.strptime(analytic_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), |
568 | 406 | datetime.datetime.strptime(analytic_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), | 365 | datetime.datetime.strptime(analytic_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y'), |
569 | 407 | aji_period_id and aji_period_id.code or "", | 366 | aji_period_id and aji_period_id.code or "", |
570 | 367 | self.translate_account(cr, uid, pool, account, context=context), | ||
571 | 408 | account and account.code + " " + account.name or "", | 368 | account and account.code + " " + account.name or "", |
572 | 409 | analytic_line.destination_id and analytic_line.destination_id.code or "", | 369 | analytic_line.destination_id and analytic_line.destination_id.code or "", |
574 | 410 | analytic_line.cost_center_id and analytic_line.cost_center_id.code or "", | 370 | cost_center_code, |
575 | 411 | analytic_line.account_id and analytic_line.account_id.code or "", | 371 | analytic_line.account_id and analytic_line.account_id.code or "", |
576 | 412 | analytic_line.partner_txt or "", | 372 | analytic_line.partner_txt or "", |
579 | 413 | analytic_line.amount_currency > 0 and ZERO_CELL_CONTENT or round(-analytic_line.amount_currency, 2), | 373 | analytic_line.amount_currency > 0 and "0.00" or round(-analytic_line.amount_currency, 2), |
580 | 414 | analytic_line.amount_currency > 0 and round(analytic_line.amount_currency, 2) or ZERO_CELL_CONTENT, | 374 | analytic_line.amount_currency > 0 and round(analytic_line.amount_currency, 2) or "0.00", |
581 | 415 | currency and currency.name or "", | 375 | currency and currency.name or "", |
586 | 416 | analytic_line.amount > 0 and ZERO_CELL_CONTENT or round(-analytic_line.amount, 2), | 376 | analytic_line.amount > 0 and "0.00" or round(-analytic_line.amount, 2), |
587 | 417 | analytic_line.amount > 0 and round(analytic_line.amount, 2) or ZERO_CELL_CONTENT, | 377 | analytic_line.amount > 0 and round(analytic_line.amount, 2) or "0.00", |
588 | 418 | func_currency and func_currency.name or "", | 378 | analytic_line.functional_currency_id and analytic_line.functional_currency_id.name or ""] |
585 | 419 | rate] | ||
589 | 420 | first_result_lines.append(formatted_data) | 379 | first_result_lines.append(formatted_data) |
633 | 421 | if is_analytic_cur_adj_entry or is_analytic_rev_entry: | 380 | |
634 | 422 | # US-788/1 and US-478/3: FXA/REV raw data override | 381 | # exclude In-kind Donations and OD-Extra Accounting entries from the "formatted data" file |
635 | 423 | # without impacting formatted_data for other files | 382 | if analytic_line.journal_id.type not in ['inkind', 'extra']: |
636 | 424 | # US-788/1: always display booking as func | 383 | # format CC as: P + the 4 digits from the right |
637 | 425 | # US-478/3 always rate of 1 | 384 | cost_center = formatted_data[11] and "P%s" % formatted_data[11][-4:] or "" |
638 | 426 | first_result_lines[-1][13] = first_result_lines[-1][16] # US-788/1 | 385 | # data for the "Employee Id" column |
639 | 427 | first_result_lines[-1][14] = first_result_lines[-1][17] # US-788/1 | 386 | employee_id = '' |
640 | 428 | first_result_lines[-1][15] = first_result_lines[-1][18] # US-788/1 | 387 | if analytic_line.move_id and analytic_line.move_id.employee_id and analytic_line.move_id.employee_id.employee_type == 'ex': # expat staff |
641 | 429 | first_result_lines[-1][-1] = 1. # US-478/3 | 388 | employee_id = analytic_line.move_id.employee_id.identification_id or '' |
642 | 430 | if analytic_line.journal_id \ | 389 | |
643 | 431 | and analytic_line.journal_id.type not in ( | 390 | # data for the columns: Exchange rate, Booking Debit, Booking Credit, Booking Currency |
644 | 432 | exclude_jn_type_for_balance_and_expense_report): # US-274/2 | 391 | exchange_rate = 0 |
645 | 433 | # Add to second report (expenses only) | 392 | booking_amounts = [analytic_line.amount_currency > 0 and "0.00" or round(-analytic_line.amount_currency, 2), |
646 | 434 | up_exp_ccy = currency | 393 | analytic_line.amount_currency > 0 and round(analytic_line.amount_currency, 2) or "0.00"] |
647 | 435 | up_exp_rate = rate | 394 | booking_curr = formatted_data[16:17] |
648 | 436 | up_exp_amount = analytic_line.amount_currency | 395 | if analytic_line.journal_id.type in no_rate_analytic_journal_types: |
649 | 437 | 396 | # use 1 as exchange rate and display the functional values in the "booking" columns | |
650 | 438 | if is_analytic_rev_entry: | 397 | exchange_rate = 1 |
651 | 439 | # US-1008 for up_expenses (file 2), match REV AJIs to JIs: | 398 | booking_amounts = [analytic_line.amount > 0 and "0.00" or round(-analytic_line.amount, 2), |
652 | 440 | # display AJIs booked on REV journal in func ccy and rate 1 | 399 | analytic_line.amount > 0 and round(analytic_line.amount, 2) or "0.00"] |
653 | 441 | # as already done here for JIs of up_balances (file 3) | 400 | booking_curr = formatted_data[19:20] |
654 | 442 | up_exp_ccy = func_currency | 401 | # automatic corrections |
655 | 443 | up_exp_rate = 1. | 402 | elif analytic_line.journal_id.type == 'correction' and (analytic_line.last_corrected_id or analytic_line.reversal_origin): |
656 | 444 | up_exp_amount = analytic_line.amount | 403 | # If there are several levels of correction use the last one |
657 | 445 | 404 | corr_aal = analytic_line.last_corrected_id or analytic_line.reversal_origin # AJI corrected or reversed | |
658 | 446 | other_formatted_data = [integration_ref , | 405 | initial_id = -1 |
659 | 447 | analytic_line.document_date and datetime.datetime.strptime(analytic_line.document_date, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "0", | 406 | final_id = -2 |
660 | 448 | "0", | 407 | while initial_id != final_id: |
661 | 449 | "0", | 408 | initial_id = corr_aal.id |
662 | 450 | analytic_line.cost_center_id and analytic_line.cost_center_id.code or "0", | 409 | # check if the corrected line corrects another line |
663 | 451 | "1", | 410 | corr_aal = corr_aal.last_corrected_id or corr_aal |
664 | 452 | account and account.code + " " + account.name or "0", | 411 | final_id = corr_aal.id |
665 | 453 | up_exp_ccy and up_exp_ccy.name or "0", | 412 | # rate of the original corrected entry |
666 | 454 | up_exp_amount and round(-up_exp_amount, 2) or ZERO_CELL_CONTENT, | 413 | if currency.id not in rates: |
667 | 455 | "0", | 414 | rates[currency.id] = {} |
668 | 456 | up_exp_rate, | 415 | if corr_aal.date not in rates[currency.id]: |
669 | 457 | analytic_line.date and datetime.datetime.strptime(analytic_line.date, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "0", | 416 | rate = 0 |
670 | 458 | analytic_line.entry_sequence or "0", | 417 | rate_ids = rate_obj.search(cr, uid, [('currency_id', '=', currency.id), ('name', '<=', corr_aal.date)], |
671 | 459 | "0", | 418 | order='name DESC', limit=1, context=context) |
672 | 460 | analytic_line.name or "0", | 419 | if rate_ids: |
673 | 461 | analytic_line.ref or "0", | 420 | rate = rate_obj.browse(cr, uid, rate_ids[0], fields_to_fetch=['rate'], context=context).rate |
674 | 462 | analytic_line.destination_id and analytic_line.destination_id.code or "0"] | 421 | rates[currency.id][corr_aal.date] = rate |
675 | 463 | second_result_lines.append(other_formatted_data) | 422 | exchange_rate = rates[currency.id][corr_aal.date] |
676 | 423 | # other lines | ||
677 | 424 | elif currency: | ||
678 | 425 | # rate of the period selected | ||
679 | 426 | if currency.id not in rates: | ||
680 | 427 | rates[currency.id] = {} | ||
681 | 428 | if period.date_start not in rates[currency.id]: | ||
682 | 429 | rate = 0 | ||
683 | 430 | rate_ids = rate_obj.search(cr, uid, [('currency_id', '=', currency.id), ('name', '<=', period.date_start)], | ||
684 | 431 | order='name DESC', limit=1, context=context) | ||
685 | 432 | if rate_ids: | ||
686 | 433 | rate = rate_obj.browse(cr, uid, rate_ids[0], fields_to_fetch=['rate'], context=context).rate | ||
687 | 434 | rates[currency.id][period.date_start] = rate | ||
688 | 435 | exchange_rate = rates[currency.id][period.date_start] | ||
689 | 436 | |||
690 | 437 | if (journal.code, journal.id, currency.id) not in main_lines: | ||
691 | 438 | main_lines[(journal.code, journal.id, currency.id)] = [] | ||
692 | 439 | main_lines[(journal.code, journal.id, currency.id)].append(formatted_data[:9] + [formatted_data[10]] + | ||
693 | 440 | [department_info] + [cost_center] + | ||
694 | 441 | [formatted_data[13]] + [employee_id] + | ||
695 | 442 | [exchange_rate] + booking_amounts + | ||
696 | 443 | booking_curr + [field_activity]) | ||
697 | 464 | 444 | ||
698 | 465 | analytic_line_count += 1 | 445 | analytic_line_count += 1 |
699 | 466 | if analytic_line_count % 30 == 0: | 446 | if analytic_line_count % 30 == 0: |
700 | @@ -474,69 +454,58 @@ | |||
701 | 474 | share=analytic_share, finished=True, already_done=move_share) | 454 | share=analytic_share, finished=True, already_done=move_share) |
702 | 475 | 455 | ||
703 | 476 | first_result_lines = sorted(first_result_lines, key=lambda line: line[2]) | 456 | first_result_lines = sorted(first_result_lines, key=lambda line: line[2]) |
734 | 477 | if not move_line_ids and not analytic_line_ids: | 457 | first_report = [first_header] + first_result_lines |
735 | 478 | first_report = [] | 458 | |
736 | 479 | else: | 459 | counterpart_date = period and period.date_stop and \ |
737 | 480 | first_report = [first_header] + first_result_lines | 460 | datetime.datetime.strptime(period.date_stop, '%Y-%m-%d').date().strftime('%d/%m/%Y') or "" |
738 | 481 | 461 | ||
739 | 482 | second_report = sorted(second_result_lines, key=lambda line: line[12]) | 462 | # regroup second report lines |
740 | 483 | 463 | for key in sorted(main_lines.iterkeys(), key=lambda tuple: tuple[0]): | |
741 | 484 | for line in sorted(account_lines, key=lambda line: line[10]): | 464 | second_result_lines += sorted(main_lines[key], key=lambda line: line[2]) |
742 | 485 | third_report.append(line) | 465 | |
743 | 486 | third_report.append(self.create_counterpart(cr, uid, line)) | 466 | for key in sorted(account_lines_debit.iterkeys(), key=lambda tuple: tuple[0]): |
744 | 487 | 467 | # for entries "shrunk for HQ export" | |
745 | 488 | if last_processed_journal and last_processed_journal.type not in ( | 468 | subtotal_lines = self.create_subtotal(cr, uid, key, account_lines_debit[key], counterpart_date, period, |
746 | 489 | exclude_jn_type_for_balance_and_expense_report): # US-274/2 | 469 | department_info, field_activity, context=context) |
747 | 490 | for key in sorted(account_lines_debit.iterkeys(), key=lambda tuple: tuple[0]): | 470 | if subtotal_lines: |
748 | 491 | # create the sequence number for those lines | 471 | second_result_lines += subtotal_lines |
719 | 492 | sequence_number = move_prefix + "-" + \ | ||
720 | 493 | period.date_start[5:7] + "-" + \ | ||
721 | 494 | period.date_start[:4] + "-" + \ | ||
722 | 495 | key[0] + "-" + \ | ||
723 | 496 | key[1] | ||
724 | 497 | |||
725 | 498 | subtotal_lines = self.create_subtotal(cr, uid, key, | ||
726 | 499 | account_lines_debit[key], | ||
727 | 500 | account_lines_functional_debit[key], | ||
728 | 501 | account_lines_functional_debit_no_ccy_adj[key], | ||
729 | 502 | counterpart_date, | ||
730 | 503 | country_code, | ||
731 | 504 | sequence_number) | ||
732 | 505 | if subtotal_lines: | ||
733 | 506 | third_report += subtotal_lines | ||
749 | 507 | 472 | ||
750 | 508 | self.shared_update_percent(cr, uid, pool, [bg_id], | 473 | self.shared_update_percent(cr, uid, pool, [bg_id], |
751 | 509 | share=0.05, finished=True, | 474 | share=0.05, finished=True, |
752 | 510 | already_done=move_share+analytic_share) | 475 | already_done=move_share+analytic_share) |
753 | 511 | 476 | ||
755 | 512 | # Write result to the final content | 477 | second_report = [second_header] + second_result_lines |
756 | 478 | |||
757 | 479 | # set prefix for file names | ||
758 | 480 | mission_code = '' | ||
759 | 481 | if parent_instance: | ||
760 | 482 | mission_code = "%s" % parent_instance.code[:3] | ||
761 | 483 | tm = strptime(period.date_start, '%Y-%m-%d') | ||
762 | 484 | year = str(tm.tm_year) | ||
763 | 485 | period_number = period and period.number and '%02d' % period.number or '' | ||
764 | 486 | prefix = '%sY%sP%s_' % (mission_code, year, period_number) | ||
765 | 487 | |||
766 | 513 | zip_buffer = StringIO.StringIO() | 488 | zip_buffer = StringIO.StringIO() |
767 | 514 | first_fileobj = NamedTemporaryFile('w+b', delete=False) | 489 | first_fileobj = NamedTemporaryFile('w+b', delete=False) |
768 | 515 | second_fileobj = NamedTemporaryFile('w+b', delete=False) | 490 | second_fileobj = NamedTemporaryFile('w+b', delete=False) |
771 | 516 | third_fileobj = NamedTemporaryFile('w+b', delete=False) | 491 | # for Raw data file: use double quotes for all entries |
772 | 517 | writer = csv.writer(first_fileobj, quoting=csv.QUOTE_ALL) | 492 | writer = csv.writer(first_fileobj, quoting=csv.QUOTE_ALL, delimiter=",") |
773 | 518 | for line in first_report: | 493 | for line in first_report: |
775 | 519 | writer.writerow(map(self._enc,line)) | 494 | writer.writerow(map(self._enc, line)) |
776 | 520 | first_fileobj.close() | 495 | first_fileobj.close() |
778 | 521 | writer = csv.writer(second_fileobj, quoting=csv.QUOTE_ALL) | 496 | # for formatted data file: use double quotes only for entries containing double quote or comma |
779 | 497 | writer = csv.writer(second_fileobj, quoting=csv.QUOTE_MINIMAL, delimiter=",") | ||
780 | 522 | for line in second_report: | 498 | for line in second_report: |
782 | 523 | writer.writerow(map(self._enc,line)) | 499 | writer.writerow(map(self._enc, line)) |
783 | 524 | second_fileobj.close() | 500 | second_fileobj.close() |
790 | 525 | writer = csv.writer(third_fileobj, quoting=csv.QUOTE_ALL) | 501 | |
785 | 526 | for line in third_report: | ||
786 | 527 | line.pop() | ||
787 | 528 | line.pop() | ||
788 | 529 | writer.writerow(map(self._enc,line)) | ||
789 | 530 | third_fileobj.close() | ||
791 | 531 | out_zipfile = zipfile.ZipFile(zip_buffer, "w") | 502 | out_zipfile = zipfile.ZipFile(zip_buffer, "w") |
795 | 532 | out_zipfile.write(first_fileobj.name, "%sRaw_Data.csv" % (integration_ref and integration_ref+'_' or ''), zipfile.ZIP_DEFLATED) | 503 | out_zipfile.write(first_fileobj.name, prefix + "Raw data UF export.csv", zipfile.ZIP_DEFLATED) |
796 | 533 | out_zipfile.write(second_fileobj.name, "%sUp_Expenses.csv" % (integration_ref and integration_ref+'_' or ''), zipfile.ZIP_DEFLATED) | 504 | out_zipfile.write(second_fileobj.name, prefix + "formatted data D365 import.csv", zipfile.ZIP_DEFLATED) |
794 | 534 | out_zipfile.write(third_fileobj.name, "%sUp_Balances.csv" % (integration_ref and integration_ref+'_' or ''), zipfile.ZIP_DEFLATED) | ||
797 | 535 | out_zipfile.close() | 505 | out_zipfile.close() |
798 | 536 | out = zip_buffer.getvalue() | 506 | out = zip_buffer.getvalue() |
799 | 537 | os.unlink(first_fileobj.name) | 507 | os.unlink(first_fileobj.name) |
800 | 538 | os.unlink(second_fileobj.name) | 508 | os.unlink(second_fileobj.name) |
801 | 539 | os.unlink(third_fileobj.name) | ||
802 | 540 | 509 | ||
803 | 541 | # Mark lines as exported | 510 | # Mark lines as exported |
804 | 542 | if move_line_ids: | 511 | if move_line_ids: |
805 | 543 | 512 | ||
806 | === modified file 'bin/addons/vertical_integration/wizard/wizard_hq_report_oca.py' | |||
807 | --- bin/addons/vertical_integration/wizard/wizard_hq_report_oca.py 2017-03-16 17:04:51 +0000 | |||
808 | +++ bin/addons/vertical_integration/wizard/wizard_hq_report_oca.py 2019-06-07 09:34:36 +0000 | |||
809 | @@ -23,6 +23,8 @@ | |||
810 | 23 | from tools.translate import _ | 23 | from tools.translate import _ |
811 | 24 | assert _ # pyflakes | 24 | assert _ # pyflakes |
812 | 25 | import time | 25 | import time |
813 | 26 | from time import strptime | ||
814 | 27 | |||
815 | 26 | 28 | ||
816 | 27 | class wizard_hq_report_oca(osv.osv_memory): | 29 | class wizard_hq_report_oca(osv.osv_memory): |
817 | 28 | _name = "wizard.hq.report.oca" | 30 | _name = "wizard.hq.report.oca" |
818 | @@ -60,14 +62,21 @@ | |||
819 | 60 | data = {} | 62 | data = {} |
820 | 61 | # add parameters | 63 | # add parameters |
821 | 62 | data['form'] = {} | 64 | data['form'] = {} |
822 | 65 | mission_code = '' | ||
823 | 66 | year = '' | ||
824 | 67 | period_number = '' | ||
825 | 63 | if wizard.instance_id: | 68 | if wizard.instance_id: |
826 | 69 | mission_code = "%s" % wizard.instance_id.code[:3] | ||
827 | 64 | # Get projects below instance | 70 | # Get projects below instance |
828 | 65 | data['form'].update({'instance_ids': [wizard.instance_id.id] + [x.id for x in wizard.instance_id.child_ids]}) | 71 | data['form'].update({'instance_ids': [wizard.instance_id.id] + [x.id for x in wizard.instance_id.child_ids]}) |
829 | 66 | if wizard.period_id: | 72 | if wizard.period_id: |
830 | 73 | tm = strptime(wizard.period_id.date_start, '%Y-%m-%d') | ||
831 | 74 | year = str(tm.tm_year) | ||
832 | 75 | period_number = wizard.period_id.number and '%02d' % wizard.period_id.number or '' | ||
833 | 67 | data['form'].update({'period_id': wizard.period_id.id}) | 76 | data['form'].update({'period_id': wizard.period_id.id}) |
834 | 68 | # UFTP-375: Permit user to select all lines or only previous ones | 77 | # UFTP-375: Permit user to select all lines or only previous ones |
835 | 69 | data['form'].update({'selection': wizard.selection}) | 78 | data['form'].update({'selection': wizard.selection}) |
837 | 70 | data['target_filename'] = '%s_%s_%s' % (_('Export to HQ System'), wizard.instance_id and wizard.instance_id.code or '', time.strftime('%Y%m%d')) | 79 | data['target_filename'] = '%sY%sP%s_formatted data D365 import' % (mission_code, year, period_number) |
838 | 71 | 80 | ||
839 | 72 | background_id = self.pool.get('memory.background.report').create(cr, uid, { | 81 | background_id = self.pool.get('memory.background.report').create(cr, uid, { |
840 | 73 | 'file_name': data['target_filename'], | 82 | 'file_name': data['target_filename'], |