Merge lp:~jfb-tempo-consulting/unifield-server/US-7927 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 6041
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-7927
Merge into: lp:unifield-server
Diff against target: 167 lines (+42/-44)
3 files modified
bin/addons/consumption_calculation/weekly_forecast_report.py (+1/-1)
bin/addons/procurement_cycle/replenishment.py (+0/-4)
bin/addons/stock/product.py (+41/-39)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-7927
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+405086@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
=== modified file 'bin/addons/consumption_calculation/weekly_forecast_report.py'
--- bin/addons/consumption_calculation/weekly_forecast_report.py 2020-07-27 12:47:30 +0000
+++ bin/addons/consumption_calculation/weekly_forecast_report.py 2021-07-02 09:34:24 +0000
@@ -517,7 +517,7 @@
517 product_id = product['id']517 product_id = product['id']
518 j += 1518 j += 1
519 cons = product_cons[product_id][1]519 cons = product_cons[product_id][1]
520 if not cons and not product['qty_available']:520 if not cons and not product['qty_available'] and not in_pipe_vals.get(product_id):
521 continue521 continue
522522
523 weekly_cons = cons523 weekly_cons = cons
524524
=== modified file 'bin/addons/procurement_cycle/replenishment.py'
--- bin/addons/procurement_cycle/replenishment.py 2021-04-12 09:46:40 +0000
+++ bin/addons/procurement_cycle/replenishment.py 2021-07-02 09:34:24 +0000
@@ -2182,14 +2182,10 @@
2182 for prod_id in prod_obj.browse(cr, uid, segment[seg_id]['prod_seg_line'].keys(), fields_to_fetch=['incoming_qty'], context={'to_date': segment[seg_id]['to_date_rdd'], 'location': segment[seg_id]['location_ids']}):2182 for prod_id in prod_obj.browse(cr, uid, segment[seg_id]['prod_seg_line'].keys(), fields_to_fetch=['incoming_qty'], context={'to_date': segment[seg_id]['to_date_rdd'], 'location': segment[seg_id]['location_ids']}):
2183 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_before_rdd'] = prod_id.incoming_qty2183 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_before_rdd'] = prod_id.incoming_qty
21842184
2185 for prod_id, qty in prod_obj.get_pipeline_from_po(cr, uid, segment[seg_id]['prod_seg_line'].keys(), to_date=segment[seg_id]['to_date_rdd'], location_ids=segment[seg_id]['location_ids']).iteritems():
2186 ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_before_rdd'] += qty
21872185
2188 if not inv_review and 'pipeline_between_rdd_oc' in field_name:2186 if not inv_review and 'pipeline_between_rdd_oc' in field_name:
2189 for prod_id in prod_obj.browse(cr, uid, segment[seg_id]['prod_seg_line'].keys(), fields_to_fetch=['incoming_qty'], context={'from_strict_date': segment[seg_id]['to_date_rdd'], 'to_date': segment[seg_id]['to_date_oc'], 'location': segment[seg_id]['location_ids']}):2187 for prod_id in prod_obj.browse(cr, uid, segment[seg_id]['prod_seg_line'].keys(), fields_to_fetch=['incoming_qty'], context={'from_strict_date': segment[seg_id]['to_date_rdd'], 'to_date': segment[seg_id]['to_date_oc'], 'location': segment[seg_id]['location_ids']}):
2190 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_between_rdd_oc'] = prod_id.incoming_qty2188 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_between_rdd_oc'] = prod_id.incoming_qty
2191 for prod_id, qty in prod_obj.get_pipeline_from_po(cr, uid, segment[seg_id]['prod_seg_line'].keys(), from_date=segment[seg_id]['to_date_rdd'], to_date=segment[seg_id]['to_date_oc'], location_ids=segment[seg_id]['location_ids']).iteritems():
2192 ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_between_rdd_oc'] += qty
21932189
2194 return ret2190 return ret
21952191
21962192
=== modified file 'bin/addons/stock/product.py'
--- bin/addons/stock/product.py 2020-07-28 15:33:53 +0000
+++ bin/addons/stock/product.py 2021-07-02 09:34:24 +0000
@@ -236,28 +236,46 @@
236236
237 results = []237 results = []
238 results2 = []238 results2 = []
239 results3 = []
239 from_date = context.get('from_date',False)240 from_date = context.get('from_date',False)
240 from_strict_date = context.get('from_strict_date',False)241 from_strict_date = context.get('from_strict_date',False)
241 to_date = context.get('to_date',False)242 to_date = context.get('to_date',False)
242 date_str = False243 date_str = False
243 date_values = False244 date_values = False
244 where = [tuple(location_ids), tuple(location_ids), tuple(ids), tuple(states)]245 where = [tuple(location_ids), tuple(location_ids), tuple(ids), tuple(states)]
246
247 pol_query_date = 'coalesce(pol.confirmed_delivery_date, pol.date_planned)'
248 date_pol_str = ''
249 date_pol_cond = {}
245 if from_strict_date and to_date:250 if from_strict_date and to_date:
246 date_str = "date>%s AND date<=%s"251 date_str = "date>%s AND date<=%s"
247 where.append(tuple([from_strict_date]))252 where.append(tuple([from_strict_date]))
248 where.append(tuple([to_date]))253 where.append(tuple([to_date]))
254
255 date_pol_str = 'AND %s>%%(from_date)s AND %s <=%%(to_date)s' % (pol_query_date, pol_query_date)
256 date_pol_cond = {'from_date': from_strict_date, 'to_date': to_date}
249 elif from_date and to_date:257 elif from_date and to_date:
250 date_str = "date>=%s AND date<=%s"258 date_str = "date>=%s AND date<=%s"
251 where.append(tuple([from_date]))259 where.append(tuple([from_date]))
252 where.append(tuple([to_date]))260 where.append(tuple([to_date]))
261
262 date_pol_str = 'AND %s>=%%(from_date)s AND %s<=%%(to_date)s' % (pol_query_date, pol_query_date)
263 date_pol_cond = {'from_date': from_date, 'to_date': to_date}
253 elif from_date:264 elif from_date:
254 date_str = "date>=%s"265 date_str = "date>=%s"
255 date_values = [from_date]266 date_values = [from_date]
256 where.append(tuple(date_values))267 where.append(tuple(date_values))
268
269 date_pol_str = 'AND %s>=%%(from_date)s' % (pol_query_date, )
270 date_pol_cond = {'from_date': from_date}
257 elif to_date:271 elif to_date:
258 date_str = "date<=%s"272 date_str = "date<=%s"
259 date_values = [to_date]273 date_values = [to_date]
260 where.append(tuple(date_values))274 where.append(tuple(date_values))
275
276 date_pol_str = 'AND %s<=%%(to_date)s' % (pol_query_date, )
277 date_pol_cond = {'to_date': to_date}
278
261 prodlot_id = context.get('prodlot_id', False)279 prodlot_id = context.get('prodlot_id', False)
262 prodlot_id_str = (prodlot_id and (' AND prodlot_id = %s ' % str(prodlot_id)) or '')280 prodlot_id_str = (prodlot_id and (' AND prodlot_id = %s ' % str(prodlot_id)) or '')
263281
@@ -288,6 +306,27 @@
288 %s306 %s
289 group by m.product_id, m.product_uom, t.uom_id""" % (join_batch, prodlot_id_str, date_str, where_batch),tuple(where)) # not_a_user_entry307 group by m.product_id, m.product_uom, t.uom_id""" % (join_batch, prodlot_id_str, date_str, where_batch),tuple(where)) # not_a_user_entry
290 results = cr.fetchall()308 results = cr.fetchall()
309
310 if not join_batch and 'assigned' in states:
311 # Validated PO lines
312 pol_cond = {'location_id': tuple(location_ids), 'product_id': tuple(ids)}
313 pol_cond.update(date_pol_cond)
314 cr.execute('''
315 select sum(pol.product_qty) as qty, pol.product_id, pol.product_uom, t.uom_id
316 from
317 purchase_order_line pol, product_product p, product_template t
318 where
319 p.id = pol.product_id and
320 t.id = p.product_tmpl_id and
321 p.id in %%(product_id)s and
322 pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n') and
323 location_dest_id in %%(location_id)s
324 %s
325 group by pol.product_id, pol.product_uom, t.uom_id
326 ''' % date_pol_str, pol_cond) # not_a_user_entry
327 results3 = cr.fetchall()
328
329
291 if 'out' in what:330 if 'out' in what:
292 if not states and context.get('out_states'):331 if not states and context.get('out_states'):
293 where[3] = tuple(context['out_states'])332 where[3] = tuple(context['out_states'])
@@ -305,11 +344,11 @@
305 %s344 %s
306 group by m.product_id, m.product_uom, t.uom_id""" % (join_batch, prodlot_id_str, date_str, where_batch),tuple(where)) # not_a_user_entry345 group by m.product_id, m.product_uom, t.uom_id""" % (join_batch, prodlot_id_str, date_str, where_batch),tuple(where)) # not_a_user_entry
307 results2 = cr.fetchall()346 results2 = cr.fetchall()
308 if results or results2:347 if results or results2 or results3:
309 uoms_o = {}348 uoms_o = {}
310 uom_obj = self.pool.get('product.uom')349 uom_obj = self.pool.get('product.uom')
311 context.update({'raise-exception': False})350 context.update({'raise-exception': False})
312 for sign, data in [(1, results), (-1, results2)]:351 for sign, data in [(1, results), (-1, results2), (1, results3)]:
313 for amount, prod_id, prod_uom, pt_uom in data:352 for amount, prod_id, prod_uom, pt_uom in data:
314 target_uom = context.get('uom', False) or pt_uom353 target_uom = context.get('uom', False) or pt_uom
315 if target_uom != prod_uom:354 if target_uom != prod_uom:
@@ -420,43 +459,6 @@
420 res['fields']['qty_available']['string'] = _('Produced Qty')459 res['fields']['qty_available']['string'] = _('Produced Qty')
421 return res460 return res
422461
423 def get_pipeline_from_po(self, cr, uid, ids, from_date=False, to_date=False, location_ids=False, context=None):
424 '''
425 ids: product_ids
426
427 return the pipeline from validated(-p) purchase order line
428 '''
429
430 params = []
431 query = ''
432 if location_ids:
433 query += ' and location_dest_id in %s '
434 if isinstance(location_ids, (int, long)):
435 params.append((location_ids, ))
436 else:
437 params.append(tuple(location_ids))
438
439 if from_date:
440 query += ' and coalesce(confirmed_delivery_date, date_planned) > %s '
441 params.append(from_date)
442
443 if to_date:
444 query += ' and coalesce(confirmed_delivery_date, date_planned) <= %s '
445 params.append(to_date)
446
447
448 cr.execute('''
449 select
450 pol.product_id, sum(pol.product_qty)
451 from
452 purchase_order_line pol
453 where
454 pol.product_id in %s and
455 pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n')
456 ''' + query + '''
457 group by pol.product_id''',
458 [tuple(ids)]+params) # not_a_user_entry
459 return dict(cr.fetchall())
460462
461product_product()463product_product()
462464

Subscribers

People subscribed via source and target branches