Merge lp:~julie-w/unifield-server/US-3677 into lp:unifield-server
- US-3677
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 5130 |
Proposed branch: | lp:~julie-w/unifield-server/US-3677 |
Merge into: | lp:unifield-server |
Diff against target: |
288 lines (+210/-0) (has conflicts) 3 files modified
bin/addons/account_override/invoice.py (+157/-0) bin/addons/msf_profile/i18n/fr_MF.po (+43/-0) bin/osv/orm.py (+10/-0) Text conflict in bin/addons/msf_profile/i18n/fr_MF.po |
To merge this branch: | bzr merge lp:~julie-w/unifield-server/US-3677 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+357629@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/account_override/invoice.py' | |||
2 | --- bin/addons/account_override/invoice.py 2018-08-06 13:07:33 +0000 | |||
3 | +++ bin/addons/account_override/invoice.py 2018-10-22 13:50:56 +0000 | |||
4 | @@ -27,6 +27,7 @@ | |||
5 | 27 | from time import strftime | 27 | from time import strftime |
6 | 28 | from tools.translate import _ | 28 | from tools.translate import _ |
7 | 29 | from lxml import etree | 29 | from lxml import etree |
8 | 30 | from datetime import datetime | ||
9 | 30 | import re | 31 | import re |
10 | 31 | import netsvc | 32 | import netsvc |
11 | 32 | 33 | ||
12 | @@ -264,6 +265,141 @@ | |||
13 | 264 | 'is_merged_by_account': lambda *a: False, | 265 | 'is_merged_by_account': lambda *a: False, |
14 | 265 | } | 266 | } |
15 | 266 | 267 | ||
16 | 268 | def import_data_web(self, cr, uid, fields, datas, mode='init', current_module='', noupdate=False, context=None, filename=None, | ||
17 | 269 | display_all_errors=False, has_header=False): | ||
18 | 270 | """ | ||
19 | 271 | Overrides the standard import_data_web method for account.invoice model: | ||
20 | 272 | - based on the 3 values for "cost_center_id / destination_id / funding_pool_id", creates a new AD at 100% for | ||
21 | 273 | each invoice line and add it to "datas" | ||
22 | 274 | - removes these 3 values that won't be used in the SI line | ||
23 | 275 | - adapts the "fields" list accordingly | ||
24 | 276 | - converts the dates from the format '%d/%m/%Y' to the standard one '%Y-%m-%d' so the checks on dates are correctly made | ||
25 | 277 | """ | ||
26 | 278 | if context is None: | ||
27 | 279 | context = {} | ||
28 | 280 | new_data = datas | ||
29 | 281 | analytic_acc_obj = self.pool.get('account.analytic.account') | ||
30 | 282 | account_obj = self.pool.get('account.account') | ||
31 | 283 | analytic_distrib_obj = self.pool.get('analytic.distribution') | ||
32 | 284 | cc_distrib_line_obj = self.pool.get('cost.center.distribution.line') | ||
33 | 285 | fp_distrib_line_obj = self.pool.get('funding.pool.distribution.line') | ||
34 | 286 | curr_obj = self.pool.get('res.currency') | ||
35 | 287 | nb_ad_fields = 0 | ||
36 | 288 | if 'invoice_line/cost_center_id' in fields: | ||
37 | 289 | nb_ad_fields += 1 | ||
38 | 290 | if 'invoice_line/destination_id' in fields: | ||
39 | 291 | nb_ad_fields += 1 | ||
40 | 292 | if 'invoice_line/funding_pool_id' in fields: | ||
41 | 293 | nb_ad_fields += 1 | ||
42 | 294 | if nb_ad_fields: | ||
43 | 295 | if nb_ad_fields != 3: | ||
44 | 296 | raise osv.except_osv(_('Error'), | ||
45 | 297 | _('Either the Cost Center, the Destination, or the Funding Pool is missing.')) | ||
46 | 298 | # note: CC, dest and FP indexes always exist at this step | ||
47 | 299 | cc_index = fields.index('invoice_line/cost_center_id') | ||
48 | 300 | dest_index = fields.index('invoice_line/destination_id') | ||
49 | 301 | fp_index = fields.index('invoice_line/funding_pool_id') | ||
50 | 302 | si_line_name_index = 'invoice_line/name' in fields and fields.index('invoice_line/name') | ||
51 | 303 | si_journal_index = 'journal_id' in fields and fields.index('journal_id') | ||
52 | 304 | curr_index = 'currency_id' in fields and fields.index('currency_id') | ||
53 | 305 | account_index = 'invoice_line/account_id' in fields and fields.index('invoice_line/account_id') | ||
54 | 306 | doc_date_index = 'document_date' in fields and fields.index('document_date') | ||
55 | 307 | date_inv_index = 'date_invoice' in fields and fields.index('date_invoice') | ||
56 | 308 | new_data = [] | ||
57 | 309 | curr = False | ||
58 | 310 | for data in datas: | ||
59 | 311 | cc_ids = [] | ||
60 | 312 | dest_ids = [] | ||
61 | 313 | fp_ids = [] | ||
62 | 314 | distrib_id = '' | ||
63 | 315 | cc = len(data) > cc_index and data[cc_index].strip() | ||
64 | 316 | dest = len(data) > dest_index and data[dest_index].strip() | ||
65 | 317 | fp = len(data) > fp_index and data[fp_index].strip() | ||
66 | 318 | # check if details for SI line are filled in (based on the required field "name") | ||
67 | 319 | has_si_line = si_line_name_index is not False and len(data) > si_line_name_index and data[si_line_name_index].strip() | ||
68 | 320 | # process AD only for SI lines where at least one AD field has been filled in | ||
69 | 321 | # (otherwise no AD should be added to the line AND no error should be displayed) | ||
70 | 322 | if has_si_line and (cc or dest or fp): # at least one AD field has been filled in | ||
71 | 323 | if cc: | ||
72 | 324 | cc_dom = [('category', '=', 'OC'), ('type', '=', 'normal'), '|', ('code', '=ilike', cc), ('name', '=ilike', cc)] | ||
73 | 325 | cc_ids = analytic_acc_obj.search(cr, uid, cc_dom, order='id', limit=1, context=context) | ||
74 | 326 | if dest: | ||
75 | 327 | dest_dom = [('category', '=', 'DEST'), ('type', '=', 'normal'), '|', ('code', '=ilike', dest), ('name', '=ilike', dest)] | ||
76 | 328 | dest_ids = analytic_acc_obj.search(cr, uid, dest_dom, order='id', limit=1, context=context) | ||
77 | 329 | if fp: | ||
78 | 330 | fp_dom = [('category', '=', 'FUNDING'), ('type', '=', 'normal'), '|', ('code', '=ilike', fp), ('name', '=ilike', fp)] | ||
79 | 331 | fp_ids = analytic_acc_obj.search(cr, uid, fp_dom, order='id', limit=1, context=context) | ||
80 | 332 | if not cc_ids or not dest_ids or not fp_ids: | ||
81 | 333 | raise osv.except_osv(_('Error'), _('Either the Cost Center, the Destination, or the Funding Pool ' | ||
82 | 334 | 'was not found on the line %s.') % data) | ||
83 | 335 | else: | ||
84 | 336 | # create the Analytic Distribution | ||
85 | 337 | distrib_id = analytic_distrib_obj.create(cr, uid, {}, context=context) | ||
86 | 338 | # get the next currency to use IF NEED BE (cf for an SI with several lines the curr. is indicated on the first one only) | ||
87 | 339 | si_journal = si_journal_index is not False and len(data) > si_journal_index and data[si_journal_index].strip() | ||
88 | 340 | if si_journal: # first line of the SI | ||
89 | 341 | curr = curr_index is not False and len(data) > curr_index and data[curr_index].strip() | ||
90 | 342 | curr_ids = [] | ||
91 | 343 | if curr: # must exist at least on the first imported line | ||
92 | 344 | curr_ids = curr_obj.search(cr, uid, [('name', '=ilike', curr)], limit=1, context=context) | ||
93 | 345 | if not curr_ids: | ||
94 | 346 | raise osv.except_osv(_('Error'), | ||
95 | 347 | _('The currency was not found for the line %s.') % data) | ||
96 | 348 | vals = { | ||
97 | 349 | 'analytic_id': cc_ids[0], # analytic_id = Cost Center for the CC distrib line | ||
98 | 350 | 'percentage': 100.0, | ||
99 | 351 | 'distribution_id': distrib_id, | ||
100 | 352 | 'currency_id': curr_ids[0], | ||
101 | 353 | 'destination_id': dest_ids[0], | ||
102 | 354 | } | ||
103 | 355 | cc_distrib_line_obj.create(cr, uid, vals, context=context) | ||
104 | 356 | vals.update({ | ||
105 | 357 | 'analytic_id': fp_ids[0], # analytic_id = Funding Pool for the FP distrib line | ||
106 | 358 | 'cost_center_id': cc_ids[0], | ||
107 | 359 | }) | ||
108 | 360 | fp_distrib_line_obj.create(cr, uid, vals, context=context) | ||
109 | 361 | account_code = account_index is not False and len(data) > account_index and data[account_index].strip() | ||
110 | 362 | if account_code: | ||
111 | 363 | account_ids = account_obj.search(cr, uid, [('code', '=', account_code)], context=context, limit=1) | ||
112 | 364 | if not account_ids: | ||
113 | 365 | raise osv.except_osv(_('Error'), _('The account %s was not found on the line %s.') % (account_code, data)) | ||
114 | 366 | parent_id = False # no distrib. at header level | ||
115 | 367 | distrib_state = analytic_distrib_obj._get_distribution_state(cr, uid, distrib_id, parent_id, | ||
116 | 368 | account_ids[0], context=context) | ||
117 | 369 | if distrib_state == 'invalid': | ||
118 | 370 | raise osv.except_osv(_('Error'), _('The analytic distribution is invalid on the line %s.') % data) | ||
119 | 371 | # create a new list with the new distrib id and without the old AD fields | ||
120 | 372 | # to be done also if no AD to ensure the size of each data list is always the same | ||
121 | 373 | i = 0 | ||
122 | 374 | new_sub_list = [] | ||
123 | 375 | for d in data: # loop on each value of the file line | ||
124 | 376 | if i not in [cc_index, dest_index, fp_index]: | ||
125 | 377 | if doc_date_index is not False and date_inv_index is not False and i in [doc_date_index, date_inv_index]: | ||
126 | 378 | # format the date from '%d/%m/%Y' to '%Y-%m-%d' so the checks on dates are correctly made | ||
127 | 379 | raw_date = len(data) > i and data[i].strip() | ||
128 | 380 | try: | ||
129 | 381 | new_date = raw_date and datetime.strptime(raw_date, '%d/%m/%Y').strftime('%Y-%m-%d') or '' | ||
130 | 382 | except ValueError: | ||
131 | 383 | new_date = raw_date | ||
132 | 384 | new_sub_list.append(new_date) | ||
133 | 385 | else: | ||
134 | 386 | new_sub_list.append(d) | ||
135 | 387 | i += 1 | ||
136 | 388 | # add new field value | ||
137 | 389 | new_sub_list.append(distrib_id) | ||
138 | 390 | new_data.append(new_sub_list) | ||
139 | 391 | |||
140 | 392 | # remove old field names from fields | ||
141 | 393 | fields.remove('invoice_line/cost_center_id') | ||
142 | 394 | fields.remove('invoice_line/destination_id') | ||
143 | 395 | fields.remove('invoice_line/funding_pool_id') | ||
144 | 396 | # add new field | ||
145 | 397 | fields.append('invoice_line/analytic_distribution_id/.id') # .id = id in the database | ||
146 | 398 | |||
147 | 399 | return super(account_invoice, self).import_data_web(cr, uid, fields, new_data, mode=mode, current_module=current_module, | ||
148 | 400 | noupdate=noupdate, context=context, filename=filename, | ||
149 | 401 | display_all_errors=display_all_errors, has_header=has_header) | ||
150 | 402 | |||
151 | 267 | def onchange_company_id(self, cr, uid, ids, company_id, part_id, ctype, invoice_line, currency_id): | 403 | def onchange_company_id(self, cr, uid, ids, company_id, part_id, ctype, invoice_line, currency_id): |
152 | 268 | """ | 404 | """ |
153 | 269 | This is a method to redefine the journal_id domain with the current_instance taken into account | 405 | This is a method to redefine the journal_id domain with the current_instance taken into account |
154 | @@ -1529,6 +1665,15 @@ | |||
155 | 1529 | 1665 | ||
156 | 1530 | return res | 1666 | return res |
157 | 1531 | 1667 | ||
158 | 1668 | def _get_fake_m2o(self, cr, uid, ids, field_name=None, arg=None, context=None): | ||
159 | 1669 | """ | ||
160 | 1670 | Returns False for all ids | ||
161 | 1671 | """ | ||
162 | 1672 | res = {} | ||
163 | 1673 | for i in ids: | ||
164 | 1674 | res[i] = False | ||
165 | 1675 | return res | ||
166 | 1676 | |||
167 | 1532 | _columns = { | 1677 | _columns = { |
168 | 1533 | 'line_number': fields.integer(string='Line Number'), | 1678 | 'line_number': fields.integer(string='Line Number'), |
169 | 1534 | 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Account Computation')), | 1679 | 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Account Computation')), |
170 | @@ -1543,6 +1688,18 @@ | |||
171 | 1543 | 'reversed_invoice_line_id': fields.many2one('account.invoice.line', string='Reversed Invoice Line', | 1688 | 'reversed_invoice_line_id': fields.many2one('account.invoice.line', string='Reversed Invoice Line', |
172 | 1544 | help='Invoice line that has been reversed by this one through a ' | 1689 | help='Invoice line that has been reversed by this one through a ' |
173 | 1545 | '"refund cancel" or "refund modify"'), | 1690 | '"refund cancel" or "refund modify"'), |
174 | 1691 | 'cost_center_id': fields.function(_get_fake_m2o, method=True, type='many2one', store=False, | ||
175 | 1692 | states={'draft': [('readonly', False)]}, # see def detect_data in unifield-web/addons/openerp/controllers/impex.py | ||
176 | 1693 | relation="account.analytic.account", string='Cost Center', | ||
177 | 1694 | help="Field used for import only"), | ||
178 | 1695 | 'destination_id': fields.function(_get_fake_m2o, method=True, type='many2one', store=False, | ||
179 | 1696 | relation="account.analytic.account", string='Destination', | ||
180 | 1697 | states={'draft': [('readonly', False)]}, | ||
181 | 1698 | help="Field used for import only"), | ||
182 | 1699 | 'funding_pool_id': fields.function(_get_fake_m2o, method=True, type='many2one', store=False, | ||
183 | 1700 | relation="account.analytic.account", string='Funding Pool', | ||
184 | 1701 | states={'draft': [('readonly', False)]}, | ||
185 | 1702 | help="Field used for import only"), | ||
186 | 1546 | } | 1703 | } |
187 | 1547 | 1704 | ||
188 | 1548 | _defaults = { | 1705 | _defaults = { |
189 | 1549 | 1706 | ||
190 | === modified file 'bin/addons/msf_profile/i18n/fr_MF.po' | |||
191 | --- bin/addons/msf_profile/i18n/fr_MF.po 2018-10-17 09:42:30 +0000 | |||
192 | +++ bin/addons/msf_profile/i18n/fr_MF.po 2018-10-22 13:50:56 +0000 | |||
193 | @@ -38394,6 +38394,7 @@ | |||
194 | 38394 | #: field:hr.analytic.reallocation,funding_pool_id:0 | 38394 | #: field:hr.analytic.reallocation,funding_pool_id:0 |
195 | 38395 | #: field:hr.employee,funding_pool_id:0 | 38395 | #: field:hr.employee,funding_pool_id:0 |
196 | 38396 | #: field:hr.payroll.msf,funding_pool_id:0 | 38396 | #: field:hr.payroll.msf,funding_pool_id:0 |
197 | 38397 | #: field:account.invoice.line,funding_pool_id:0 | ||
198 | 38397 | #: report:addons/account/report/free_allocation_report.mako:208 | 38398 | #: report:addons/account/report/free_allocation_report.mako:208 |
199 | 38398 | #, python-format | 38399 | #, python-format |
200 | 38399 | msgid "Funding Pool" | 38400 | msgid "Funding Pool" |
201 | @@ -81948,6 +81949,7 @@ | |||
202 | 81948 | #: report:addons/sale/report/fo_allocation_report.mako:231 | 81949 | #: report:addons/sale/report/fo_allocation_report.mako:231 |
203 | 81949 | #: report:sale.order.allocation.report:0 | 81950 | #: report:sale.order.allocation.report:0 |
204 | 81950 | #: field:purchase.report,cost_center_id:0 | 81951 | #: field:purchase.report,cost_center_id:0 |
205 | 81952 | #: field:account.invoice.line,cost_center_id:0 | ||
206 | 81951 | #: code:addons/register_accounting/wizard/wizard_register_import.py:570 | 81953 | #: code:addons/register_accounting/wizard/wizard_register_import.py:570 |
207 | 81952 | #: report:addons/account/report/free_allocation_report.mako:205 | 81954 | #: report:addons/account/report/free_allocation_report.mako:205 |
208 | 81953 | #, python-format | 81955 | #, python-format |
209 | @@ -96141,6 +96143,7 @@ | |||
210 | 96141 | #: field:purchase.order.line.allocation.report,destination_id:0 | 96143 | #: field:purchase.order.line.allocation.report,destination_id:0 |
211 | 96142 | #: code:addons/register_accounting/wizard/wizard_register_import.py:558 | 96144 | #: code:addons/register_accounting/wizard/wizard_register_import.py:558 |
212 | 96143 | #: field:wizard.register.import.lines,destination_id:0 | 96145 | #: field:wizard.register.import.lines,destination_id:0 |
213 | 96146 | #: field:account.invoice.line,destination_id:0 | ||
214 | 96144 | #: report:addons/sale/report/fo_allocation_report.mako:228 | 96147 | #: report:addons/sale/report/fo_allocation_report.mako:228 |
215 | 96145 | #: report:sale.order.allocation.report:0 | 96148 | #: report:sale.order.allocation.report:0 |
216 | 96146 | #: field:sale.order.line.cancel,partner_id:0 | 96149 | #: field:sale.order.line.cancel,partner_id:0 |
217 | @@ -101952,6 +101955,7 @@ | |||
218 | 101952 | #: field:account.commitment.line,commit_number:0 | 101955 | #: field:account.commitment.line,commit_number:0 |
219 | 101953 | msgid "Commitment Voucher Number" | 101956 | msgid "Commitment Voucher Number" |
220 | 101954 | msgstr "Numéro du Bon d'Engagement" | 101957 | msgstr "Numéro du Bon d'Engagement" |
221 | 101958 | <<<<<<< TREE | ||
222 | 101955 | 101959 | ||
223 | 101956 | #. module: account_mcdb | 101960 | #. module: account_mcdb |
224 | 101957 | #: code:addons/account_mcdb/account_mcdb.py:1494 | 101961 | #: code:addons/account_mcdb/account_mcdb.py:1494 |
225 | @@ -101975,3 +101979,42 @@ | |||
226 | 101975 | #: code:addons/account_mcdb/account_mcdb.py:1276 | 101979 | #: code:addons/account_mcdb/account_mcdb.py:1276 |
227 | 101976 | msgid "Related entries" | 101980 | msgid "Related entries" |
228 | 101977 | msgstr "Ecritures associées" | 101981 | msgstr "Ecritures associées" |
229 | 101982 | ======= | ||
230 | 101983 | |||
231 | 101984 | #. module: account_override | ||
232 | 101985 | #: code:addons/account_override/invoice.py:339 | ||
233 | 101986 | #, python-format | ||
234 | 101987 | msgid "The currency was not found for the line %s." | ||
235 | 101988 | msgstr "La devise n'a pas été trouvée pour la ligne %s." | ||
236 | 101989 | |||
237 | 101990 | #. module: account_override | ||
238 | 101991 | #: code:addons/account_override/invoice.py:293 | ||
239 | 101992 | #, python-format | ||
240 | 101993 | msgid "Either the Cost Center, the Destination, or the Funding Pool is missing." | ||
241 | 101994 | msgstr "Il manque le Centre de Coût, la Destination, ou le Funding Pool." | ||
242 | 101995 | |||
243 | 101996 | #. module: account_override | ||
244 | 101997 | #: code:addons/account_override/invoice.py:325 | ||
245 | 101998 | #, python-format | ||
246 | 101999 | msgid "Either the Cost Center, the Destination, or the Funding Pool was not found on the line %s." | ||
247 | 102000 | msgstr "Le Centre de Coût, la Destination, ou le Funding Pool n'a pas été trouvé sur la ligne %s." | ||
248 | 102001 | |||
249 | 102002 | #. module: account_override | ||
250 | 102003 | #: code:addons/account_override/invoice.py:365 | ||
251 | 102004 | #, python-format | ||
252 | 102005 | msgid "The account %s was not found on the line %s." | ||
253 | 102006 | msgstr "Le compte %s n'a pas été trouvé sur la ligne %s." | ||
254 | 102007 | |||
255 | 102008 | #. module: account_override | ||
256 | 102009 | #: code:addons/account_override/invoice.py:370 | ||
257 | 102010 | #, python-format | ||
258 | 102011 | msgid "The analytic distribution is invalid on the line %s." | ||
259 | 102012 | msgstr "La distribution analytique est invalide sur la ligne %s." | ||
260 | 102013 | |||
261 | 102014 | #. module: account_override | ||
262 | 102015 | #: help:account.invoice.line,cost_center_id:0 | ||
263 | 102016 | #: help:account.invoice.line,destination_id:0 | ||
264 | 102017 | #: help:account.invoice.line,funding_pool_id:0 | ||
265 | 102018 | msgid "Field used for import only" | ||
266 | 102019 | msgstr "Champ utilisé pour l'import uniquement" | ||
267 | 102020 | >>>>>>> MERGE-SOURCE | ||
268 | 101978 | 102021 | ||
269 | === modified file 'bin/osv/orm.py' | |||
270 | --- bin/osv/orm.py 2018-08-14 14:10:58 +0000 | |||
271 | +++ bin/osv/orm.py 2018-10-22 13:50:56 +0000 | |||
272 | @@ -1122,6 +1122,16 @@ | |||
273 | 1122 | self._parent_store_compute(cr) | 1122 | self._parent_store_compute(cr) |
274 | 1123 | return (position, 0, 0, 0) | 1123 | return (position, 0, 0, 0) |
275 | 1124 | 1124 | ||
276 | 1125 | def import_data_web(self, cr, uid, fields, datas, mode='init', current_module='', noupdate=False, context=None, | ||
277 | 1126 | filename=None, display_all_errors=False, has_header=False): | ||
278 | 1127 | """ | ||
279 | 1128 | Import data method called at import from web ONLY (contrary to the import_data method also used for sync msgs). | ||
280 | 1129 | Call import_data by default but can be overridden if needed. | ||
281 | 1130 | """ | ||
282 | 1131 | return super(orm, self).import_data(cr, uid, fields, datas, mode=mode, current_module=current_module, | ||
283 | 1132 | noupdate=noupdate, context=context, filename=filename, | ||
284 | 1133 | display_all_errors=display_all_errors, has_header=has_header) | ||
285 | 1134 | |||
286 | 1125 | def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): | 1135 | def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): |
287 | 1126 | """ | 1136 | """ |
288 | 1127 | Read records with given ids with the given fields | 1137 | Read records with given ids with the given fields |