Merge lp:~jfb-tempo-consulting/unifield-server/US-7927 into lp:unifield-server
- US-7927
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+405086@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/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 | 517 | product_id = product['id'] | 517 | product_id = product['id'] |
6 | 518 | j += 1 | 518 | j += 1 |
7 | 519 | cons = product_cons[product_id][1] | 519 | cons = product_cons[product_id][1] |
9 | 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): |
10 | 521 | continue | 521 | continue |
11 | 522 | 522 | ||
12 | 523 | weekly_cons = cons | 523 | weekly_cons = cons |
13 | 524 | 524 | ||
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 | 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']}): |
19 | 2183 | ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_before_rdd'] = prod_id.incoming_qty | 2183 | ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_before_rdd'] = prod_id.incoming_qty |
20 | 2184 | 2184 | ||
21 | 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(): | ||
22 | 2186 | ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_before_rdd'] += qty | ||
23 | 2187 | 2185 | ||
24 | 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: |
25 | 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']}): |
26 | 2190 | ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_between_rdd_oc'] = prod_id.incoming_qty | 2188 | ret[segment[seg_id]['prod_seg_line'][prod_id.id]]['pipeline_between_rdd_oc'] = prod_id.incoming_qty |
27 | 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(): | ||
28 | 2192 | ret[segment[seg_id]['prod_seg_line'][prod_id]]['pipeline_between_rdd_oc'] += qty | ||
29 | 2193 | 2189 | ||
30 | 2194 | return ret | 2190 | return ret |
31 | 2195 | 2191 | ||
32 | 2196 | 2192 | ||
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 | 236 | 236 | ||
38 | 237 | results = [] | 237 | results = [] |
39 | 238 | results2 = [] | 238 | results2 = [] |
40 | 239 | results3 = [] | ||
41 | 239 | from_date = context.get('from_date',False) | 240 | from_date = context.get('from_date',False) |
42 | 240 | from_strict_date = context.get('from_strict_date',False) | 241 | from_strict_date = context.get('from_strict_date',False) |
43 | 241 | to_date = context.get('to_date',False) | 242 | to_date = context.get('to_date',False) |
44 | 242 | date_str = False | 243 | date_str = False |
45 | 243 | date_values = False | 244 | date_values = False |
46 | 244 | where = [tuple(location_ids), tuple(location_ids), tuple(ids), tuple(states)] | 245 | where = [tuple(location_ids), tuple(location_ids), tuple(ids), tuple(states)] |
47 | 246 | |||
48 | 247 | pol_query_date = 'coalesce(pol.confirmed_delivery_date, pol.date_planned)' | ||
49 | 248 | date_pol_str = '' | ||
50 | 249 | date_pol_cond = {} | ||
51 | 245 | if from_strict_date and to_date: | 250 | if from_strict_date and to_date: |
52 | 246 | date_str = "date>%s AND date<=%s" | 251 | date_str = "date>%s AND date<=%s" |
53 | 247 | where.append(tuple([from_strict_date])) | 252 | where.append(tuple([from_strict_date])) |
54 | 248 | where.append(tuple([to_date])) | 253 | where.append(tuple([to_date])) |
55 | 254 | |||
56 | 255 | date_pol_str = 'AND %s>%%(from_date)s AND %s <=%%(to_date)s' % (pol_query_date, pol_query_date) | ||
57 | 256 | date_pol_cond = {'from_date': from_strict_date, 'to_date': to_date} | ||
58 | 249 | elif from_date and to_date: | 257 | elif from_date and to_date: |
59 | 250 | date_str = "date>=%s AND date<=%s" | 258 | date_str = "date>=%s AND date<=%s" |
60 | 251 | where.append(tuple([from_date])) | 259 | where.append(tuple([from_date])) |
61 | 252 | where.append(tuple([to_date])) | 260 | where.append(tuple([to_date])) |
62 | 261 | |||
63 | 262 | date_pol_str = 'AND %s>=%%(from_date)s AND %s<=%%(to_date)s' % (pol_query_date, pol_query_date) | ||
64 | 263 | date_pol_cond = {'from_date': from_date, 'to_date': to_date} | ||
65 | 253 | elif from_date: | 264 | elif from_date: |
66 | 254 | date_str = "date>=%s" | 265 | date_str = "date>=%s" |
67 | 255 | date_values = [from_date] | 266 | date_values = [from_date] |
68 | 256 | where.append(tuple(date_values)) | 267 | where.append(tuple(date_values)) |
69 | 268 | |||
70 | 269 | date_pol_str = 'AND %s>=%%(from_date)s' % (pol_query_date, ) | ||
71 | 270 | date_pol_cond = {'from_date': from_date} | ||
72 | 257 | elif to_date: | 271 | elif to_date: |
73 | 258 | date_str = "date<=%s" | 272 | date_str = "date<=%s" |
74 | 259 | date_values = [to_date] | 273 | date_values = [to_date] |
75 | 260 | where.append(tuple(date_values)) | 274 | where.append(tuple(date_values)) |
76 | 275 | |||
77 | 276 | date_pol_str = 'AND %s<=%%(to_date)s' % (pol_query_date, ) | ||
78 | 277 | date_pol_cond = {'to_date': to_date} | ||
79 | 278 | |||
80 | 261 | prodlot_id = context.get('prodlot_id', False) | 279 | prodlot_id = context.get('prodlot_id', False) |
81 | 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 '') |
82 | 263 | 281 | ||
83 | @@ -288,6 +306,27 @@ | |||
84 | 288 | %s | 306 | %s |
85 | 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_entry | 307 | 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 | 290 | results = cr.fetchall() | 308 | results = cr.fetchall() |
87 | 309 | |||
88 | 310 | if not join_batch and 'assigned' in states: | ||
89 | 311 | # Validated PO lines | ||
90 | 312 | pol_cond = {'location_id': tuple(location_ids), 'product_id': tuple(ids)} | ||
91 | 313 | pol_cond.update(date_pol_cond) | ||
92 | 314 | cr.execute(''' | ||
93 | 315 | select sum(pol.product_qty) as qty, pol.product_id, pol.product_uom, t.uom_id | ||
94 | 316 | from | ||
95 | 317 | purchase_order_line pol, product_product p, product_template t | ||
96 | 318 | where | ||
97 | 319 | p.id = pol.product_id and | ||
98 | 320 | t.id = p.product_tmpl_id and | ||
99 | 321 | p.id in %%(product_id)s and | ||
100 | 322 | pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n') and | ||
101 | 323 | location_dest_id in %%(location_id)s | ||
102 | 324 | %s | ||
103 | 325 | group by pol.product_id, pol.product_uom, t.uom_id | ||
104 | 326 | ''' % date_pol_str, pol_cond) # not_a_user_entry | ||
105 | 327 | results3 = cr.fetchall() | ||
106 | 328 | |||
107 | 329 | |||
108 | 291 | if 'out' in what: | 330 | if 'out' in what: |
109 | 292 | if not states and context.get('out_states'): | 331 | if not states and context.get('out_states'): |
110 | 293 | where[3] = tuple(context['out_states']) | 332 | where[3] = tuple(context['out_states']) |
111 | @@ -305,11 +344,11 @@ | |||
112 | 305 | %s | 344 | %s |
113 | 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_entry | 345 | 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 | 307 | results2 = cr.fetchall() | 346 | results2 = cr.fetchall() |
116 | 308 | if results or results2: | 347 | if results or results2 or results3: |
117 | 309 | uoms_o = {} | 348 | uoms_o = {} |
118 | 310 | uom_obj = self.pool.get('product.uom') | 349 | uom_obj = self.pool.get('product.uom') |
119 | 311 | context.update({'raise-exception': False}) | 350 | context.update({'raise-exception': False}) |
121 | 312 | for sign, data in [(1, results), (-1, results2)]: | 351 | for sign, data in [(1, results), (-1, results2), (1, results3)]: |
122 | 313 | for amount, prod_id, prod_uom, pt_uom in data: | 352 | for amount, prod_id, prod_uom, pt_uom in data: |
123 | 314 | target_uom = context.get('uom', False) or pt_uom | 353 | target_uom = context.get('uom', False) or pt_uom |
124 | 315 | if target_uom != prod_uom: | 354 | if target_uom != prod_uom: |
125 | @@ -420,43 +459,6 @@ | |||
126 | 420 | res['fields']['qty_available']['string'] = _('Produced Qty') | 459 | res['fields']['qty_available']['string'] = _('Produced Qty') |
127 | 421 | return res | 460 | return res |
128 | 422 | 461 | ||
129 | 423 | def get_pipeline_from_po(self, cr, uid, ids, from_date=False, to_date=False, location_ids=False, context=None): | ||
130 | 424 | ''' | ||
131 | 425 | ids: product_ids | ||
132 | 426 | |||
133 | 427 | return the pipeline from validated(-p) purchase order line | ||
134 | 428 | ''' | ||
135 | 429 | |||
136 | 430 | params = [] | ||
137 | 431 | query = '' | ||
138 | 432 | if location_ids: | ||
139 | 433 | query += ' and location_dest_id in %s ' | ||
140 | 434 | if isinstance(location_ids, (int, long)): | ||
141 | 435 | params.append((location_ids, )) | ||
142 | 436 | else: | ||
143 | 437 | params.append(tuple(location_ids)) | ||
144 | 438 | |||
145 | 439 | if from_date: | ||
146 | 440 | query += ' and coalesce(confirmed_delivery_date, date_planned) > %s ' | ||
147 | 441 | params.append(from_date) | ||
148 | 442 | |||
149 | 443 | if to_date: | ||
150 | 444 | query += ' and coalesce(confirmed_delivery_date, date_planned) <= %s ' | ||
151 | 445 | params.append(to_date) | ||
152 | 446 | |||
153 | 447 | |||
154 | 448 | cr.execute(''' | ||
155 | 449 | select | ||
156 | 450 | pol.product_id, sum(pol.product_qty) | ||
157 | 451 | from | ||
158 | 452 | purchase_order_line pol | ||
159 | 453 | where | ||
160 | 454 | pol.product_id in %s and | ||
161 | 455 | pol.state in ('validated', 'validated_n', 'sourced_sy', 'sourced_v', 'sourced_n') | ||
162 | 456 | ''' + query + ''' | ||
163 | 457 | group by pol.product_id''', | ||
164 | 458 | [tuple(ids)]+params) # not_a_user_entry | ||
165 | 459 | return dict(cr.fetchall()) | ||
166 | 460 | 462 | ||
167 | 461 | product_product() | 463 | product_product() |
168 | 462 | 464 |