Merge lp:~unifield-team/unifield-server/qt-us-2292 into lp:unifield-server

Proposed by Quentin THEURET @Amaris
Status: Merged
Merged at revision: 4263
Proposed branch: lp:~unifield-team/unifield-server/qt-us-2292
Merge into: lp:unifield-server
Diff against target: 116 lines (+37/-16)
2 files modified
bin/addons/consumption_calculation/consumption_calculation.py (+10/-7)
bin/addons/consumption_calculation/history_consumption.py (+27/-9)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/qt-us-2292
Reviewer Review Type Date Requested Status
Jeff Allen Pending
Review via email: mp+318072@code.launchpad.net
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/consumption_calculation/consumption_calculation.py'
2--- bin/addons/consumption_calculation/consumption_calculation.py 2017-01-31 15:03:10 +0000
3+++ bin/addons/consumption_calculation/consumption_calculation.py 2017-02-23 08:12:35 +0000
4@@ -1654,13 +1654,16 @@
5 for id in ids:
6 res[id] = 0.00
7 if from_date and to_date:
8- rcr_domain = ['&', '&', ('product_id', '=', id), ('rac_id.cons_location_id', 'in', location_ids),
9- # All lines with a report started out the period and finished in the period
10- '|', '&', ('rac_id.period_to', '>=', from_date), ('rac_id.period_to', '<=', to_date),
11- # All lines with a report started in the period and finished out the period
12- '|', '&', ('rac_id.period_from', '<=', to_date), ('rac_id.period_from', '>=', from_date),
13- # All lines with a report started before the period and finished after the period
14- '&', ('rac_id.period_from', '<=', from_date), ('rac_id.period_to', '>=', to_date)]
15+ rac_ids = self.pool.get('real.average.consumption').search(cr, uid, [
16+ ('cons_location_id', 'in', location_ids),
17+ # All lines with a report started out the period and finished in the period
18+ '|', '&', ('period_to', '>=', from_date), ('period_to', '<=', to_date),
19+ #  All lines with a report started in the period and finished out the period
20+ '|', '&', ('period_from', '<=', to_date), ('period_from', '>=', from_date),
21+ #  All lines with a report started before the period and finished after the period
22+ '&', ('period_from', '<=', from_date), ('period_to', '>=', to_date)
23+ ])
24+ rcr_domain = [('product_id', '=', id), ('rac_id', 'in', rac_ids)]
25
26 rcr_line_ids = self.pool.get('real.average.consumption.line').search(cr, uid, rcr_domain, context=context)
27 for line in self.pool.get('real.average.consumption.line').browse(cr, uid, rcr_line_ids, context=context):
28
29=== modified file 'bin/addons/consumption_calculation/history_consumption.py'
30--- bin/addons/consumption_calculation/history_consumption.py 2016-10-12 10:07:50 +0000
31+++ bin/addons/consumption_calculation/history_consumption.py 2017-02-23 08:12:35 +0000
32@@ -148,8 +148,8 @@
33 'location_id',
34 'id',
35 'nomen_manda_0',
36- 'sublist_id']
37- , context=context)
38+ 'sublist_id'],
39+ context=context)
40 product_ids = []
41
42 # Update the locations in context
43@@ -242,6 +242,23 @@
44 import pooler
45 new_cr = pooler.get_db(cr.dbname).cursor()
46
47+ res = self.browse(cr, uid, ids[0], context=context)
48+ if res.consumption_type == 'rac':
49+ cr.execute('''
50+ SELECT distinct(product_id)
51+ FROM real_average_consumption_line
52+ WHERE move_id IS NOT NULL
53+ ''')
54+ else:
55+ cr.execute('''
56+ SELECT distinct(product_id)
57+ FROM stock_move
58+ WHERE state = 'done'
59+ AND
60+ (location_id IN %s OR location_dest_id IN %s)
61+ ''', (tuple(context.get('location_id', [])), tuple(context.get('location_id', []))))
62+ product_ids = [x[0] for x in cr.fetchall()]
63+
64 # split ids into slices to not read a lot record in the same time (memory)
65 ids_len = len(product_ids)
66 slice_len = 500
67@@ -260,6 +277,7 @@
68 except Exception, e:
69 logging.getLogger('history.consumption').warn('Exception in read average', exc_info=True)
70 new_cr.rollback()
71+
72 self.write(new_cr, uid, ids, {'status': 'ready'}, context=context)
73
74 new_cr.commit()
75@@ -549,7 +567,7 @@
76 ('consumption_id', '=', obj_id)]
77 if context.get('amc') == 'AMC':
78 cons_prod_domain.append(('cons_type', '=', 'amc'))
79- cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context)
80+ cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, order='NO_ORDER', limit=1, context=context)
81 if cons_id:
82 consumption = cons_prod_obj.browse(cr, uid, cons_id[0], context=context).value
83 else:
84@@ -561,7 +579,7 @@
85 'value': consumption}, context=context)
86 else:
87 cons_prod_domain.append(('cons_type', '=', 'fmc'))
88- cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context)
89+ cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, order='NO_ORDER', limit=1, context=context)
90 if cons_id:
91 consumption = cons_prod_obj.browse(cr, uid, cons_id[0], context=context).value
92 else:
93@@ -581,7 +599,7 @@
94 ('consumption_id', '=', obj_id),
95 ('cons_type', '=', context.get('amc') == 'AMC' and 'amc' or 'fmc')]
96 r.update({'average': round(total_consumption/float(len(context.get('months'))),2)})
97- cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, context=context)
98+ cons_id = cons_prod_obj.search(cr, uid, cons_prod_domain, order='NO_ORDER', limit=1, context=context)
99 if cons_id:
100 cons_prod_obj.write(cr, uid, cons_id, {'value': r['average']}, context=context)
101 else:
102@@ -664,10 +682,10 @@
103
104 _columns = {
105 'consumption_id': fields.many2one('product.history.consumption', string='Consumption id', select=1, ondelete='cascade'),
106- 'product_id': fields.many2one('product.product', string='Product'),
107- 'name': fields.char(size=64, string='Name'),
108- 'value': fields.float(digits=(16,2), string='Value', select=1),
109- 'cons_type': fields.selection([('amc', 'AMC'), ('fmc', 'FMC')], string='Consumption type'),
110+ 'product_id': fields.many2one('product.product', string='Product', select=1),
111+ 'name': fields.char(size=64, string='Name', select=1),
112+ 'value': fields.float(digits=(16,2), string='Value'),
113+ 'cons_type': fields.selection([('amc', 'AMC'), ('fmc', 'FMC')], string='Consumption type', select=1),
114 }
115
116 def read(self, cr, uid, ids, fields, context=None, load='_classic_read'):

Subscribers

People subscribed via source and target branches

to all changes: