Merge lp:~unifield-team/unifield-wm/us-862 into lp:unifield-wm

Proposed by jftempo
Status: Merged
Merged at revision: 2753
Proposed branch: lp:~unifield-team/unifield-wm/us-862
Merge into: lp:unifield-wm
Diff against target: 548 lines (+197/-68)
1 file modified
msf_doc_import/initial_stock_inventory.py (+197/-68)
To merge this branch: bzr merge lp:~unifield-team/unifield-wm/us-862
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+284481@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 'msf_doc_import/initial_stock_inventory.py'
2--- msf_doc_import/initial_stock_inventory.py 2016-01-22 16:07:10 +0000
3+++ msf_doc_import/initial_stock_inventory.py 2016-01-29 16:05:36 +0000
4@@ -102,6 +102,7 @@
5 reader.next()
6 line_num = 1
7 product_error = []
8+ no_product_error = []
9 for row in reader:
10 line_num += 1
11 # Check length of the row
12@@ -114,6 +115,7 @@
13 product_cost = 1.00
14 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
15 location_id = False
16+ location_not_found = False
17 batch = False
18 batch_name = False
19 expiry = False
20@@ -129,6 +131,8 @@
21 if not product_code:
22 to_correct_ok = True
23 import_to_correct = True
24+ no_product_error.append(line_num)
25+ continue
26 else:
27 try:
28 product_code = product_code.strip()
29@@ -143,13 +147,13 @@
30 to_correct_ok = True
31 import_to_correct = True
32
33- # Product name
34- p_name = row.cells[1].data
35- if not product_id:
36- to_correct_ok = True
37- import_to_correct = True
38- product_error.append(line_num)
39- continue
40+ # Product name
41+ p_name = row.cells[1].data
42+ if not product_id:
43+ to_correct_ok = True
44+ import_to_correct = True
45+ product_error.append(line_num)
46+ continue
47
48 # Location
49 loc_id = row.cells[2].data
50@@ -165,6 +169,7 @@
51 location_id = False
52 to_correct_ok = True
53 import_to_correct = True
54+ location_not_found = True
55 else:
56 location_id = loc_ids[0]
57 except Exception:
58@@ -203,10 +208,13 @@
59 expiry = row.cells[4].data.strftime('%Y-%m-%d')
60 else:
61 bad_expiry = True
62- comment += _('Incorrectly formatted expiry date.')
63+ comment += _('Incorrectly formatted expiry date.\n')
64 to_correct_ok = True
65 import_to_correct = True
66 if expiry and not batch:
67+ batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context)
68+ if batch_ids:
69+ comment += _('Other batch with the same expiry date exist.\n')
70 if product.batch_management and batch_name:
71 batch = batch_obj.create(cr, uid, {
72 'product_id': product_id,
73@@ -217,25 +225,17 @@
74 batch = False
75 to_correct_ok = True
76 import_to_correct = True
77- else:
78- if batch_name:
79- batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry), ('name', '=', batch_name)], context=context)
80- else:
81- batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context)
82- if not batch_ids:
83- if batch_name:
84- expiry = False
85- batch = False
86- to_correct_ok = True
87- import_to_correct = True
88- else:
89- batch = batch_ids[0]
90 elif expiry and batch:
91 b_expiry = batch_obj.browse(cr, uid, batch, context=context).life_date
92 if expiry != b_expiry:
93- err_exp_message = _('Expiry date inconsistent with %s') % row.cells[3].data
94- comment += err_exp_message
95- comment += '\n'
96+ if product.batch_management:
97+ err_exp_message = _('Expiry date inconsistent with %s.\n') % row.cells[3].data
98+ comment += err_exp_message
99+ comment += '\n'
100+ expiry = False
101+ elif product.perishable:
102+ batch = False
103+
104 # Quantity
105 p_qty = row.cells[5].data
106 if not p_qty:
107@@ -246,8 +246,10 @@
108 else:
109 product_qty = 0.00
110
111- if not location_id:
112+ if not location_id and not location_not_found:
113 comment += _('Location is missing.\n')
114+ elif location_not_found:
115+ comment += _('Location not found.\n')
116 if product:
117 product_uom = product.uom_id.id
118 hidden_batch_management_mandatory = product.batch_management
119@@ -257,19 +259,34 @@
120 comment += _('Batch not found.\n')
121 else:
122 comment += _('Batch is missing.\n')
123- if hidden_perishable_mandatory and not expiry:
124+ if hidden_perishable_mandatory and not expiry and not bad_expiry:
125 comment += _('Expiry date is missing.\n')
126- if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and batch_name:
127+ if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch_name or batch or bad_batch_name):
128+ batch = False
129+ bad_batch_name = False
130+ expiry = False
131+ bad_expiry = False
132+ # Remove the res.log that indicates errors on import
133+ if to_correct_ok and location_id and not location_not_found:
134+ to_correct_ok = False
135+ comment = ''
136 comment += _('This product is not Batch Number managed.\n')
137+ if not hidden_perishable_mandatory and (expiry or bad_expiry):
138 batch = False
139- if not hidden_perishable_mandatory and expiry:
140+ bad_batch_name = False
141+ expiry = False
142+ bad_expiry = False
143+ # Remove the res.log that indicates errors on import
144+ if to_correct_ok and location_id and not location_not_found:
145+ to_correct_ok = False
146+ comment = ''
147 comment += _('This product is not Expiry Date managed.\n')
148- expiry = False
149 else:
150 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]
151 hidden_batch_management_mandatory = False
152 hidden_perishable_mandatory = False
153
154+
155 if product_uom and product_qty:
156 product_qty = self.pool.get('product.uom')._compute_round_up_qty(cr, uid, product_uom, product_qty)
157
158@@ -281,6 +298,7 @@
159 'reason_type_id': discrepancy_id,
160 'currency_id': currency_id,
161 'location_id': location_id,
162+ 'location_not_found': location_not_found,
163 'prod_lot_id': batch,
164 'expiry_date': expiry,
165 'bad_expiry': bad_expiry,
166@@ -303,6 +321,14 @@
167 len(product_error) > 1 and 's' or '',
168 ' / '.join(str(x) for x in product_error)),
169 )
170+ if no_product_error:
171+ raise osv.except_osv(
172+ _('Error'),
173+ _('Product not defined on %s line%s: %s') % (
174+ len(no_product_error) > 1 and 'these' or 'this',
175+ len(no_product_error) > 1 and 's' or '',
176+ ' / '.join(str(x) for x in no_product_error)),
177+ )
178
179 # write order line on Inventory
180 context['import_in_progress'] = True
181@@ -312,7 +338,7 @@
182
183 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]
184
185- if import_to_correct:
186+ if any(x[2]['to_correct'] for x in vals['inventory_line_id']):
187 msg_to_return = _("The import of lines had errors, please correct the red lines below")
188
189 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})
190@@ -377,6 +403,7 @@
191 if context is None:
192 context = {}
193 comment = ''
194+ just_warn = False
195 pl_obj = self.pool.get('stock.production.lot')
196 hidden_batch_management_mandatory = False
197 hidden_perishable_mandatory = False
198@@ -389,6 +416,11 @@
199 vals['hidden_perishable_mandatory'] = hidden_perishable_mandatory
200
201 location_id = vals.get('location_id')
202+ location_not_found = vals.get('location_not_found')
203+
204+ if 'location_not_found' in vals:
205+ del vals['location_not_found']
206+
207 batch = vals.get('prod_lot_id')
208 expiry = vals.get('expiry_date')
209 batch_name = vals.get('batch_name')
210@@ -401,18 +433,22 @@
211 if 'bad_batch_name' in vals:
212 del vals['bad_batch_name']
213
214- if not location_id:
215+ if not location_id and not location_not_found:
216 comment += _('Location is missing.\n')
217+ elif location_not_found:
218+ comment += _('Location not found.\n')
219
220 if hidden_batch_management_mandatory and not batch:
221 if bad_batch_name:
222 comment += _('Incorrect batch number format.\n')
223+ vals['expiry_date'] = False
224 elif batch_name and not bad_expiry and expiry:
225 comment += _('Batch not found.\n')
226 elif batch_name and not bad_expiry and not expiry:
227 comment += _('Expiry date is missing.\n')
228 elif batch_name and bad_expiry:
229 comment += _('Incorrectly formatted expiry date. Batch not created.\n')
230+ vals['expiry_date'] = False
231 else:
232 comment += _('Batch is missing.\n')
233 vals['expiry_date'] = False
234@@ -425,27 +461,34 @@
235 else:
236 comment += _('Batch not found.\n')
237 elif hidden_perishable_mandatory and not expiry:
238- comment += _('Expiry date is missing.\n')
239+ if not bad_expiry:
240+ comment += _('Expiry date is missing.\n')
241+ else:
242+ comment += _('Incorrectly formatted expiry date.\n')
243 vals['expiry_date'] = False
244
245- if batch and expiry and pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date'] != expiry:
246- comment += _('Expiry date and batch not consistent')
247- vals.update({
248- 'prod_lot_id': False,
249- 'expiry_date': False,
250- })
251+ #if hidden_perishable_mandatory and ((batch and expiry and pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date'] != expiry) \
252+ # or (not batch and expiry and not bad_expiry)):
253+ # comment += _('Expiry date will be created (with its internal batch).\n')
254+ # just_warn = True
255+ # vals.update({
256+ # 'prod_lot_id': False,
257+ # 'to_correct_ok': False,
258+ # })
259
260 if hidden_batch_management_mandatory and batch and not expiry:
261 expiry = pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date']
262- vals['expiry_date'] = expiry
263- comment += _('Please check Expiry Date is correct!')
264+ comment += _('Please check Expiry Date is correct!.\n')
265
266 if not comment:
267 if vals.get('comment'):
268 comment = vals.get('comment')
269 vals.update({'comment': comment, 'to_correct_ok': False})
270 elif context.get('import_in_progress'):
271- vals.update({'comment': comment, 'to_correct_ok': True})
272+ if just_warn:
273+ vals.update({'comment': comment, 'to_correct_ok': False})
274+ else:
275+ vals.update({'comment': comment, 'to_correct_ok': True})
276
277 res = super(stock_inventory_line, self).create(cr, uid, vals, context=context)
278 return res
279@@ -556,6 +599,7 @@
280
281 product_cache = {}
282 product_error = []
283+ no_product_error = []
284
285 fileobj = SpreadsheetXML(xmlstring=base64.decodestring(obj.file_to_import))
286
287@@ -577,6 +621,7 @@
288 product_cost = 1.00
289 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
290 location_id = False
291+ location_not_found = False
292 batch = False
293 expiry = False
294 bad_expiry = None
295@@ -592,6 +637,8 @@
296 if not product_code:
297 to_correct_ok = True
298 import_to_correct = True
299+ no_product_error.append(line_num)
300+ continue
301 else:
302 try:
303 product_code = product_code.strip()
304@@ -606,13 +653,13 @@
305 to_correct_ok = True
306 import_to_correct = True
307
308- # Product name
309- p_name = row.cells[1].data
310- if not product_id:
311- to_correct_ok = True
312- import_to_correct = True
313- product_error.append(line_num)
314- continue
315+ # Product name
316+ p_name = row.cells[1].data
317+ if not product_id:
318+ to_correct_ok = True
319+ import_to_correct = True
320+ product_error.append(line_num)
321+ continue
322
323 # Average cost
324 cost = row.cells[2].data
325@@ -644,6 +691,7 @@
326 location_id = False
327 to_correct_ok = True
328 import_to_correct = True
329+ location_not_found = True
330 else:
331 location_id = loc_ids[0]
332 except Exception:
333@@ -668,12 +716,9 @@
334 expiry = row.cells[5].data
335 else:
336 bad_expiry = True
337- comment += _('Incorrectly formatted expiry date.')
338+ comment += _('Incorrectly formatted expiry date.\n')
339 to_correct_ok = True
340 import_to_correct = True
341- else:
342- to_correct_ok = True
343- import_to_correct = True
344
345 # Quantity
346 p_qty = row.cells[6].data
347@@ -685,20 +730,47 @@
348 else:
349 product_qty = 0.00
350
351- if not location_id:
352+ if not location_id and not location_not_found:
353 comment += _('Location is missing.\n')
354+ elif location_not_found:
355+ comment += _('Location not found.\n')
356 if product_id:
357 product = product_obj.browse(cr, uid, product_id)
358 product_uom = product.uom_id.id
359 hidden_batch_management_mandatory = product.batch_management
360 hidden_perishable_mandatory = product.perishable
361+
362+ if hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name):
363+ batch_name = False
364+ bad_batch_name = False
365+
366 if hidden_batch_management_mandatory and not batch:
367 if batch_name:
368 comment += _('Batch not found.\n')
369 else:
370 comment += _('Batch is missing.\n')
371- if hidden_perishable_mandatory and not expiry:
372+ if hidden_perishable_mandatory and not expiry and not bad_expiry:
373 comment += _('Expiry date is missing.\n')
374+ if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name):
375+ batch = False
376+ bad_batch_name = False
377+ expiry = False
378+ bad_expiry = False
379+ # Remove the res.log that indicates errors on import
380+ if to_correct_ok and location_id and not location_not_found:
381+ to_correct_ok = False
382+ comment = ''
383+ comment += _('This product is not Batch Number managed.\n')
384+ if not hidden_perishable_mandatory and (expiry or bad_expiry):
385+ batch = False
386+ bad_batch_name = False
387+ expiry = False
388+ bad_expiry = False
389+ # Remove the res.log that indicates errors on import
390+ if to_correct_ok and location_id and not location_not_found:
391+ to_correct_ok = False
392+ comment = ''
393+ comment += _('This product is not Expiry Date managed.\n')
394 else:
395 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]
396 hidden_batch_management_mandatory = False
397@@ -712,6 +784,7 @@
398 'average_cost': product_cost,
399 'currency_id': currency_id,
400 'location_id': location_id,
401+ 'location_not_found': location_not_found,
402 'prodlot_name': batch,
403 'expiry_date': expiry and expiry.strftime('%Y-%m-%d') or False,
404 'bad_expiry': bad_expiry,
405@@ -734,14 +807,24 @@
406 len(product_error) > 1 and 's' or '',
407 ' / '.join(str(x) for x in product_error)),
408 )
409+ if no_product_error:
410+ raise osv.except_osv(
411+ _('Error'),
412+ _('Product not defined on %s line%s: %s') % (
413+ len(no_product_error) > 1 and 'these' or 'this',
414+ len(no_product_error) > 1 and 's' or '',
415+ ' / '.join(str(x) for x in no_product_error)),
416+ )
417
418 # write order line on Inventory
419 vals.update({'file_to_import': False})
420+ context['import_in_progress'] = True
421 self.write(cr, uid, ids, vals, context=context)
422+ context['import_in_progress'] = False
423
424 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]
425
426- if import_to_correct:
427+ if any(x[2]['to_correct'] for x in vals['inventory_line_id']):
428 msg_to_return = _("The import of lines had errors, please correct the red lines below")
429
430 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})
431@@ -804,7 +887,9 @@
432 }
433
434 def create(self, cr, uid, vals, context=None):
435+ pl_obj = self.pool.get('stock.production.lot')
436 comment = ''
437+ just_warn = False
438 hidden_batch_management_mandatory = False
439 hidden_perishable_mandatory = False
440
441@@ -814,6 +899,10 @@
442 hidden_perishable_mandatory = product.perishable
443
444 location_id = vals.get('location_id')
445+ location_not_found = vals.get('location_not_found')
446+
447+ if 'location_not_found' in vals:
448+ del vals['location_not_found']
449
450 batch = vals.get('prodlot_name')
451 batch_numer = vals.get('prod_lot_id', False)
452@@ -821,7 +910,7 @@
453 batch = self.pool.get('stock.production.lot').browse(cr, uid, batch_numer, context=context).name
454 vals.update({'prodlot_name':batch})
455 expiry = vals.get('expiry_date')
456- batch_name = vals.get('batch_name')
457+ batch_name = vals.get('prodlot_name')
458 bad_expiry = vals.get('bad_expiry')
459 bad_batch_name = vals.get('bad_batch_name')
460
461@@ -831,8 +920,10 @@
462 if 'bad_batch_name' in vals:
463 del vals['bad_batch_name']
464
465- if not location_id:
466+ if not location_id and not location_not_found:
467 comment += _('Location is missing.\n')
468+ elif location_not_found:
469+ comment += _('Location not found.\n')
470
471 if hidden_batch_management_mandatory and not batch:
472 if bad_batch_name:
473@@ -843,16 +934,57 @@
474 comment += _('Incorrectly formatted expiry date. Batch not created.\n')
475 else:
476 comment += _('Batch is missing.\n')
477- if hidden_perishable_mandatory and not expiry:
478- if bad_expiry:
479- comment += _('Incorrectly formatted expiry date.\n')
480- else:
481- comment += _('Expiry date is missing.\n')
482+
483+ if not product.batch_management and hidden_perishable_mandatory:
484+ if expiry and batch:
485+ batch_ids = pl_obj.search(cr, uid, [
486+ ('product_id', '=', product.id),
487+ ('life_date', '=', expiry),
488+ ('name', '=', batch),
489+ ], context=context)
490+ if batch_ids:
491+ batch = pl_obj.browse(cr, uid, batch_ids[0], context=context).name
492+ vals['prodlot_name'] = batch
493+ else:
494+ batch = False
495+ vals['prodlot_name'] = False
496+# if expiry and not batch:
497+# comment += _('Expiry date will be created (with its internal batch).\n')
498+# just_warn = True
499+# vals.update({
500+# 'to_correct_ok': False,
501+# 'prodlot_name': False,
502+# })
503+# if expiry and batch:
504+# comment += _('Expiry date selected (with its internal batch).\n')
505+# just_warn = True
506+ if not expiry:
507+ if bad_expiry:
508+ comment += _('Incorrectly formatted expiry date.\n')
509+ vals['prodlot_name'] = False
510+ else:
511+ comment += _('Expiry date is missing.\n')
512+
513+ if hidden_batch_management_mandatory and batch and expiry:
514+ pl_ids = pl_obj.search(cr, uid, [('name', '=', batch), ('product_id', '=', vals.get('product_id'))], context=context)
515+ if pl_ids and pl_obj.read(cr, uid, pl_ids[0], ['life_date'], context=context)['life_date'] != expiry:
516+ comment += _('Expiry date and batch not consistent.\n')
517+ vals.update({
518+ 'prod_lot_id': False,
519+ 'prodlot_name': '',
520+ 'expiry_date': False,
521+ })
522
523 if not comment:
524+ if vals.get('comment'):
525+ comment = vals.get('comment')
526 vals.update({'comment': comment, 'to_correct_ok': False})
527- else:
528- vals.update({'comment': comment, 'to_correct_ok': True})
529+ elif context.get('import_in_progress'):
530+ if just_warn:
531+ vals.update({'comment': comment, 'to_correct_ok': False})
532+ else:
533+ vals.update({'comment': comment, 'to_correct_ok': False})
534+
535
536 res = super(initial_stock_inventory_line, self).create(cr, uid, vals, context=context)
537 return res
538@@ -877,10 +1009,7 @@
539 if not location_id:
540 comment += _('Location is missing.\n')
541 if hidden_batch_management_mandatory and not batch:
542- if batch_name:
543- comment += _('Batch not found.\n')
544- else:
545- comment += _('Batch is missing.\n')
546+ comment += _('Batch is missing.\n')
547 if hidden_perishable_mandatory and not expiry:
548 comment += _('Expiry date is missing.\n')
549

Subscribers

People subscribed via source and target branches