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

Proposed by jftempo
Status: Merged
Merged at revision: 5904
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-7926
Merge into: lp:unifield-server
Diff against target: 112 lines (+14/-25)
1 file modified
bin/addons/consumption_calculation/expiry_calculation.py (+14/-25)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-7926
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+396134@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/expiry_calculation.py'
2--- bin/addons/consumption_calculation/expiry_calculation.py 2020-01-17 12:55:13 +0000
3+++ bin/addons/consumption_calculation/expiry_calculation.py 2021-01-12 10:43:22 +0000
4@@ -313,7 +313,6 @@
5 if consumption_type == 'fmc':
6 res = product_obj.browse(cr, uid, product_id, context=new_context).reviewed_consumption
7 elif consumption_type == 'amc':
8- # TODO TEST JFB
9 res = product_obj.compute_amc(cr, uid, product_id, context=new_context)[product_id]
10 else:
11 res = product_obj.browse(cr, uid, product_id, context=new_context).monthly_consumption
12@@ -382,7 +381,6 @@
13 else:
14 new_cr = cr
15
16- move_obj = self.pool.get('stock.move')
17 lot_obj = self.pool.get('stock.production.lot')
18 loc_obj = self.pool.get('stock.location')
19 product_obj = self.pool.get('product.product')
20@@ -448,16 +446,7 @@
21 location_ids = loc_obj.search(new_cr, uid, [('location_id', 'child_of', report.location_id.id), ('quarantine_location', '=', False), ('id', 'not in', not_loc_ids)], order='location_id', context=context)
22 else:
23 # Get all locations
24- wh_location_ids = loc_obj.search(new_cr, uid, [('usage', '=', 'internal'), ('quarantine_location', '=', False), ('id', 'not in', not_loc_ids)], order='location_id', context=context)
25-
26- move_ids = move_obj.search(new_cr, uid, [('prodlot_id', '!=', False)], context=context)
27- for move in move_obj.browse(new_cr, uid, move_ids, context=context):
28- if move.location_id.id not in location_ids:
29- if move.location_id.usage == 'internal' and not move.location_id.quarantine_location and move.location_id.id in wh_location_ids:
30- location_ids.append(move.location_id.id)
31- if move.location_dest_id.id not in location_ids and not move.location_dest_id.quarantine_location and move.location_dest_id.id in wh_location_ids:
32- if move.location_dest_id.usage == 'internal':
33- location_ids.append(move.location_dest_id.id)
34+ location_ids = loc_obj.search(new_cr, uid, [('usage', '=', 'internal'), ('quarantine_location', '=', False), ('id', 'not in', not_loc_ids)], order='location_id', context=context)
35
36 context.update({'location_id': location_ids, 'location': location_ids})
37
38@@ -466,7 +455,6 @@
39 lot_domain.append(('product_id', 'in', only_product_ids))
40
41 lot_ids = lot_obj.search(new_cr, uid, lot_domain, order='product_id, life_date', context=context)
42-
43 from_date = DateFrom(report.date_from)
44 to_date = DateFrom(report.date_to) + RelativeDateTime(day=1, months=1, days=-1)
45
46@@ -510,27 +498,29 @@
47 if not last_expiry_date:
48 last_expiry_date = month - RelativeDateTime(days=1)
49
50- item_id = item_obj.create(new_cr, uid, {
51- 'name': start_month_flag and 'expired_qty_col' or month.strftime('%m/%y'),
52- 'line_id': products[lot.product_id.id]['line_id'],
53- 'uom_id': lot.product_id.uom_id.id,
54- }, context=context)
55 available_qty = 0.00
56 expired_qty = 0.00
57 seq += 1
58
59 # Create a line for each lot which expired in this month
60 domain = [('product_id', '=', lot.product_id.id),
61- ('stock_available', '>', 0.00),
62+ ('id', 'in', lot_ids),
63 ('life_date', '<', (month + RelativeDateTime(months=1, day=1)).strftime('%Y-%m-%d'))]
64
65 if not start_month_flag:
66 domain.append(('life_date', '>=', month.strftime('%Y-%m-%d')))
67- item_obj.write(new_cr, uid, [item_id], {'period_start': (month + RelativeDateTime(day=1)).strftime('%Y-%m-%d')}, context=context)
68+ item_period_start = (month + RelativeDateTime(day=1)).strftime('%Y-%m-%d')
69 else:
70- item_obj.write(new_cr, uid, [item_id], {'period_start': month.strftime('%Y-%m-%d')}, context=context)
71+ item_period_start = month.strftime('%Y-%m-%d')
72 domain.append(('life_date', '<=', month.strftime('%Y-%m-01')))
73
74+ item_id = item_obj.create(new_cr, uid, {
75+ 'name': start_month_flag and 'expired_qty_col' or month.strftime('%m/%y'),
76+ 'line_id': products[lot.product_id.id]['line_id'],
77+ 'uom_id': lot.product_id.uom_id.id,
78+ 'period_start': item_period_start,
79+ }, context=context)
80+
81 product_lot_ids = lot_obj.search(new_cr, uid, domain, order='life_date', context=context)
82
83 # Create an item line for each lot and each location
84@@ -576,12 +566,11 @@
85
86 lot_context = context.copy()
87 lot_context.update({'prodlot_id': product_lot.id})
88- product = product_obj.browse(new_cr, uid, lot.product_id.id, context=lot_context)
89 lot_expired_qty = l_expired_qty
90 for location in location_ids:
91 new_lot_context = lot_context.copy()
92 new_lot_context.update({'location': location, 'compute_child': False})
93- product2 = product_obj.browse(new_cr, uid, lot.product_id.id, context=new_lot_context)
94+ product2 = product_obj.browse(new_cr, uid, lot.product_id.id, fields_to_fetch=['qty_available'], context=new_lot_context)
95 if product2.qty_available > 0.00:
96 # Create the item line
97 if product2.qty_available <= lot_expired_qty:
98@@ -592,12 +581,12 @@
99 lot_expired_qty = 0.00
100 item_line_obj.create(new_cr, uid, {'item_id': item_id,
101 'lot_id': product_lot.id,
102- 'uom_id': product.uom_id.id,
103+ 'uom_id': lot.product_id.uom_id.id,
104 'location_id': location,
105 'available_qty': product2.qty_available,
106 'expired_qty': new_lot_expired}, context=context)
107
108- available_qty += product.qty_available
109+ available_qty += product_lot.stock_available
110
111 item_obj.write(new_cr, uid, [item_id], {'available_qty': available_qty,
112 'expired_qty': expired_qty}, context=context)

Subscribers

People subscribed via source and target branches