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
=== modified file 'msf_doc_import/initial_stock_inventory.py'
--- msf_doc_import/initial_stock_inventory.py 2016-01-22 16:07:10 +0000
+++ msf_doc_import/initial_stock_inventory.py 2016-01-29 16:05:36 +0000
@@ -102,6 +102,7 @@
102 reader.next()102 reader.next()
103 line_num = 1103 line_num = 1
104 product_error = []104 product_error = []
105 no_product_error = []
105 for row in reader:106 for row in reader:
106 line_num += 1107 line_num += 1
107 # Check length of the row108 # Check length of the row
@@ -114,6 +115,7 @@
114 product_cost = 1.00115 product_cost = 1.00
115 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id116 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
116 location_id = False117 location_id = False
118 location_not_found = False
117 batch = False119 batch = False
118 batch_name = False120 batch_name = False
119 expiry = False121 expiry = False
@@ -129,6 +131,8 @@
129 if not product_code:131 if not product_code:
130 to_correct_ok = True132 to_correct_ok = True
131 import_to_correct = True133 import_to_correct = True
134 no_product_error.append(line_num)
135 continue
132 else:136 else:
133 try:137 try:
134 product_code = product_code.strip()138 product_code = product_code.strip()
@@ -143,13 +147,13 @@
143 to_correct_ok = True147 to_correct_ok = True
144 import_to_correct = True148 import_to_correct = True
145149
146 # Product name150 # Product name
147 p_name = row.cells[1].data151 p_name = row.cells[1].data
148 if not product_id:152 if not product_id:
149 to_correct_ok = True153 to_correct_ok = True
150 import_to_correct = True154 import_to_correct = True
151 product_error.append(line_num)155 product_error.append(line_num)
152 continue156 continue
153157
154 # Location158 # Location
155 loc_id = row.cells[2].data159 loc_id = row.cells[2].data
@@ -165,6 +169,7 @@
165 location_id = False169 location_id = False
166 to_correct_ok = True170 to_correct_ok = True
167 import_to_correct = True171 import_to_correct = True
172 location_not_found = True
168 else:173 else:
169 location_id = loc_ids[0]174 location_id = loc_ids[0]
170 except Exception:175 except Exception:
@@ -203,10 +208,13 @@
203 expiry = row.cells[4].data.strftime('%Y-%m-%d')208 expiry = row.cells[4].data.strftime('%Y-%m-%d')
204 else:209 else:
205 bad_expiry = True210 bad_expiry = True
206 comment += _('Incorrectly formatted expiry date.')211 comment += _('Incorrectly formatted expiry date.\n')
207 to_correct_ok = True212 to_correct_ok = True
208 import_to_correct = True213 import_to_correct = True
209 if expiry and not batch:214 if expiry and not batch:
215 batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context)
216 if batch_ids:
217 comment += _('Other batch with the same expiry date exist.\n')
210 if product.batch_management and batch_name:218 if product.batch_management and batch_name:
211 batch = batch_obj.create(cr, uid, {219 batch = batch_obj.create(cr, uid, {
212 'product_id': product_id,220 'product_id': product_id,
@@ -217,25 +225,17 @@
217 batch = False225 batch = False
218 to_correct_ok = True226 to_correct_ok = True
219 import_to_correct = True227 import_to_correct = True
220 else:
221 if batch_name:
222 batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry), ('name', '=', batch_name)], context=context)
223 else:
224 batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context)
225 if not batch_ids:
226 if batch_name:
227 expiry = False
228 batch = False
229 to_correct_ok = True
230 import_to_correct = True
231 else:
232 batch = batch_ids[0]
233 elif expiry and batch:228 elif expiry and batch:
234 b_expiry = batch_obj.browse(cr, uid, batch, context=context).life_date229 b_expiry = batch_obj.browse(cr, uid, batch, context=context).life_date
235 if expiry != b_expiry:230 if expiry != b_expiry:
236 err_exp_message = _('Expiry date inconsistent with %s') % row.cells[3].data231 if product.batch_management:
237 comment += err_exp_message232 err_exp_message = _('Expiry date inconsistent with %s.\n') % row.cells[3].data
238 comment += '\n'233 comment += err_exp_message
234 comment += '\n'
235 expiry = False
236 elif product.perishable:
237 batch = False
238
239 # Quantity239 # Quantity
240 p_qty = row.cells[5].data240 p_qty = row.cells[5].data
241 if not p_qty:241 if not p_qty:
@@ -246,8 +246,10 @@
246 else:246 else:
247 product_qty = 0.00247 product_qty = 0.00
248248
249 if not location_id:249 if not location_id and not location_not_found:
250 comment += _('Location is missing.\n')250 comment += _('Location is missing.\n')
251 elif location_not_found:
252 comment += _('Location not found.\n')
251 if product:253 if product:
252 product_uom = product.uom_id.id254 product_uom = product.uom_id.id
253 hidden_batch_management_mandatory = product.batch_management255 hidden_batch_management_mandatory = product.batch_management
@@ -257,19 +259,34 @@
257 comment += _('Batch not found.\n')259 comment += _('Batch not found.\n')
258 else:260 else:
259 comment += _('Batch is missing.\n')261 comment += _('Batch is missing.\n')
260 if hidden_perishable_mandatory and not expiry:262 if hidden_perishable_mandatory and not expiry and not bad_expiry:
261 comment += _('Expiry date is missing.\n')263 comment += _('Expiry date is missing.\n')
262 if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and batch_name:264 if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch_name or batch or bad_batch_name):
265 batch = False
266 bad_batch_name = False
267 expiry = False
268 bad_expiry = False
269 # Remove the res.log that indicates errors on import
270 if to_correct_ok and location_id and not location_not_found:
271 to_correct_ok = False
272 comment = ''
263 comment += _('This product is not Batch Number managed.\n')273 comment += _('This product is not Batch Number managed.\n')
274 if not hidden_perishable_mandatory and (expiry or bad_expiry):
264 batch = False275 batch = False
265 if not hidden_perishable_mandatory and expiry:276 bad_batch_name = False
277 expiry = False
278 bad_expiry = False
279 # Remove the res.log that indicates errors on import
280 if to_correct_ok and location_id and not location_not_found:
281 to_correct_ok = False
282 comment = ''
266 comment += _('This product is not Expiry Date managed.\n')283 comment += _('This product is not Expiry Date managed.\n')
267 expiry = False
268 else:284 else:
269 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]285 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]
270 hidden_batch_management_mandatory = False286 hidden_batch_management_mandatory = False
271 hidden_perishable_mandatory = False287 hidden_perishable_mandatory = False
272288
289
273 if product_uom and product_qty:290 if product_uom and product_qty:
274 product_qty = self.pool.get('product.uom')._compute_round_up_qty(cr, uid, product_uom, product_qty)291 product_qty = self.pool.get('product.uom')._compute_round_up_qty(cr, uid, product_uom, product_qty)
275292
@@ -281,6 +298,7 @@
281 'reason_type_id': discrepancy_id,298 'reason_type_id': discrepancy_id,
282 'currency_id': currency_id,299 'currency_id': currency_id,
283 'location_id': location_id,300 'location_id': location_id,
301 'location_not_found': location_not_found,
284 'prod_lot_id': batch,302 'prod_lot_id': batch,
285 'expiry_date': expiry,303 'expiry_date': expiry,
286 'bad_expiry': bad_expiry,304 'bad_expiry': bad_expiry,
@@ -303,6 +321,14 @@
303 len(product_error) > 1 and 's' or '',321 len(product_error) > 1 and 's' or '',
304 ' / '.join(str(x) for x in product_error)),322 ' / '.join(str(x) for x in product_error)),
305 )323 )
324 if no_product_error:
325 raise osv.except_osv(
326 _('Error'),
327 _('Product not defined on %s line%s: %s') % (
328 len(no_product_error) > 1 and 'these' or 'this',
329 len(no_product_error) > 1 and 's' or '',
330 ' / '.join(str(x) for x in no_product_error)),
331 )
306332
307 # write order line on Inventory333 # write order line on Inventory
308 context['import_in_progress'] = True334 context['import_in_progress'] = True
@@ -312,7 +338,7 @@
312338
313 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]339 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]
314340
315 if import_to_correct:341 if any(x[2]['to_correct'] for x in vals['inventory_line_id']):
316 msg_to_return = _("The import of lines had errors, please correct the red lines below")342 msg_to_return = _("The import of lines had errors, please correct the red lines below")
317343
318 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})344 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})
@@ -377,6 +403,7 @@
377 if context is None:403 if context is None:
378 context = {}404 context = {}
379 comment = ''405 comment = ''
406 just_warn = False
380 pl_obj = self.pool.get('stock.production.lot')407 pl_obj = self.pool.get('stock.production.lot')
381 hidden_batch_management_mandatory = False408 hidden_batch_management_mandatory = False
382 hidden_perishable_mandatory = False409 hidden_perishable_mandatory = False
@@ -389,6 +416,11 @@
389 vals['hidden_perishable_mandatory'] = hidden_perishable_mandatory416 vals['hidden_perishable_mandatory'] = hidden_perishable_mandatory
390417
391 location_id = vals.get('location_id')418 location_id = vals.get('location_id')
419 location_not_found = vals.get('location_not_found')
420
421 if 'location_not_found' in vals:
422 del vals['location_not_found']
423
392 batch = vals.get('prod_lot_id')424 batch = vals.get('prod_lot_id')
393 expiry = vals.get('expiry_date')425 expiry = vals.get('expiry_date')
394 batch_name = vals.get('batch_name')426 batch_name = vals.get('batch_name')
@@ -401,18 +433,22 @@
401 if 'bad_batch_name' in vals:433 if 'bad_batch_name' in vals:
402 del vals['bad_batch_name']434 del vals['bad_batch_name']
403435
404 if not location_id:436 if not location_id and not location_not_found:
405 comment += _('Location is missing.\n')437 comment += _('Location is missing.\n')
438 elif location_not_found:
439 comment += _('Location not found.\n')
406440
407 if hidden_batch_management_mandatory and not batch:441 if hidden_batch_management_mandatory and not batch:
408 if bad_batch_name:442 if bad_batch_name:
409 comment += _('Incorrect batch number format.\n')443 comment += _('Incorrect batch number format.\n')
444 vals['expiry_date'] = False
410 elif batch_name and not bad_expiry and expiry:445 elif batch_name and not bad_expiry and expiry:
411 comment += _('Batch not found.\n')446 comment += _('Batch not found.\n')
412 elif batch_name and not bad_expiry and not expiry:447 elif batch_name and not bad_expiry and not expiry:
413 comment += _('Expiry date is missing.\n')448 comment += _('Expiry date is missing.\n')
414 elif batch_name and bad_expiry:449 elif batch_name and bad_expiry:
415 comment += _('Incorrectly formatted expiry date. Batch not created.\n')450 comment += _('Incorrectly formatted expiry date. Batch not created.\n')
451 vals['expiry_date'] = False
416 else:452 else:
417 comment += _('Batch is missing.\n')453 comment += _('Batch is missing.\n')
418 vals['expiry_date'] = False454 vals['expiry_date'] = False
@@ -425,27 +461,34 @@
425 else:461 else:
426 comment += _('Batch not found.\n')462 comment += _('Batch not found.\n')
427 elif hidden_perishable_mandatory and not expiry:463 elif hidden_perishable_mandatory and not expiry:
428 comment += _('Expiry date is missing.\n')464 if not bad_expiry:
465 comment += _('Expiry date is missing.\n')
466 else:
467 comment += _('Incorrectly formatted expiry date.\n')
429 vals['expiry_date'] = False468 vals['expiry_date'] = False
430469
431 if batch and expiry and pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date'] != expiry:470 #if hidden_perishable_mandatory and ((batch and expiry and pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date'] != expiry) \
432 comment += _('Expiry date and batch not consistent')471 # or (not batch and expiry and not bad_expiry)):
433 vals.update({472 # comment += _('Expiry date will be created (with its internal batch).\n')
434 'prod_lot_id': False,473 # just_warn = True
435 'expiry_date': False,474 # vals.update({
436 })475 # 'prod_lot_id': False,
476 # 'to_correct_ok': False,
477 # })
437478
438 if hidden_batch_management_mandatory and batch and not expiry:479 if hidden_batch_management_mandatory and batch and not expiry:
439 expiry = pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date']480 expiry = pl_obj.read(cr, uid, batch, ['life_date'], context=context)['life_date']
440 vals['expiry_date'] = expiry481 comment += _('Please check Expiry Date is correct!.\n')
441 comment += _('Please check Expiry Date is correct!')
442482
443 if not comment:483 if not comment:
444 if vals.get('comment'):484 if vals.get('comment'):
445 comment = vals.get('comment')485 comment = vals.get('comment')
446 vals.update({'comment': comment, 'to_correct_ok': False})486 vals.update({'comment': comment, 'to_correct_ok': False})
447 elif context.get('import_in_progress'):487 elif context.get('import_in_progress'):
448 vals.update({'comment': comment, 'to_correct_ok': True})488 if just_warn:
489 vals.update({'comment': comment, 'to_correct_ok': False})
490 else:
491 vals.update({'comment': comment, 'to_correct_ok': True})
449492
450 res = super(stock_inventory_line, self).create(cr, uid, vals, context=context)493 res = super(stock_inventory_line, self).create(cr, uid, vals, context=context)
451 return res494 return res
@@ -556,6 +599,7 @@
556599
557 product_cache = {}600 product_cache = {}
558 product_error = []601 product_error = []
602 no_product_error = []
559603
560 fileobj = SpreadsheetXML(xmlstring=base64.decodestring(obj.file_to_import))604 fileobj = SpreadsheetXML(xmlstring=base64.decodestring(obj.file_to_import))
561605
@@ -577,6 +621,7 @@
577 product_cost = 1.00621 product_cost = 1.00
578 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id622 currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
579 location_id = False623 location_id = False
624 location_not_found = False
580 batch = False625 batch = False
581 expiry = False626 expiry = False
582 bad_expiry = None627 bad_expiry = None
@@ -592,6 +637,8 @@
592 if not product_code:637 if not product_code:
593 to_correct_ok = True638 to_correct_ok = True
594 import_to_correct = True639 import_to_correct = True
640 no_product_error.append(line_num)
641 continue
595 else:642 else:
596 try:643 try:
597 product_code = product_code.strip()644 product_code = product_code.strip()
@@ -606,13 +653,13 @@
606 to_correct_ok = True653 to_correct_ok = True
607 import_to_correct = True654 import_to_correct = True
608655
609 # Product name656 # Product name
610 p_name = row.cells[1].data657 p_name = row.cells[1].data
611 if not product_id:658 if not product_id:
612 to_correct_ok = True659 to_correct_ok = True
613 import_to_correct = True660 import_to_correct = True
614 product_error.append(line_num)661 product_error.append(line_num)
615 continue662 continue
616663
617 # Average cost664 # Average cost
618 cost = row.cells[2].data665 cost = row.cells[2].data
@@ -644,6 +691,7 @@
644 location_id = False691 location_id = False
645 to_correct_ok = True692 to_correct_ok = True
646 import_to_correct = True693 import_to_correct = True
694 location_not_found = True
647 else:695 else:
648 location_id = loc_ids[0]696 location_id = loc_ids[0]
649 except Exception:697 except Exception:
@@ -668,12 +716,9 @@
668 expiry = row.cells[5].data716 expiry = row.cells[5].data
669 else:717 else:
670 bad_expiry = True718 bad_expiry = True
671 comment += _('Incorrectly formatted expiry date.')719 comment += _('Incorrectly formatted expiry date.\n')
672 to_correct_ok = True720 to_correct_ok = True
673 import_to_correct = True721 import_to_correct = True
674 else:
675 to_correct_ok = True
676 import_to_correct = True
677722
678 # Quantity723 # Quantity
679 p_qty = row.cells[6].data724 p_qty = row.cells[6].data
@@ -685,20 +730,47 @@
685 else:730 else:
686 product_qty = 0.00731 product_qty = 0.00
687732
688 if not location_id:733 if not location_id and not location_not_found:
689 comment += _('Location is missing.\n')734 comment += _('Location is missing.\n')
735 elif location_not_found:
736 comment += _('Location not found.\n')
690 if product_id:737 if product_id:
691 product = product_obj.browse(cr, uid, product_id)738 product = product_obj.browse(cr, uid, product_id)
692 product_uom = product.uom_id.id739 product_uom = product.uom_id.id
693 hidden_batch_management_mandatory = product.batch_management740 hidden_batch_management_mandatory = product.batch_management
694 hidden_perishable_mandatory = product.perishable741 hidden_perishable_mandatory = product.perishable
742
743 if hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name):
744 batch_name = False
745 bad_batch_name = False
746
695 if hidden_batch_management_mandatory and not batch:747 if hidden_batch_management_mandatory and not batch:
696 if batch_name:748 if batch_name:
697 comment += _('Batch not found.\n')749 comment += _('Batch not found.\n')
698 else:750 else:
699 comment += _('Batch is missing.\n')751 comment += _('Batch is missing.\n')
700 if hidden_perishable_mandatory and not expiry:752 if hidden_perishable_mandatory and not expiry and not bad_expiry:
701 comment += _('Expiry date is missing.\n')753 comment += _('Expiry date is missing.\n')
754 if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name):
755 batch = False
756 bad_batch_name = False
757 expiry = False
758 bad_expiry = False
759 # Remove the res.log that indicates errors on import
760 if to_correct_ok and location_id and not location_not_found:
761 to_correct_ok = False
762 comment = ''
763 comment += _('This product is not Batch Number managed.\n')
764 if not hidden_perishable_mandatory and (expiry or bad_expiry):
765 batch = False
766 bad_batch_name = False
767 expiry = False
768 bad_expiry = False
769 # Remove the res.log that indicates errors on import
770 if to_correct_ok and location_id and not location_not_found:
771 to_correct_ok = False
772 comment = ''
773 comment += _('This product is not Expiry Date managed.\n')
702 else:774 else:
703 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]775 product_uom = self.pool.get('product.uom').search(cr, uid, [], context=context)[0]
704 hidden_batch_management_mandatory = False776 hidden_batch_management_mandatory = False
@@ -712,6 +784,7 @@
712 'average_cost': product_cost,784 'average_cost': product_cost,
713 'currency_id': currency_id,785 'currency_id': currency_id,
714 'location_id': location_id,786 'location_id': location_id,
787 'location_not_found': location_not_found,
715 'prodlot_name': batch,788 'prodlot_name': batch,
716 'expiry_date': expiry and expiry.strftime('%Y-%m-%d') or False,789 'expiry_date': expiry and expiry.strftime('%Y-%m-%d') or False,
717 'bad_expiry': bad_expiry,790 'bad_expiry': bad_expiry,
@@ -734,14 +807,24 @@
734 len(product_error) > 1 and 's' or '',807 len(product_error) > 1 and 's' or '',
735 ' / '.join(str(x) for x in product_error)),808 ' / '.join(str(x) for x in product_error)),
736 )809 )
810 if no_product_error:
811 raise osv.except_osv(
812 _('Error'),
813 _('Product not defined on %s line%s: %s') % (
814 len(no_product_error) > 1 and 'these' or 'this',
815 len(no_product_error) > 1 and 's' or '',
816 ' / '.join(str(x) for x in no_product_error)),
817 )
737818
738 # write order line on Inventory819 # write order line on Inventory
739 vals.update({'file_to_import': False})820 vals.update({'file_to_import': False})
821 context['import_in_progress'] = True
740 self.write(cr, uid, ids, vals, context=context)822 self.write(cr, uid, ids, vals, context=context)
823 context['import_in_progress'] = False
741824
742 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]825 view_id = obj_data.get_object_reference(cr, uid, 'specific_rules','stock_initial_inventory_form_view')[1]
743826
744 if import_to_correct:827 if any(x[2]['to_correct'] for x in vals['inventory_line_id']):
745 msg_to_return = _("The import of lines had errors, please correct the red lines below")828 msg_to_return = _("The import of lines had errors, please correct the red lines below")
746829
747 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})830 return self.log(cr, uid, obj.id, msg_to_return, context={'view_id': view_id,})
@@ -804,7 +887,9 @@
804 }887 }
805888
806 def create(self, cr, uid, vals, context=None):889 def create(self, cr, uid, vals, context=None):
890 pl_obj = self.pool.get('stock.production.lot')
807 comment = ''891 comment = ''
892 just_warn = False
808 hidden_batch_management_mandatory = False893 hidden_batch_management_mandatory = False
809 hidden_perishable_mandatory = False894 hidden_perishable_mandatory = False
810895
@@ -814,6 +899,10 @@
814 hidden_perishable_mandatory = product.perishable899 hidden_perishable_mandatory = product.perishable
815900
816 location_id = vals.get('location_id')901 location_id = vals.get('location_id')
902 location_not_found = vals.get('location_not_found')
903
904 if 'location_not_found' in vals:
905 del vals['location_not_found']
817906
818 batch = vals.get('prodlot_name')907 batch = vals.get('prodlot_name')
819 batch_numer = vals.get('prod_lot_id', False)908 batch_numer = vals.get('prod_lot_id', False)
@@ -821,7 +910,7 @@
821 batch = self.pool.get('stock.production.lot').browse(cr, uid, batch_numer, context=context).name910 batch = self.pool.get('stock.production.lot').browse(cr, uid, batch_numer, context=context).name
822 vals.update({'prodlot_name':batch})911 vals.update({'prodlot_name':batch})
823 expiry = vals.get('expiry_date')912 expiry = vals.get('expiry_date')
824 batch_name = vals.get('batch_name')913 batch_name = vals.get('prodlot_name')
825 bad_expiry = vals.get('bad_expiry')914 bad_expiry = vals.get('bad_expiry')
826 bad_batch_name = vals.get('bad_batch_name')915 bad_batch_name = vals.get('bad_batch_name')
827916
@@ -831,8 +920,10 @@
831 if 'bad_batch_name' in vals:920 if 'bad_batch_name' in vals:
832 del vals['bad_batch_name']921 del vals['bad_batch_name']
833922
834 if not location_id:923 if not location_id and not location_not_found:
835 comment += _('Location is missing.\n')924 comment += _('Location is missing.\n')
925 elif location_not_found:
926 comment += _('Location not found.\n')
836927
837 if hidden_batch_management_mandatory and not batch:928 if hidden_batch_management_mandatory and not batch:
838 if bad_batch_name:929 if bad_batch_name:
@@ -843,16 +934,57 @@
843 comment += _('Incorrectly formatted expiry date. Batch not created.\n')934 comment += _('Incorrectly formatted expiry date. Batch not created.\n')
844 else:935 else:
845 comment += _('Batch is missing.\n')936 comment += _('Batch is missing.\n')
846 if hidden_perishable_mandatory and not expiry:937
847 if bad_expiry:938 if not product.batch_management and hidden_perishable_mandatory:
848 comment += _('Incorrectly formatted expiry date.\n')939 if expiry and batch:
849 else:940 batch_ids = pl_obj.search(cr, uid, [
850 comment += _('Expiry date is missing.\n')941 ('product_id', '=', product.id),
942 ('life_date', '=', expiry),
943 ('name', '=', batch),
944 ], context=context)
945 if batch_ids:
946 batch = pl_obj.browse(cr, uid, batch_ids[0], context=context).name
947 vals['prodlot_name'] = batch
948 else:
949 batch = False
950 vals['prodlot_name'] = False
951# if expiry and not batch:
952# comment += _('Expiry date will be created (with its internal batch).\n')
953# just_warn = True
954# vals.update({
955# 'to_correct_ok': False,
956# 'prodlot_name': False,
957# })
958# if expiry and batch:
959# comment += _('Expiry date selected (with its internal batch).\n')
960# just_warn = True
961 if not expiry:
962 if bad_expiry:
963 comment += _('Incorrectly formatted expiry date.\n')
964 vals['prodlot_name'] = False
965 else:
966 comment += _('Expiry date is missing.\n')
967
968 if hidden_batch_management_mandatory and batch and expiry:
969 pl_ids = pl_obj.search(cr, uid, [('name', '=', batch), ('product_id', '=', vals.get('product_id'))], context=context)
970 if pl_ids and pl_obj.read(cr, uid, pl_ids[0], ['life_date'], context=context)['life_date'] != expiry:
971 comment += _('Expiry date and batch not consistent.\n')
972 vals.update({
973 'prod_lot_id': False,
974 'prodlot_name': '',
975 'expiry_date': False,
976 })
851977
852 if not comment:978 if not comment:
979 if vals.get('comment'):
980 comment = vals.get('comment')
853 vals.update({'comment': comment, 'to_correct_ok': False})981 vals.update({'comment': comment, 'to_correct_ok': False})
854 else:982 elif context.get('import_in_progress'):
855 vals.update({'comment': comment, 'to_correct_ok': True})983 if just_warn:
984 vals.update({'comment': comment, 'to_correct_ok': False})
985 else:
986 vals.update({'comment': comment, 'to_correct_ok': False})
987
856988
857 res = super(initial_stock_inventory_line, self).create(cr, uid, vals, context=context)989 res = super(initial_stock_inventory_line, self).create(cr, uid, vals, context=context)
858 return res990 return res
@@ -877,10 +1009,7 @@
877 if not location_id:1009 if not location_id:
878 comment += _('Location is missing.\n')1010 comment += _('Location is missing.\n')
879 if hidden_batch_management_mandatory and not batch:1011 if hidden_batch_management_mandatory and not batch:
880 if batch_name:1012 comment += _('Batch is missing.\n')
881 comment += _('Batch not found.\n')
882 else:
883 comment += _('Batch is missing.\n')
884 if hidden_perishable_mandatory and not expiry:1013 if hidden_perishable_mandatory and not expiry:
885 comment += _('Expiry date is missing.\n')1014 comment += _('Expiry date is missing.\n')
8861015

Subscribers

People subscribed via source and target branches