Merge lp:~unifield-team/unifield-wm/utp-768-883 into lp:unifield-wm
- utp-768-883
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 1834 |
Proposed branch: | lp:~unifield-team/unifield-wm/utp-768-883 |
Merge into: | lp:unifield-wm |
Diff against target: |
673 lines (+413/-43) 3 files modified
consumption_calculation/consumption_calculation.py (+1/-1) consumption_calculation/history_consumption.py (+304/-22) consumption_calculation/history_consumption_view.xml (+108/-20) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-wm/utp-768-883 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Dev Team | Pending | ||
Review via email: mp+193786@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 'consumption_calculation/consumption_calculation.py' |
2 | --- consumption_calculation/consumption_calculation.py 2013-09-05 09:32:29 +0000 |
3 | +++ consumption_calculation/consumption_calculation.py 2013-11-04 14:27:47 +0000 |
4 | @@ -1646,7 +1646,7 @@ |
5 | |
6 | if not nb_months: nb_months = 1 |
7 | |
8 | - uom_id = self.browse(cr, uid, ids[0], context=context).uom_id.id |
9 | + uom_id = self.read(cr, uid, ids[0], ['uom_id'], context=context)['uom_id'][0] |
10 | res = res/nb_months |
11 | res = self.pool.get('product.uom')._compute_qty(cr, uid, uom_id, res, uom_id) |
12 | |
13 | |
14 | === modified file 'consumption_calculation/history_consumption.py' |
15 | --- consumption_calculation/history_consumption.py 2012-04-20 07:58:44 +0000 |
16 | +++ consumption_calculation/history_consumption.py 2013-11-04 14:27:47 +0000 |
17 | @@ -27,16 +27,29 @@ |
18 | |
19 | import time |
20 | |
21 | +HIST_STATUS = [('draft', 'Draft'), ('in_progress', 'In Progress'), ('ready', 'Ready')] |
22 | |
23 | -class product_history_consumption(osv.osv_memory): |
24 | +class product_history_consumption(osv.osv): |
25 | _name = 'product.history.consumption' |
26 | + _rec_name = 'location_id' |
27 | + |
28 | + def _get_status(self, cr, uid, ids, field_name, args, context=None): |
29 | + ''' |
30 | + Return the same status as status |
31 | + ''' |
32 | + res = {} |
33 | + |
34 | + for obj in self.browse(cr, uid, ids, context=context): |
35 | + res[obj.id] = obj.status |
36 | + |
37 | + return res |
38 | |
39 | _columns = { |
40 | - 'date_from': fields.date(string='From date', required=True), |
41 | - 'date_to': fields.date(string='To date', required=True), |
42 | + 'date_from': fields.date(string='From date'), |
43 | + 'date_to': fields.date(string='To date'), |
44 | 'month_ids': fields.one2many('product.history.consumption.month', 'history_id', string='Months'), |
45 | 'consumption_type': fields.selection([('rac', 'Real Average Consumption'), ('amc', 'Average Monthly Consumption')], |
46 | - string='Consumption type', required=True), |
47 | + string='Consumption type'), |
48 | 'location_id': fields.many2one('stock.location', string='Location', domain="[('usage', '=', 'internal')]"), |
49 | 'sublist_id': fields.many2one('product.list', string='List/Sublist'), |
50 | 'nomen_id': fields.many2one('product.nomenclature', string='Products\' nomenclature level'), |
51 | @@ -44,10 +57,17 @@ |
52 | 'nomen_manda_1': fields.many2one('product.nomenclature', 'Group'), |
53 | 'nomen_manda_2': fields.many2one('product.nomenclature', 'Family'), |
54 | 'nomen_manda_3': fields.many2one('product.nomenclature', 'Root'), |
55 | + 'requestor_id': fields.many2one('res.users', string='Requestor'), |
56 | + 'requestor_date': fields.datetime(string='Date of the demand'), |
57 | + 'fake_status': fields.function(_get_status, method=True, type='selection', selection=HIST_STATUS, readonly=True, string='Status'), |
58 | + 'status': fields.selection(HIST_STATUS, string='Status'), |
59 | } |
60 | |
61 | _defaults = { |
62 | 'date_to': lambda *a: (DateFrom(time.strftime('%Y-%m-%d')) + RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), |
63 | + 'requestor_id': lambda obj, cr, uid, c: uid, |
64 | + 'requestor_date': time.strftime('%Y-%m-%d %H:%M:%S'), |
65 | + 'status': 'draft', |
66 | } |
67 | |
68 | def open_history_consumption(self, cr, uid, ids, context=None): |
69 | @@ -82,21 +102,27 @@ |
70 | if date_from and date_to: |
71 | res['value'].update({'month_ids': []}) |
72 | current_date = DateFrom(date_from) + RelativeDateTime(day=1) |
73 | + if current_date > (DateFrom(date_to) + RelativeDateTime(months=1, day=1, days=-1)): |
74 | + return {'warning': {'title': _('Error'), |
75 | + 'message': _('The \'To Date\' should be greater than \'From Date\'')}} |
76 | # For all months in the period |
77 | while current_date <= (DateFrom(date_to) + RelativeDateTime(months=1, day=1, days=-1)): |
78 | search_ids = month_obj.search(cr, uid, [('name', '=', current_date.strftime('%m/%Y')), ('history_id', 'in', ids)], context=context) |
79 | # If the month is in the period and not in the list, create it |
80 | if not search_ids: |
81 | - month_id = month_obj.create(cr, uid, {'name': current_date.strftime('%m/%Y'), |
82 | - 'date_from': current_date.strftime('%Y-%m-%d'), |
83 | - 'date_to': (current_date + RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), |
84 | - 'history_id': ids[0]}) |
85 | - res['value']['month_ids'].append(month_id) |
86 | +# month_id = month_obj.create(cr, uid, {'name': current_date.strftime('%m/%Y'), |
87 | +# 'date_from': current_date.strftime('%Y-%m-%d'), |
88 | +# 'date_to': (current_date + RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), |
89 | +# 'history_id': ids[0]}, context=context) |
90 | +# res['value']['month_ids'].append(month_id) |
91 | + res['value']['month_ids'].append({'name': current_date.strftime('%m/%Y'), |
92 | + 'date_from': current_date.strftime('%Y-%m-%d'), |
93 | + 'date_to': (current_date + RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d')}) |
94 | else: |
95 | res['value']['month_ids'].extend(search_ids) |
96 | current_date = current_date + RelativeDateTime(months=1) |
97 | else: |
98 | - res['value'] = {'month_ids': [False]} |
99 | + res['value'] = {'month_ids': []} |
100 | |
101 | # Delete all months out of the period |
102 | del_months = [] |
103 | @@ -109,9 +135,9 @@ |
104 | return res |
105 | |
106 | |
107 | - def create_lines(self, cr, uid, ids, context=None): |
108 | + def get_data(self, cr, uid, ids, context=None): |
109 | ''' |
110 | - Create one line by product for the period |
111 | + Get parameters of the report |
112 | ''' |
113 | if not context: |
114 | context = {} |
115 | @@ -131,6 +157,9 @@ |
116 | nb_months = len(months) |
117 | total_consumption = {} |
118 | |
119 | + if not months: |
120 | + raise osv.except_osv(_('Error'), _('You have to choose at least one month for consumption history')) |
121 | + |
122 | if obj.nomen_manda_0: |
123 | for report in self.browse(cr, uid, ids, context=context): |
124 | product_ids = [] |
125 | @@ -158,7 +187,6 @@ |
126 | if product.id not in products: |
127 | batch_mandatory = product.batch_management or product.perishable |
128 | date_mandatory = not product.batch_management and product.perishable |
129 | - self.pool.get('product.product').write(cr, uid, ids, {'name': product.id,}) |
130 | |
131 | if obj.sublist_id: |
132 | context.update({'search_default_list_ids': obj.sublist_id.id}) |
133 | @@ -171,13 +199,72 @@ |
134 | domain = [] |
135 | |
136 | new_context = context.copy() |
137 | - new_context.update({'months': [], 'amc': obj.consumption_type == 'amc' and 'AMC' or 'RAC', 'obj_id': obj.id, 'history_cons': True}) |
138 | + new_context.update({'months': [], 'amc': obj.consumption_type == 'amc' and 'AMC' or 'RAC', 'obj_id': obj.id, 'history_cons': True, 'need_thread': True}) |
139 | |
140 | # For each month, compute the RAC |
141 | for month in self.pool.get('product.history.consumption.month').browse(cr, uid, months, context=context): |
142 | new_context['months'].append({'date_from': month.date_from, 'date_to': month.date_to}) |
143 | |
144 | |
145 | + return product_ids, domain, new_context |
146 | + |
147 | + def create_lines(self, cr, uid, ids, context=None): |
148 | + ''' |
149 | + Create one line by product for the period |
150 | + ''' |
151 | + if not context: |
152 | + context = {} |
153 | + |
154 | + product_ids, domain, new_context = self.get_data(cr, uid, ids, context=context) |
155 | + |
156 | + if not product_ids: |
157 | + product_ids = self.pool.get('product.product').search(cr, uid, [], context=new_context) |
158 | + |
159 | + import threading |
160 | + self.write(cr, uid, ids, {'status': 'in_progress'}, context=context) |
161 | + new_thread = threading.Thread(target=self._create_lines, args=(cr, uid, ids, product_ids, new_context)) |
162 | + new_thread.start() |
163 | + new_thread.join(10.0) |
164 | + if new_thread.isAlive(): |
165 | + view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'consumption_calculation', 'history_consumption_waiting_view')[1] |
166 | + return {'type': 'ir.actions.act_window', |
167 | + 'res_model': 'product.history.consumption', |
168 | + 'view_type': 'form', |
169 | + 'view_mode': 'form', |
170 | + 'res_id': ids[0], |
171 | + 'view_id': [view_id], |
172 | + 'context': new_context, |
173 | + 'target': 'same'} |
174 | + |
175 | + return self.open_report(cr, uid, ids, context=new_context) |
176 | + |
177 | + def _create_lines(self, cr, uid, ids, product_ids, context=None): |
178 | + ''' |
179 | + Create lines in background |
180 | + ''' |
181 | + import pooler |
182 | + new_cr = pooler.get_db(cr.dbname).cursor() |
183 | + |
184 | + try: |
185 | + self.pool.get('product.product').read(new_cr, uid, product_ids, ['average'], context=context) |
186 | + except Exception, e: |
187 | + cr.rollback() |
188 | + self.write(new_cr, uid, ids, {'status': 'ready'}, context=context) |
189 | + |
190 | + new_cr.commit() |
191 | + new_cr.close() |
192 | + |
193 | + return |
194 | + |
195 | + def open_report(self, cr, uid, ids, context=None): |
196 | + ''' |
197 | + Open the report |
198 | + ''' |
199 | + if not context: |
200 | + context = {} |
201 | + |
202 | + product_ids, domain, new_context = self.get_data(cr, uid, ids, context=context) |
203 | + |
204 | return {'type': 'ir.actions.act_window', |
205 | 'res_model': 'product.product', |
206 | 'domain': domain, |
207 | @@ -186,6 +273,33 @@ |
208 | 'context': new_context, |
209 | 'target': 'dummy'} |
210 | |
211 | + def unlink(self, cr, uid, ids, context=None): |
212 | + ''' |
213 | + Remove the data saved in DB |
214 | + ''' |
215 | + hist_obj = self.pool.get('product.history.consumption.product') |
216 | + for cons in self.browse(cr, uid, ids, context=context): |
217 | + hist_ids = hist_obj.search(cr, uid, [('consumption_id', '=', cons.id)], context=context) |
218 | + hist_obj.unlink(cr, uid, hist_ids, context=context) |
219 | + return super(product_history_consumption, self).unlink(cr, uid, ids, context=context) |
220 | + |
221 | + def in_progress(self, cr, uid, ids, context=None): |
222 | + ''' |
223 | + Return dummy |
224 | + ''' |
225 | + return self.go_to_list(cr, uid, ids, context=context) |
226 | + |
227 | + def go_to_list(self, cr, uid, ids, context=None): |
228 | + ''' |
229 | + Returns to the list of reports |
230 | + ''' |
231 | + return {'type': 'ir.actions.act_window', |
232 | + 'res_model': 'product.history.consumption', |
233 | + 'view_mode': 'tree,form', |
234 | + 'view_type': 'form', |
235 | + 'target': 'dummy', |
236 | + 'context': context} |
237 | + |
238 | ############################################################################################################################## |
239 | # The code below aims to enable filtering products regarding their nomenclature. |
240 | # NB: the difference with the other same kind of product filters (with nomenclature and sublist) is that here we are dealing with osv_memory |
241 | @@ -212,7 +326,7 @@ |
242 | |
243 | product_history_consumption() |
244 | |
245 | -class product_history_consumption_month(osv.osv_memory): |
246 | +class product_history_consumption_month(osv.osv): |
247 | _name = 'product.history.consumption.month' |
248 | _order = 'name, date_from, date_to' |
249 | |
250 | @@ -220,7 +334,7 @@ |
251 | 'name': fields.char(size=64, string='Month'), |
252 | 'date_from': fields.date(string='Date from'), |
253 | 'date_to': fields.date(string='Date to'), |
254 | - 'history_id': fields.many2one('product.history.consumption', string='History'), |
255 | + 'history_id': fields.many2one('product.history.consumption', string='History', ondelete='cascade'), |
256 | } |
257 | |
258 | product_history_consumption_month() |
259 | @@ -230,6 +344,79 @@ |
260 | _name = 'product.product' |
261 | _inherit = 'product.product' |
262 | |
263 | + def export_data(self, cr, uid, ids, fields_to_export, context=None): |
264 | + ''' |
265 | + Override the export_data function to add fictive fields |
266 | + ''' |
267 | + if not context: |
268 | + context = {} |
269 | + |
270 | + history_fields = [] |
271 | + new_fields_to_export = [] |
272 | + fields_sort = {} |
273 | + sort_iter2 = 0 |
274 | + default_code_index = False |
275 | + remove_default_code = False |
276 | + |
277 | + # Add fictive fields |
278 | + if context.get('history_cons', False): |
279 | + months = context.get('months', []) |
280 | + |
281 | + if context.get('amc', False) and 'average' in fields_to_export: |
282 | + history_fields.append('average') |
283 | + |
284 | + if 'default_code' not in fields_to_export: |
285 | + fields_to_export.append('default_code') |
286 | + remove_default_code = True |
287 | + |
288 | + for month in months: |
289 | + field_name = DateFrom(month.get('date_from')).strftime('%m_%Y') |
290 | + if field_name in fields_to_export: |
291 | + history_fields.append(field_name) |
292 | + |
293 | + # Prepare normal fields to export to avoid error on export data with fictive fields |
294 | + to_export_iter = 0 |
295 | + for f in fields_to_export: |
296 | + if f not in history_fields: |
297 | + new_fields_to_export.append(f) |
298 | + if f == 'default_code': |
299 | + default_code_index = to_export_iter |
300 | + to_export_iter += 1 |
301 | + |
302 | + # We save the order of the fields to read them in the good order |
303 | + fields_sort.update({sort_iter2: f}) |
304 | + sort_iter2 += 1 |
305 | + |
306 | + res = super(product_product, self).export_data(cr, uid, ids, new_fields_to_export, context=dict(context, history_cons=False)) |
307 | + |
308 | + # Set the fields in the good order |
309 | + if context.get('history_cons', False): |
310 | + new_data = [] |
311 | + for r in res['datas']: |
312 | + new_r = [] |
313 | + product_id = self.search(cr, uid, [('default_code', '=', r[default_code_index])], context=context) |
314 | + datas = {} |
315 | + if product_id: |
316 | + datas = self.read(cr, uid, product_id, history_fields + ['default_code', 'id'], context=context)[0] |
317 | + |
318 | + iter_r = 0 |
319 | + for j in range(sort_iter2): |
320 | + f = fields_sort[j] |
321 | + |
322 | + if f == 'default_code' and remove_default_code: |
323 | + continue |
324 | + |
325 | + if f in history_fields: |
326 | + new_r.append(str(datas.get(f, 0.00))) |
327 | + else: |
328 | + new_r.append(r[iter_r]) |
329 | + iter_r += 1 |
330 | + new_data.append(new_r) |
331 | + |
332 | + res['datas'] = new_data |
333 | + |
334 | + return res |
335 | + |
336 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): |
337 | if not context: |
338 | context = {} |
339 | @@ -255,7 +442,7 @@ |
340 | tmp_months.sort() |
341 | |
342 | for month in tmp_months: |
343 | - line_view += """<field name="%s" />""" % DateFrom(month).strftime('%m/%Y') |
344 | + line_view += """<field name="%s" />""" % DateFrom(month).strftime('%m_%Y') |
345 | |
346 | line_view += "</tree>" |
347 | |
348 | @@ -282,7 +469,7 @@ |
349 | months = context.get('months', []) |
350 | |
351 | for month in months: |
352 | - res.update({DateFrom(month.get('date_from')).strftime('%m/%Y'): {'digits': (16,2), |
353 | + res.update({DateFrom(month.get('date_from')).strftime('%m_%Y'): {'digits': (16,2), |
354 | 'selectable': True, |
355 | 'type': 'float', |
356 | 'string': '%s' % DateFrom(month.get('date_from')).strftime('%m/%Y')}}) |
357 | @@ -299,8 +486,11 @@ |
358 | ''' |
359 | Set value for each month |
360 | ''' |
361 | + cons_prod_obj = self.pool.get('product.history.consumption.product') |
362 | + |
363 | if context is None: |
364 | context = {} |
365 | + |
366 | if context.get('history_cons', False): |
367 | res = super(product_product, self).read(cr, uid, ids, vals, context=context, load=load) |
368 | |
369 | @@ -317,28 +507,120 @@ |
370 | raise osv.except_osv(_('Error'), _('No months found !')) |
371 | |
372 | obj_id = context.get('obj_id') |
373 | - |
374 | for r in res: |
375 | total_consumption = 0.00 |
376 | for month in context.get('months'): |
377 | - field_name = DateFrom(month.get('date_from')).strftime('%m/%Y') |
378 | + field_name = DateFrom(month.get('date_from')).strftime('%m_%Y') |
379 | cons_context = {'from_date': month.get('date_from'), 'to_date': month.get('date_to'), 'location_id': context.get('location_id')} |
380 | consumption = 0.00 |
381 | + cons_prod_domain = [('name', '=', field_name), |
382 | + ('product_id', '=', r['id']), |
383 | + ('consumption_id', '=', obj_id)] |
384 | if context.get('amc') == 'AMC': |
385 | - consumption = self.pool.get('product.product').compute_amc(cr, uid, r['id'], context=cons_context) |
386 | + cons_prod_domain.append(('cons_type', '=', 'amc')) |
387 | + cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context) |
388 | + if cons_id: |
389 | + consumption = cons_prod_obj.browse(cr, uid, cons_id[0], context=context).value |
390 | + else: |
391 | + consumption = self.pool.get('product.product').compute_amc(cr, uid, r['id'], context=cons_context) or 0.00 |
392 | + cons_prod_obj.create(cr, uid, {'name': field_name, |
393 | + 'product_id': r['id'], |
394 | + 'consumption_id': obj_id, |
395 | + 'cons_type': 'amc', |
396 | + 'value': consumption}, context=context) |
397 | else: |
398 | - consumption = self.pool.get('product.product').browse(cr, uid, r['id'], context=cons_context).monthly_consumption |
399 | + cons_prod_domain.append(('cons_type', '=', 'fmc')) |
400 | + cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context) |
401 | + if cons_id: |
402 | + consumption = cons_prod_obj.browse(cr, uid, cons_id[0], context=context).value |
403 | + else: |
404 | + consumption = self.pool.get('product.product').browse(cr, uid, r['id'], context=cons_context).monthly_consumption or 0.00 |
405 | + cons_prod_obj.create(cr, uid, {'name': field_name, |
406 | + 'product_id': r['id'], |
407 | + 'consumption_id': obj_id, |
408 | + 'cons_type': 'fmc', |
409 | + 'value': consumption}, context=context) |
410 | total_consumption += consumption |
411 | # Update the value for the month |
412 | r.update({field_name: consumption}) |
413 | |
414 | # Update the average field |
415 | + cons_prod_domain = [('name', '=', 'average'), |
416 | + ('product_id', '=', r['id']), |
417 | + ('consumption_id', '=', obj_id), |
418 | + ('cons_type', '=', context.get('amc') == 'AMC' and 'amc' or 'fmc')] |
419 | r.update({'average': round(total_consumption/float(len(context.get('months'))),2)}) |
420 | + cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context) |
421 | + if cons_id: |
422 | + cons_prod_obj.write(cr, uid, cons_id, {'value': r['average']}, context=context) |
423 | + else: |
424 | + cons_prod_obj.create(cr, uid, {'name': 'average', |
425 | + 'product_id': r['id'], |
426 | + 'consumption_id': obj_id, |
427 | + 'cons_type': context.get('amc') == 'AMC' and 'amc' or 'fmc', |
428 | + 'value': r['average']}, context=context) |
429 | else: |
430 | res = super(product_product, self).read(cr, uid, ids, vals, context=context, load=load) |
431 | |
432 | return res |
433 | |
434 | + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): |
435 | + ''' |
436 | + Update the search method to sort by fictive fields if needed |
437 | + ''' |
438 | + if not context: |
439 | + context = {} |
440 | + |
441 | + hist_obj = self.pool.get('product.history.consumption.product') |
442 | + |
443 | + res = super(product_product, self).search(cr, uid, args, offset, limit, order, context, count) |
444 | + |
445 | + if context.get('history_cons', False) and context.get('obj_id', False) and order: |
446 | + hist_domain = [('consumption_id', '=', context.get('obj_id'))] |
447 | + if context.get('amc') == 'AMC': |
448 | + hist_domain.append(('cons_type', '=', 'amc')) |
449 | + else: |
450 | + hist_domain.append(('cons_type', '=', 'fmc')) |
451 | + |
452 | + for order_part in order.split(','): |
453 | + order_split = order_part.strip().split(' ') |
454 | + order_field = order_split[0] |
455 | + order_direction = order_split[1].strip() if len(order_split) == 2 else '' |
456 | + if order_field != 'id' and order_field not in self._columns and order_field not in self._inherit_fields: |
457 | + hist_domain.append(('name', '=', order_field)) |
458 | + hist_ids = hist_obj.search(cr, uid, hist_domain, offset=offset, limit=limit, order='value %s' % order_direction, context=context) |
459 | + res = list(x['product_id'][0] for x in hist_obj.read(cr, uid, hist_ids, ['product_id'], context=context)) |
460 | + break |
461 | + |
462 | + return res |
463 | + |
464 | product_product() |
465 | |
466 | + |
467 | +class product_history_consumption_product(osv.osv): |
468 | + _name = 'product.history.consumption.product' |
469 | + |
470 | + _columns = { |
471 | + 'consumption_id': fields.many2one('product.history.consumption', string='Consumption id', select=1, ondelete='cascade'), |
472 | + 'product_id': fields.many2one('product.product', string='Product'), |
473 | + 'name': fields.char(size=64, string='Name'), |
474 | + 'value': fields.float(digits=(16,2), string='Value', select=1), |
475 | + 'cons_type': fields.selection([('amc', 'AMC'), ('fmc', 'FMC')], string='Consumption type'), |
476 | + } |
477 | + |
478 | + def read(self, cr, uid, ids, fields, context=None, load='_classic_read'): |
479 | + ''' |
480 | + Return the result in the same order as given in ids |
481 | + ''' |
482 | + res = super(product_history_consumption_product, self).read(cr, uid, ids, fields, context=context, load=load) |
483 | + |
484 | + res_final = [None]*len(ids) |
485 | + for r in res: |
486 | + r_index = ids.index(r['id']) |
487 | + res_final[r_index] = r |
488 | + |
489 | + return res_final |
490 | + |
491 | +product_history_consumption_product() |
492 | + |
493 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
494 | |
495 | === modified file 'consumption_calculation/history_consumption_view.xml' |
496 | --- consumption_calculation/history_consumption_view.xml 2012-03-16 15:09:27 +0000 |
497 | +++ consumption_calculation/history_consumption_view.xml 2013-11-04 14:27:47 +0000 |
498 | @@ -7,60 +7,147 @@ |
499 | <field name="model">product.history.consumption</field> |
500 | <field name="type">form</field> |
501 | <field name="arch" type="xml"> |
502 | - <form string="Product historical consumption"> |
503 | - <group colspan="2" col="2"> |
504 | - <separator colspan="2" string="Period parameters" /> |
505 | - <field name="date_from" on_change="date_change(date_from, date_to)" /> |
506 | - <field name="date_to" on_change="date_change(date_from, date_to)" /> |
507 | - <field name="month_ids" nolabel="1" colspan="2"> |
508 | - <tree string="Months" hide_new_button="1" noteditable="True" editable="top"> |
509 | - <field name="name" /> |
510 | - </tree> |
511 | - </field> |
512 | - </group> |
513 | + <form string="Product historical consumption" hide_new_button="1" hide_duplicate_button="1"> |
514 | + <field name="status" invisible="1" /> |
515 | + <group colspan="2" col="2"> |
516 | + <separator colspan="2" string="Period parameters" /> |
517 | + <field name="date_from" on_change="date_change(date_from, date_to)" required="True" attrs="{'readonly': [('status', '!=', 'draft')]}" /> |
518 | + <field name="date_to" on_change="date_change(date_from, date_to)" required="True" attrs="{'readonly': [('status', '!=', 'draft')]}" /> |
519 | + <field name="month_ids" nolabel="1" colspan="2" attrs="{'readonly': [('status', '!=', 'draft')]}"> |
520 | + <tree string="Months" hide_new_button="1" noteditable="True" editable="top"> |
521 | + <field name="name" /> |
522 | + </tree> |
523 | + </field> |
524 | + </group> |
525 | |
526 | - <group colspan="2" col="2"> |
527 | + <group colspan="2" col="2"> |
528 | <separator colspan="2" string="Consumption parameters" /> |
529 | - <field name="consumption_type" /> |
530 | - <field name="location_id" attrs="{'invisible': [('consumption_type', '!=', 'rac')], 'required': [('consumption_type', '=', 'rac')]}" /> |
531 | + <field name="consumption_type" required="True" attrs="{'readonly': [('status', '!=', 'draft')]}" /> |
532 | + <field name="location_id" attrs="{'invisible': [('consumption_type', '!=', 'rac')], 'required': [('consumption_type', '=', 'rac')], 'readonly': [('status', '!=', 'draft')]}" /> |
533 | <separator colspan="2" string="Product parameters" /> |
534 | - <field name="sublist_id" attrs="{'readonly': [('nomen_manda_0', '!=', False)]}" /> |
535 | - <group colspan="2" col="4" attrs="{'readonly': [('sublist_id', '!=', False)]}"> |
536 | + <field name="sublist_id" attrs="{'readonly': ['|', ('nomen_manda_0', '!=', False), ('status', '!=', 'draft')]}" /> |
537 | + <group colspan="2" col="4"> |
538 | <field name="nomen_manda_0" |
539 | domain="[('level', '=', '0'), ('type', '=', 'mandatory')]" |
540 | widget="selection" |
541 | on_change="onChangeSearchNomenclature(0, 'mandatory', nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, False)" |
542 | + attrs="{'readonly': [('status', '!=', 'draft')]}" |
543 | /> |
544 | <field name="nomen_manda_1" |
545 | domain="[('id','=', 0)]" |
546 | widget="selection" |
547 | get_selection="get_nomen" |
548 | on_change="onChangeSearchNomenclature(1, 'mandatory', nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, False)" |
549 | + attrs="{'readonly': [('status', '!=', 'draft')]}" |
550 | /> |
551 | <field name="nomen_manda_2" |
552 | domain="[('id','=', 0)]" |
553 | widget="selection" |
554 | get_selection="get_nomen" |
555 | on_change="onChangeSearchNomenclature(2, 'mandatory', nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, False)" |
556 | + attrs="{'readonly': [('status', '!=', 'draft')]}" |
557 | /> |
558 | <field name="nomen_manda_3" |
559 | domain="[('id','=', 0)]" |
560 | widget="selection" |
561 | get_selection="get_nomen" |
562 | on_change="onChangeSearchNomenclature(3, 'mandatory', nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, False)" |
563 | + attrs="{'readonly': [('status', '!=', 'draft')]}" |
564 | /> |
565 | </group> |
566 | <separator colspan="2" string="Actions" /> |
567 | - <button name="create_lines" type="object" string="View historical data" icon="gtk-execute" colspan="2" /> |
568 | + <button name="create_lines" type="object" string="View historical data" icon="terp-check" colspan="2" attrs="{'readonly': [('status', '=', 'in_progress')], 'invisible': [('status', '=', 'ready')]}" /> |
569 | + <button name="open_report" type="object" string="View historical data" icon="terp-check" colspan="2" attrs="{'invisible': [('status', '!=', 'ready')]}" /> |
570 | </group> |
571 | </form> |
572 | </field> |
573 | - </record> |
574 | - |
575 | - <menuitem id="menu_product_history_consumption" |
576 | + </record> |
577 | + |
578 | + <record id="history_consumption_waiting_view" model="ir.ui.view"> |
579 | + <field name="name">history.consumption.waiting.view</field> |
580 | + <field name="model">product.history.consumption</field> |
581 | + <field name="type">form</field> |
582 | + <field name="priority" eval="99" /> |
583 | + <field name="arch" type="xml"> |
584 | + <form string="Status of the report" hide_new_button="1" hide_delete_button="1"> |
585 | + <label> </label> |
586 | + <group colspan="2" col="2"> |
587 | + <html> |
588 | + <div style="align: center"> |
589 | + <p style="font-size:14px;align:center"> |
590 | + Your historical consumption demand will be treated quickly.<br /> |
591 | + </p> |
592 | + <p style="font-size:14px;align:center"> |
593 | + Due to the volume of data, your history cannot be shown immediatly.<br /> |
594 | + </p> |
595 | + <p style="font-size:14px;align:center"> |
596 | + When the report will be ready, you can access to it by the menu Warehouse / Reporting / Consumption reports / Historical consumption.<br /> |
597 | + </p> |
598 | + </div> |
599 | + </html> |
600 | + </group> |
601 | + <label> </label> |
602 | + <!-- |
603 | + Remove the button because a click on this button waits the end of the thread to display the list of reports |
604 | + <label> </label> |
605 | + <button name="go_to_list" string="Return to the list of history consumption reports" icon="gtk-undo" type="object" colspan="2"/> |
606 | + <label> </label>--> |
607 | + </form> |
608 | + </field> |
609 | + </record> |
610 | + |
611 | + <record id="history_consumption_search_view" model="ir.ui.view"> |
612 | + <field name="name">history.consumption.search.view</field> |
613 | + <field name="model">product.history.consumption</field> |
614 | + <field name="type">search</field> |
615 | + <field name="arch" type="xml"> |
616 | + <search string="Historical consumptions"> |
617 | + <field name="requestor_id" /> |
618 | + <filter domain="[('requestor_id', '=', uid)]" icon="terp-personal" help="My requests" /> |
619 | + <field name="requestor_date" /> |
620 | + </search> |
621 | + </field> |
622 | + </record> |
623 | + |
624 | + <record id="history_consumption_tree_view" model="ir.ui.view"> |
625 | + <field name="name">history.consumption.tree.view</field> |
626 | + <field name="model">product.history.consumption</field> |
627 | + <field name="type">tree</field> |
628 | + <field name="arch" type="xml"> |
629 | + <tree string="Historical consumptions" noteditable="1" colors="grey:status=='in_progress';green:status=='ready'"> |
630 | + <field name="requestor_date" /> |
631 | + <field name="requestor_id" /> |
632 | + <field name="date_from" /> |
633 | + <field name="date_to" /> |
634 | + <field name="consumption_type" /> |
635 | + <field name="location_id" /> |
636 | + <field name="sublist_id" /> |
637 | + <field name="nomen_manda_0" /> |
638 | + <field name="nomen_manda_1" /> |
639 | + <field name="nomen_manda_2" /> |
640 | + <field name="nomen_manda_3" /> |
641 | + <button name="in_progress" type="object" icon="gtk-refresh" string="In Progress" attrs="{'invisible': [('status', '!=', 'in_progress')]}" /> |
642 | + <button name="open_report" type="object" icon="terp-check" string="Open report" attrs="{'invisible': [('status', '!=', 'ready')]}"/> |
643 | + <field name="fake_status" /> |
644 | + <field name="status" invisible="1" /> |
645 | + </tree> |
646 | + </field> |
647 | + </record> |
648 | + |
649 | + <record id="action_history_consumption" model="ir.actions.act_window"> |
650 | + <field name="name">History consumptions</field> |
651 | + <field name="res_model">product.history.consumption</field> |
652 | + <field name="view_type">form</field> |
653 | + <field name="view_mode">tree,form</field> |
654 | + <field name="target"></field> |
655 | + </record> |
656 | + |
657 | + <menuitem id="menu_product_history_consumption" |
658 | + action="action_history_consumption" |
659 | name="Historical consumption" |
660 | parent="warehouse_consumption_menu" /> |
661 | |
662 | + <!-- |
663 | <record id="action_open_history_consumption_view" model="ir.actions.server"> |
664 | <field name="name">History consumption</field> |
665 | <field name="model_id" ref="model_product_history_consumption"/> |
666 | @@ -76,6 +163,7 @@ |
667 | <field eval="'ir.actions.server,%d'%action_open_history_consumption_view" name="value"/> |
668 | <field eval="True" name="object"/> |
669 | </record> |
670 | + --> |
671 | |
672 | </data> |
673 | </openerp> |