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
1=== modified file 'bin/addons/consumption_calculation/weekly_forecast_report.py'
2--- bin/addons/consumption_calculation/weekly_forecast_report.py 2020-07-27 12:47:30 +0000
3+++ bin/addons/consumption_calculation/weekly_forecast_report.py 2021-07-02 09:34:24 +0000
4@@ -517,7 +517,7 @@
5 product_id = product['id']
6 j += 1
7 cons = product_cons[product_id][1]
8- if not cons and not product['qty_available']:
9+ if not cons and not product['qty_available'] and not in_pipe_vals.get(product_id):
10 continue
11
12 weekly_cons = cons
13
14=== modified file 'bin/addons/procurement_cycle/replenishment.py'
15--- bin/addons/procurement_cycle/replenishment.py 2021-04-12 09:46:40 +0000
16+++ bin/addons/procurement_cycle/replenishment.py 2021-07-02 09:34:24 +0000
17@@ -2182,14 +2182,10 @@
18 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']}):
19 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_before_rdd'] = prod_id.incoming_qty
20
21- 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():
22- ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_before_rdd'] += qty
23
24 if not inv_review and 'pipeline_between_rdd_oc' in field_name:
25 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']}):
26 ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_between_rdd_oc'] = prod_id.incoming_qty
27- 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():
28- ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_between_rdd_oc'] += qty
29
30 return ret
31
32
33=== modified file 'bin/addons/stock/product.py'
34--- bin/addons/stock/product.py 2020-07-28 15:33:53 +0000
35+++ bin/addons/stock/product.py 2021-07-02 09:34:24 +0000
36@@ -236,28 +236,46 @@
37
38 results = []
39 results2 = []
40+ results3 = []
41 from_date = context.get('from_date',False)
42 from_strict_date = context.get('from_strict_date',False)
43 to_date = context.get('to_date',False)
44 date_str = False
45 date_values = False
46 where = [tuple(location_ids), tuple(location_ids), tuple(ids), tuple(states)]
47+
48+ pol_query_date = 'coalesce(pol.confirmed_delivery_date, pol.date_planned)'
49+ date_pol_str = ''
50+ date_pol_cond = {}
51 if from_strict_date and to_date:
52 date_str = "date>%s AND date<=%s"
53 where.append(tuple([from_strict_date]))
54 where.append(tuple([to_date]))
55+
56+ date_pol_str = 'AND %s>%%(from_date)s AND %s <=%%(to_date)s' % (pol_query_date, pol_query_date)
57+ date_pol_cond = {'from_date': from_strict_date, 'to_date': to_date}
58 elif from_date and to_date:
59 date_str = "date>=%s AND date<=%s"
60 where.append(tuple([from_date]))
61 where.append(tuple([to_date]))
62+
63+ date_pol_str = 'AND %s>=%%(from_date)s AND %s<=%%(to_date)s' % (pol_query_date, pol_query_date)
64+ date_pol_cond = {'from_date': from_date, 'to_date': to_date}
65 elif from_date:
66 date_str = "date>=%s"
67 date_values = [from_date]
68 where.append(tuple(date_values))
69+
70+ date_pol_str = 'AND %s>=%%(from_date)s' % (pol_query_date, )
71+ date_pol_cond = {'from_date': from_date}
72 elif to_date:
73 date_str = "date<=%s"
74 date_values = [to_date]
75 where.append(tuple(date_values))
76+
77+ date_pol_str = 'AND %s<=%%(to_date)s' % (pol_query_date, )
78+ date_pol_cond = {'to_date': to_date}
79+
80 prodlot_id = context.get('prodlot_id', False)
81 prodlot_id_str = (prodlot_id and (' AND prodlot_id = %s ' % str(prodlot_id)) or '')
82
83@@ -288,6 +306,27 @@
84 %s
85 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
86 results = cr.fetchall()
87+
88+ if not join_batch and 'assigned' in states:
89+ # Validated PO lines
90+ pol_cond = {'location_id': tuple(location_ids), 'product_id': tuple(ids)}
91+ pol_cond.update(date_pol_cond)
92+ cr.execute('''
93+ select sum(pol.product_qty) as qty, pol.product_id, pol.product_uom, t.uom_id
94+ from
95+ purchase_order_line pol, product_product p, product_template t
96+ where
97+ p.id = pol.product_id and
98+ t.id = p.product_tmpl_id and
99+ p.id in %%(product_id)s and
100+ pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n') and
101+ location_dest_id in %%(location_id)s
102+ %s
103+ group by pol.product_id, pol.product_uom, t.uom_id
104+ ''' % date_pol_str, pol_cond) # not_a_user_entry
105+ results3 = cr.fetchall()
106+
107+
108 if 'out' in what:
109 if not states and context.get('out_states'):
110 where[3] = tuple(context['out_states'])
111@@ -305,11 +344,11 @@
112 %s
113 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
114 results2 = cr.fetchall()
115- if results or results2:
116+ if results or results2 or results3:
117 uoms_o = {}
118 uom_obj = self.pool.get('product.uom')
119 context.update({'raise-exception': False})
120- for sign, data in [(1, results), (-1, results2)]:
121+ for sign, data in [(1, results), (-1, results2), (1, results3)]:
122 for amount, prod_id, prod_uom, pt_uom in data:
123 target_uom = context.get('uom', False) or pt_uom
124 if target_uom != prod_uom:
125@@ -420,43 +459,6 @@
126 res['fields']['qty_available']['string'] = _('Produced Qty')
127 return res
128
129- def get_pipeline_from_po(self, cr, uid, ids, from_date=False, to_date=False, location_ids=False, context=None):
130- '''
131- ids: product_ids
132-
133- return the pipeline from validated(-p) purchase order line
134- '''
135-
136- params = []
137- query = ''
138- if location_ids:
139- query += ' and location_dest_id in %s '
140- if isinstance(location_ids, (int, long)):
141- params.append((location_ids, ))
142- else:
143- params.append(tuple(location_ids))
144-
145- if from_date:
146- query += ' and coalesce(confirmed_delivery_date, date_planned) > %s '
147- params.append(from_date)
148-
149- if to_date:
150- query += ' and coalesce(confirmed_delivery_date, date_planned) <= %s '
151- params.append(to_date)
152-
153-
154- cr.execute('''
155- select
156- pol.product_id, sum(pol.product_qty)
157- from
158- purchase_order_line pol
159- where
160- pol.product_id in %s and
161- pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n')
162- ''' + query + '''
163- group by pol.product_id''',
164- [tuple(ids)]+params) # not_a_user_entry
165- return dict(cr.fetchall())
166
167 product_product()
168

Subscribers

People subscribed via source and target branches