Merge lp:~unifield-team/unifield-wm/us-862 into lp:unifield-wm
- us-862
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+284481@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 '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 | 102 | reader.next() | 102 | reader.next() |
6 | 103 | line_num = 1 | 103 | line_num = 1 |
7 | 104 | product_error = [] | 104 | product_error = [] |
8 | 105 | no_product_error = [] | ||
9 | 105 | for row in reader: | 106 | for row in reader: |
10 | 106 | line_num += 1 | 107 | line_num += 1 |
11 | 107 | # Check length of the row | 108 | # Check length of the row |
12 | @@ -114,6 +115,7 @@ | |||
13 | 114 | product_cost = 1.00 | 115 | product_cost = 1.00 |
14 | 115 | currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id | 116 | currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id |
15 | 116 | location_id = False | 117 | location_id = False |
16 | 118 | location_not_found = False | ||
17 | 117 | batch = False | 119 | batch = False |
18 | 118 | batch_name = False | 120 | batch_name = False |
19 | 119 | expiry = False | 121 | expiry = False |
20 | @@ -129,6 +131,8 @@ | |||
21 | 129 | if not product_code: | 131 | if not product_code: |
22 | 130 | to_correct_ok = True | 132 | to_correct_ok = True |
23 | 131 | import_to_correct = True | 133 | import_to_correct = True |
24 | 134 | no_product_error.append(line_num) | ||
25 | 135 | continue | ||
26 | 132 | else: | 136 | else: |
27 | 133 | try: | 137 | try: |
28 | 134 | product_code = product_code.strip() | 138 | product_code = product_code.strip() |
29 | @@ -143,13 +147,13 @@ | |||
30 | 143 | to_correct_ok = True | 147 | to_correct_ok = True |
31 | 144 | import_to_correct = True | 148 | import_to_correct = True |
32 | 145 | 149 | ||
40 | 146 | # Product name | 150 | # Product name |
41 | 147 | p_name = row.cells[1].data | 151 | p_name = row.cells[1].data |
42 | 148 | if not product_id: | 152 | if not product_id: |
43 | 149 | to_correct_ok = True | 153 | to_correct_ok = True |
44 | 150 | import_to_correct = True | 154 | import_to_correct = True |
45 | 151 | product_error.append(line_num) | 155 | product_error.append(line_num) |
46 | 152 | continue | 156 | continue |
47 | 153 | 157 | ||
48 | 154 | # Location | 158 | # Location |
49 | 155 | loc_id = row.cells[2].data | 159 | loc_id = row.cells[2].data |
50 | @@ -165,6 +169,7 @@ | |||
51 | 165 | location_id = False | 169 | location_id = False |
52 | 166 | to_correct_ok = True | 170 | to_correct_ok = True |
53 | 167 | import_to_correct = True | 171 | import_to_correct = True |
54 | 172 | location_not_found = True | ||
55 | 168 | else: | 173 | else: |
56 | 169 | location_id = loc_ids[0] | 174 | location_id = loc_ids[0] |
57 | 170 | except Exception: | 175 | except Exception: |
58 | @@ -203,10 +208,13 @@ | |||
59 | 203 | expiry = row.cells[4].data.strftime('%Y-%m-%d') | 208 | expiry = row.cells[4].data.strftime('%Y-%m-%d') |
60 | 204 | else: | 209 | else: |
61 | 205 | bad_expiry = True | 210 | bad_expiry = True |
63 | 206 | comment += _('Incorrectly formatted expiry date.') | 211 | comment += _('Incorrectly formatted expiry date.\n') |
64 | 207 | to_correct_ok = True | 212 | to_correct_ok = True |
65 | 208 | import_to_correct = True | 213 | import_to_correct = True |
66 | 209 | if expiry and not batch: | 214 | if expiry and not batch: |
67 | 215 | batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context) | ||
68 | 216 | if batch_ids: | ||
69 | 217 | comment += _('Other batch with the same expiry date exist.\n') | ||
70 | 210 | if product.batch_management and batch_name: | 218 | if product.batch_management and batch_name: |
71 | 211 | batch = batch_obj.create(cr, uid, { | 219 | batch = batch_obj.create(cr, uid, { |
72 | 212 | 'product_id': product_id, | 220 | 'product_id': product_id, |
73 | @@ -217,25 +225,17 @@ | |||
74 | 217 | batch = False | 225 | batch = False |
75 | 218 | to_correct_ok = True | 226 | to_correct_ok = True |
76 | 219 | import_to_correct = True | 227 | import_to_correct = True |
77 | 220 | else: | ||
78 | 221 | if batch_name: | ||
79 | 222 | batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry), ('name', '=', batch_name)], context=context) | ||
80 | 223 | else: | ||
81 | 224 | batch_ids = batch_obj.search(cr, uid, [('product_id', '=', product_id), ('life_date', '=', expiry)], context=context) | ||
82 | 225 | if not batch_ids: | ||
83 | 226 | if batch_name: | ||
84 | 227 | expiry = False | ||
85 | 228 | batch = False | ||
86 | 229 | to_correct_ok = True | ||
87 | 230 | import_to_correct = True | ||
88 | 231 | else: | ||
89 | 232 | batch = batch_ids[0] | ||
90 | 233 | elif expiry and batch: | 228 | elif expiry and batch: |
91 | 234 | b_expiry = batch_obj.browse(cr, uid, batch, context=context).life_date | 229 | b_expiry = batch_obj.browse(cr, uid, batch, context=context).life_date |
92 | 235 | if expiry != b_expiry: | 230 | if expiry != b_expiry: |
96 | 236 | err_exp_message = _('Expiry date inconsistent with %s') % row.cells[3].data | 231 | if product.batch_management: |
97 | 237 | comment += err_exp_message | 232 | err_exp_message = _('Expiry date inconsistent with %s.\n') % row.cells[3].data |
98 | 238 | comment += '\n' | 233 | comment += err_exp_message |
99 | 234 | comment += '\n' | ||
100 | 235 | expiry = False | ||
101 | 236 | elif product.perishable: | ||
102 | 237 | batch = False | ||
103 | 238 | |||
104 | 239 | # Quantity | 239 | # Quantity |
105 | 240 | p_qty = row.cells[5].data | 240 | p_qty = row.cells[5].data |
106 | 241 | if not p_qty: | 241 | if not p_qty: |
107 | @@ -246,8 +246,10 @@ | |||
108 | 246 | else: | 246 | else: |
109 | 247 | product_qty = 0.00 | 247 | product_qty = 0.00 |
110 | 248 | 248 | ||
112 | 249 | if not location_id: | 249 | if not location_id and not location_not_found: |
113 | 250 | comment += _('Location is missing.\n') | 250 | comment += _('Location is missing.\n') |
114 | 251 | elif location_not_found: | ||
115 | 252 | comment += _('Location not found.\n') | ||
116 | 251 | if product: | 253 | if product: |
117 | 252 | product_uom = product.uom_id.id | 254 | product_uom = product.uom_id.id |
118 | 253 | hidden_batch_management_mandatory = product.batch_management | 255 | hidden_batch_management_mandatory = product.batch_management |
119 | @@ -257,19 +259,34 @@ | |||
120 | 257 | comment += _('Batch not found.\n') | 259 | comment += _('Batch not found.\n') |
121 | 258 | else: | 260 | else: |
122 | 259 | comment += _('Batch is missing.\n') | 261 | comment += _('Batch is missing.\n') |
124 | 260 | if hidden_perishable_mandatory and not expiry: | 262 | if hidden_perishable_mandatory and not expiry and not bad_expiry: |
125 | 261 | comment += _('Expiry date is missing.\n') | 263 | comment += _('Expiry date is missing.\n') |
127 | 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): |
128 | 265 | batch = False | ||
129 | 266 | bad_batch_name = False | ||
130 | 267 | expiry = False | ||
131 | 268 | bad_expiry = False | ||
132 | 269 | # Remove the res.log that indicates errors on import | ||
133 | 270 | if to_correct_ok and location_id and not location_not_found: | ||
134 | 271 | to_correct_ok = False | ||
135 | 272 | comment = '' | ||
136 | 263 | comment += _('This product is not Batch Number managed.\n') | 273 | comment += _('This product is not Batch Number managed.\n') |
137 | 274 | if not hidden_perishable_mandatory and (expiry or bad_expiry): | ||
138 | 264 | batch = False | 275 | batch = False |
140 | 265 | if not hidden_perishable_mandatory and expiry: | 276 | bad_batch_name = False |
141 | 277 | expiry = False | ||
142 | 278 | bad_expiry = False | ||
143 | 279 | # Remove the res.log that indicates errors on import | ||
144 | 280 | if to_correct_ok and location_id and not location_not_found: | ||
145 | 281 | to_correct_ok = False | ||
146 | 282 | comment = '' | ||
147 | 266 | comment += _('This product is not Expiry Date managed.\n') | 283 | comment += _('This product is not Expiry Date managed.\n') |
148 | 267 | expiry = False | ||
149 | 268 | else: | 284 | else: |
150 | 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] |
151 | 270 | hidden_batch_management_mandatory = False | 286 | hidden_batch_management_mandatory = False |
152 | 271 | hidden_perishable_mandatory = False | 287 | hidden_perishable_mandatory = False |
153 | 272 | 288 | ||
154 | 289 | |||
155 | 273 | if product_uom and product_qty: | 290 | if product_uom and product_qty: |
156 | 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) |
157 | 275 | 292 | ||
158 | @@ -281,6 +298,7 @@ | |||
159 | 281 | 'reason_type_id': discrepancy_id, | 298 | 'reason_type_id': discrepancy_id, |
160 | 282 | 'currency_id': currency_id, | 299 | 'currency_id': currency_id, |
161 | 283 | 'location_id': location_id, | 300 | 'location_id': location_id, |
162 | 301 | 'location_not_found': location_not_found, | ||
163 | 284 | 'prod_lot_id': batch, | 302 | 'prod_lot_id': batch, |
164 | 285 | 'expiry_date': expiry, | 303 | 'expiry_date': expiry, |
165 | 286 | 'bad_expiry': bad_expiry, | 304 | 'bad_expiry': bad_expiry, |
166 | @@ -303,6 +321,14 @@ | |||
167 | 303 | len(product_error) > 1 and 's' or '', | 321 | len(product_error) > 1 and 's' or '', |
168 | 304 | ' / '.join(str(x) for x in product_error)), | 322 | ' / '.join(str(x) for x in product_error)), |
169 | 305 | ) | 323 | ) |
170 | 324 | if no_product_error: | ||
171 | 325 | raise osv.except_osv( | ||
172 | 326 | _('Error'), | ||
173 | 327 | _('Product not defined on %s line%s: %s') % ( | ||
174 | 328 | len(no_product_error) > 1 and 'these' or 'this', | ||
175 | 329 | len(no_product_error) > 1 and 's' or '', | ||
176 | 330 | ' / '.join(str(x) for x in no_product_error)), | ||
177 | 331 | ) | ||
178 | 306 | 332 | ||
179 | 307 | # write order line on Inventory | 333 | # write order line on Inventory |
180 | 308 | context['import_in_progress'] = True | 334 | context['import_in_progress'] = True |
181 | @@ -312,7 +338,7 @@ | |||
182 | 312 | 338 | ||
183 | 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] |
184 | 314 | 340 | ||
186 | 315 | if import_to_correct: | 341 | if any(x[2]['to_correct'] for x in vals['inventory_line_id']): |
187 | 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") |
188 | 317 | 343 | ||
189 | 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,}) |
190 | @@ -377,6 +403,7 @@ | |||
191 | 377 | if context is None: | 403 | if context is None: |
192 | 378 | context = {} | 404 | context = {} |
193 | 379 | comment = '' | 405 | comment = '' |
194 | 406 | just_warn = False | ||
195 | 380 | pl_obj = self.pool.get('stock.production.lot') | 407 | pl_obj = self.pool.get('stock.production.lot') |
196 | 381 | hidden_batch_management_mandatory = False | 408 | hidden_batch_management_mandatory = False |
197 | 382 | hidden_perishable_mandatory = False | 409 | hidden_perishable_mandatory = False |
198 | @@ -389,6 +416,11 @@ | |||
199 | 389 | vals['hidden_perishable_mandatory'] = hidden_perishable_mandatory | 416 | vals['hidden_perishable_mandatory'] = hidden_perishable_mandatory |
200 | 390 | 417 | ||
201 | 391 | location_id = vals.get('location_id') | 418 | location_id = vals.get('location_id') |
202 | 419 | location_not_found = vals.get('location_not_found') | ||
203 | 420 | |||
204 | 421 | if 'location_not_found' in vals: | ||
205 | 422 | del vals['location_not_found'] | ||
206 | 423 | |||
207 | 392 | batch = vals.get('prod_lot_id') | 424 | batch = vals.get('prod_lot_id') |
208 | 393 | expiry = vals.get('expiry_date') | 425 | expiry = vals.get('expiry_date') |
209 | 394 | batch_name = vals.get('batch_name') | 426 | batch_name = vals.get('batch_name') |
210 | @@ -401,18 +433,22 @@ | |||
211 | 401 | if 'bad_batch_name' in vals: | 433 | if 'bad_batch_name' in vals: |
212 | 402 | del vals['bad_batch_name'] | 434 | del vals['bad_batch_name'] |
213 | 403 | 435 | ||
215 | 404 | if not location_id: | 436 | if not location_id and not location_not_found: |
216 | 405 | comment += _('Location is missing.\n') | 437 | comment += _('Location is missing.\n') |
217 | 438 | elif location_not_found: | ||
218 | 439 | comment += _('Location not found.\n') | ||
219 | 406 | 440 | ||
220 | 407 | if hidden_batch_management_mandatory and not batch: | 441 | if hidden_batch_management_mandatory and not batch: |
221 | 408 | if bad_batch_name: | 442 | if bad_batch_name: |
222 | 409 | comment += _('Incorrect batch number format.\n') | 443 | comment += _('Incorrect batch number format.\n') |
223 | 444 | vals['expiry_date'] = False | ||
224 | 410 | elif batch_name and not bad_expiry and expiry: | 445 | elif batch_name and not bad_expiry and expiry: |
225 | 411 | comment += _('Batch not found.\n') | 446 | comment += _('Batch not found.\n') |
226 | 412 | elif batch_name and not bad_expiry and not expiry: | 447 | elif batch_name and not bad_expiry and not expiry: |
227 | 413 | comment += _('Expiry date is missing.\n') | 448 | comment += _('Expiry date is missing.\n') |
228 | 414 | elif batch_name and bad_expiry: | 449 | elif batch_name and bad_expiry: |
229 | 415 | comment += _('Incorrectly formatted expiry date. Batch not created.\n') | 450 | comment += _('Incorrectly formatted expiry date. Batch not created.\n') |
230 | 451 | vals['expiry_date'] = False | ||
231 | 416 | else: | 452 | else: |
232 | 417 | comment += _('Batch is missing.\n') | 453 | comment += _('Batch is missing.\n') |
233 | 418 | vals['expiry_date'] = False | 454 | vals['expiry_date'] = False |
234 | @@ -425,27 +461,34 @@ | |||
235 | 425 | else: | 461 | else: |
236 | 426 | comment += _('Batch not found.\n') | 462 | comment += _('Batch not found.\n') |
237 | 427 | elif hidden_perishable_mandatory and not expiry: | 463 | elif hidden_perishable_mandatory and not expiry: |
239 | 428 | comment += _('Expiry date is missing.\n') | 464 | if not bad_expiry: |
240 | 465 | comment += _('Expiry date is missing.\n') | ||
241 | 466 | else: | ||
242 | 467 | comment += _('Incorrectly formatted expiry date.\n') | ||
243 | 429 | vals['expiry_date'] = False | 468 | vals['expiry_date'] = False |
244 | 430 | 469 | ||
251 | 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) \ |
252 | 432 | comment += _('Expiry date and batch not consistent') | 471 | # or (not batch and expiry and not bad_expiry)): |
253 | 433 | vals.update({ | 472 | # comment += _('Expiry date will be created (with its internal batch).\n') |
254 | 434 | 'prod_lot_id': False, | 473 | # just_warn = True |
255 | 435 | 'expiry_date': False, | 474 | # vals.update({ |
256 | 436 | }) | 475 | # 'prod_lot_id': False, |
257 | 476 | # 'to_correct_ok': False, | ||
258 | 477 | # }) | ||
259 | 437 | 478 | ||
260 | 438 | if hidden_batch_management_mandatory and batch and not expiry: | 479 | if hidden_batch_management_mandatory and batch and not expiry: |
261 | 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'] |
264 | 440 | vals['expiry_date'] = expiry | 481 | comment += _('Please check Expiry Date is correct!.\n') |
263 | 441 | comment += _('Please check Expiry Date is correct!') | ||
265 | 442 | 482 | ||
266 | 443 | if not comment: | 483 | if not comment: |
267 | 444 | if vals.get('comment'): | 484 | if vals.get('comment'): |
268 | 445 | comment = vals.get('comment') | 485 | comment = vals.get('comment') |
269 | 446 | vals.update({'comment': comment, 'to_correct_ok': False}) | 486 | vals.update({'comment': comment, 'to_correct_ok': False}) |
270 | 447 | elif context.get('import_in_progress'): | 487 | elif context.get('import_in_progress'): |
272 | 448 | vals.update({'comment': comment, 'to_correct_ok': True}) | 488 | if just_warn: |
273 | 489 | vals.update({'comment': comment, 'to_correct_ok': False}) | ||
274 | 490 | else: | ||
275 | 491 | vals.update({'comment': comment, 'to_correct_ok': True}) | ||
276 | 449 | 492 | ||
277 | 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) |
278 | 451 | return res | 494 | return res |
279 | @@ -556,6 +599,7 @@ | |||
280 | 556 | 599 | ||
281 | 557 | product_cache = {} | 600 | product_cache = {} |
282 | 558 | product_error = [] | 601 | product_error = [] |
283 | 602 | no_product_error = [] | ||
284 | 559 | 603 | ||
285 | 560 | fileobj = SpreadsheetXML(xmlstring=base64.decodestring(obj.file_to_import)) | 604 | fileobj = SpreadsheetXML(xmlstring=base64.decodestring(obj.file_to_import)) |
286 | 561 | 605 | ||
287 | @@ -577,6 +621,7 @@ | |||
288 | 577 | product_cost = 1.00 | 621 | product_cost = 1.00 |
289 | 578 | currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id | 622 | currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id |
290 | 579 | location_id = False | 623 | location_id = False |
291 | 624 | location_not_found = False | ||
292 | 580 | batch = False | 625 | batch = False |
293 | 581 | expiry = False | 626 | expiry = False |
294 | 582 | bad_expiry = None | 627 | bad_expiry = None |
295 | @@ -592,6 +637,8 @@ | |||
296 | 592 | if not product_code: | 637 | if not product_code: |
297 | 593 | to_correct_ok = True | 638 | to_correct_ok = True |
298 | 594 | import_to_correct = True | 639 | import_to_correct = True |
299 | 640 | no_product_error.append(line_num) | ||
300 | 641 | continue | ||
301 | 595 | else: | 642 | else: |
302 | 596 | try: | 643 | try: |
303 | 597 | product_code = product_code.strip() | 644 | product_code = product_code.strip() |
304 | @@ -606,13 +653,13 @@ | |||
305 | 606 | to_correct_ok = True | 653 | to_correct_ok = True |
306 | 607 | import_to_correct = True | 654 | import_to_correct = True |
307 | 608 | 655 | ||
315 | 609 | # Product name | 656 | # Product name |
316 | 610 | p_name = row.cells[1].data | 657 | p_name = row.cells[1].data |
317 | 611 | if not product_id: | 658 | if not product_id: |
318 | 612 | to_correct_ok = True | 659 | to_correct_ok = True |
319 | 613 | import_to_correct = True | 660 | import_to_correct = True |
320 | 614 | product_error.append(line_num) | 661 | product_error.append(line_num) |
321 | 615 | continue | 662 | continue |
322 | 616 | 663 | ||
323 | 617 | # Average cost | 664 | # Average cost |
324 | 618 | cost = row.cells[2].data | 665 | cost = row.cells[2].data |
325 | @@ -644,6 +691,7 @@ | |||
326 | 644 | location_id = False | 691 | location_id = False |
327 | 645 | to_correct_ok = True | 692 | to_correct_ok = True |
328 | 646 | import_to_correct = True | 693 | import_to_correct = True |
329 | 694 | location_not_found = True | ||
330 | 647 | else: | 695 | else: |
331 | 648 | location_id = loc_ids[0] | 696 | location_id = loc_ids[0] |
332 | 649 | except Exception: | 697 | except Exception: |
333 | @@ -668,12 +716,9 @@ | |||
334 | 668 | expiry = row.cells[5].data | 716 | expiry = row.cells[5].data |
335 | 669 | else: | 717 | else: |
336 | 670 | bad_expiry = True | 718 | bad_expiry = True |
338 | 671 | comment += _('Incorrectly formatted expiry date.') | 719 | comment += _('Incorrectly formatted expiry date.\n') |
339 | 672 | to_correct_ok = True | 720 | to_correct_ok = True |
340 | 673 | import_to_correct = True | 721 | import_to_correct = True |
341 | 674 | else: | ||
342 | 675 | to_correct_ok = True | ||
343 | 676 | import_to_correct = True | ||
344 | 677 | 722 | ||
345 | 678 | # Quantity | 723 | # Quantity |
346 | 679 | p_qty = row.cells[6].data | 724 | p_qty = row.cells[6].data |
347 | @@ -685,20 +730,47 @@ | |||
348 | 685 | else: | 730 | else: |
349 | 686 | product_qty = 0.00 | 731 | product_qty = 0.00 |
350 | 687 | 732 | ||
352 | 688 | if not location_id: | 733 | if not location_id and not location_not_found: |
353 | 689 | comment += _('Location is missing.\n') | 734 | comment += _('Location is missing.\n') |
354 | 735 | elif location_not_found: | ||
355 | 736 | comment += _('Location not found.\n') | ||
356 | 690 | if product_id: | 737 | if product_id: |
357 | 691 | product = product_obj.browse(cr, uid, product_id) | 738 | product = product_obj.browse(cr, uid, product_id) |
358 | 692 | product_uom = product.uom_id.id | 739 | product_uom = product.uom_id.id |
359 | 693 | hidden_batch_management_mandatory = product.batch_management | 740 | hidden_batch_management_mandatory = product.batch_management |
360 | 694 | hidden_perishable_mandatory = product.perishable | 741 | hidden_perishable_mandatory = product.perishable |
361 | 742 | |||
362 | 743 | if hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name): | ||
363 | 744 | batch_name = False | ||
364 | 745 | bad_batch_name = False | ||
365 | 746 | |||
366 | 695 | if hidden_batch_management_mandatory and not batch: | 747 | if hidden_batch_management_mandatory and not batch: |
367 | 696 | if batch_name: | 748 | if batch_name: |
368 | 697 | comment += _('Batch not found.\n') | 749 | comment += _('Batch not found.\n') |
369 | 698 | else: | 750 | else: |
370 | 699 | comment += _('Batch is missing.\n') | 751 | comment += _('Batch is missing.\n') |
372 | 700 | if hidden_perishable_mandatory and not expiry: | 752 | if hidden_perishable_mandatory and not expiry and not bad_expiry: |
373 | 701 | comment += _('Expiry date is missing.\n') | 753 | comment += _('Expiry date is missing.\n') |
374 | 754 | if not hidden_perishable_mandatory and not hidden_batch_management_mandatory and (batch or bad_batch_name): | ||
375 | 755 | batch = False | ||
376 | 756 | bad_batch_name = False | ||
377 | 757 | expiry = False | ||
378 | 758 | bad_expiry = False | ||
379 | 759 | # Remove the res.log that indicates errors on import | ||
380 | 760 | if to_correct_ok and location_id and not location_not_found: | ||
381 | 761 | to_correct_ok = False | ||
382 | 762 | comment = '' | ||
383 | 763 | comment += _('This product is not Batch Number managed.\n') | ||
384 | 764 | if not hidden_perishable_mandatory and (expiry or bad_expiry): | ||
385 | 765 | batch = False | ||
386 | 766 | bad_batch_name = False | ||
387 | 767 | expiry = False | ||
388 | 768 | bad_expiry = False | ||
389 | 769 | # Remove the res.log that indicates errors on import | ||
390 | 770 | if to_correct_ok and location_id and not location_not_found: | ||
391 | 771 | to_correct_ok = False | ||
392 | 772 | comment = '' | ||
393 | 773 | comment += _('This product is not Expiry Date managed.\n') | ||
394 | 702 | else: | 774 | else: |
395 | 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] |
396 | 704 | hidden_batch_management_mandatory = False | 776 | hidden_batch_management_mandatory = False |
397 | @@ -712,6 +784,7 @@ | |||
398 | 712 | 'average_cost': product_cost, | 784 | 'average_cost': product_cost, |
399 | 713 | 'currency_id': currency_id, | 785 | 'currency_id': currency_id, |
400 | 714 | 'location_id': location_id, | 786 | 'location_id': location_id, |
401 | 787 | 'location_not_found': location_not_found, | ||
402 | 715 | 'prodlot_name': batch, | 788 | 'prodlot_name': batch, |
403 | 716 | 'expiry_date': expiry and expiry.strftime('%Y-%m-%d') or False, | 789 | 'expiry_date': expiry and expiry.strftime('%Y-%m-%d') or False, |
404 | 717 | 'bad_expiry': bad_expiry, | 790 | 'bad_expiry': bad_expiry, |
405 | @@ -734,14 +807,24 @@ | |||
406 | 734 | len(product_error) > 1 and 's' or '', | 807 | len(product_error) > 1 and 's' or '', |
407 | 735 | ' / '.join(str(x) for x in product_error)), | 808 | ' / '.join(str(x) for x in product_error)), |
408 | 736 | ) | 809 | ) |
409 | 810 | if no_product_error: | ||
410 | 811 | raise osv.except_osv( | ||
411 | 812 | _('Error'), | ||
412 | 813 | _('Product not defined on %s line%s: %s') % ( | ||
413 | 814 | len(no_product_error) > 1 and 'these' or 'this', | ||
414 | 815 | len(no_product_error) > 1 and 's' or '', | ||
415 | 816 | ' / '.join(str(x) for x in no_product_error)), | ||
416 | 817 | ) | ||
417 | 737 | 818 | ||
418 | 738 | # write order line on Inventory | 819 | # write order line on Inventory |
419 | 739 | vals.update({'file_to_import': False}) | 820 | vals.update({'file_to_import': False}) |
420 | 821 | context['import_in_progress'] = True | ||
421 | 740 | self.write(cr, uid, ids, vals, context=context) | 822 | self.write(cr, uid, ids, vals, context=context) |
422 | 823 | context['import_in_progress'] = False | ||
423 | 741 | 824 | ||
424 | 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] |
425 | 743 | 826 | ||
427 | 744 | if import_to_correct: | 827 | if any(x[2]['to_correct'] for x in vals['inventory_line_id']): |
428 | 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") |
429 | 746 | 829 | ||
430 | 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,}) |
431 | @@ -804,7 +887,9 @@ | |||
432 | 804 | } | 887 | } |
433 | 805 | 888 | ||
434 | 806 | def create(self, cr, uid, vals, context=None): | 889 | def create(self, cr, uid, vals, context=None): |
435 | 890 | pl_obj = self.pool.get('stock.production.lot') | ||
436 | 807 | comment = '' | 891 | comment = '' |
437 | 892 | just_warn = False | ||
438 | 808 | hidden_batch_management_mandatory = False | 893 | hidden_batch_management_mandatory = False |
439 | 809 | hidden_perishable_mandatory = False | 894 | hidden_perishable_mandatory = False |
440 | 810 | 895 | ||
441 | @@ -814,6 +899,10 @@ | |||
442 | 814 | hidden_perishable_mandatory = product.perishable | 899 | hidden_perishable_mandatory = product.perishable |
443 | 815 | 900 | ||
444 | 816 | location_id = vals.get('location_id') | 901 | location_id = vals.get('location_id') |
445 | 902 | location_not_found = vals.get('location_not_found') | ||
446 | 903 | |||
447 | 904 | if 'location_not_found' in vals: | ||
448 | 905 | del vals['location_not_found'] | ||
449 | 817 | 906 | ||
450 | 818 | batch = vals.get('prodlot_name') | 907 | batch = vals.get('prodlot_name') |
451 | 819 | batch_numer = vals.get('prod_lot_id', False) | 908 | batch_numer = vals.get('prod_lot_id', False) |
452 | @@ -821,7 +910,7 @@ | |||
453 | 821 | batch = self.pool.get('stock.production.lot').browse(cr, uid, batch_numer, context=context).name | 910 | batch = self.pool.get('stock.production.lot').browse(cr, uid, batch_numer, context=context).name |
454 | 822 | vals.update({'prodlot_name':batch}) | 911 | vals.update({'prodlot_name':batch}) |
455 | 823 | expiry = vals.get('expiry_date') | 912 | expiry = vals.get('expiry_date') |
457 | 824 | batch_name = vals.get('batch_name') | 913 | batch_name = vals.get('prodlot_name') |
458 | 825 | bad_expiry = vals.get('bad_expiry') | 914 | bad_expiry = vals.get('bad_expiry') |
459 | 826 | bad_batch_name = vals.get('bad_batch_name') | 915 | bad_batch_name = vals.get('bad_batch_name') |
460 | 827 | 916 | ||
461 | @@ -831,8 +920,10 @@ | |||
462 | 831 | if 'bad_batch_name' in vals: | 920 | if 'bad_batch_name' in vals: |
463 | 832 | del vals['bad_batch_name'] | 921 | del vals['bad_batch_name'] |
464 | 833 | 922 | ||
466 | 834 | if not location_id: | 923 | if not location_id and not location_not_found: |
467 | 835 | comment += _('Location is missing.\n') | 924 | comment += _('Location is missing.\n') |
468 | 925 | elif location_not_found: | ||
469 | 926 | comment += _('Location not found.\n') | ||
470 | 836 | 927 | ||
471 | 837 | if hidden_batch_management_mandatory and not batch: | 928 | if hidden_batch_management_mandatory and not batch: |
472 | 838 | if bad_batch_name: | 929 | if bad_batch_name: |
473 | @@ -843,16 +934,57 @@ | |||
474 | 843 | comment += _('Incorrectly formatted expiry date. Batch not created.\n') | 934 | comment += _('Incorrectly formatted expiry date. Batch not created.\n') |
475 | 844 | else: | 935 | else: |
476 | 845 | comment += _('Batch is missing.\n') | 936 | comment += _('Batch is missing.\n') |
482 | 846 | if hidden_perishable_mandatory and not expiry: | 937 | |
483 | 847 | if bad_expiry: | 938 | if not product.batch_management and hidden_perishable_mandatory: |
484 | 848 | comment += _('Incorrectly formatted expiry date.\n') | 939 | if expiry and batch: |
485 | 849 | else: | 940 | batch_ids = pl_obj.search(cr, uid, [ |
486 | 850 | comment += _('Expiry date is missing.\n') | 941 | ('product_id', '=', product.id), |
487 | 942 | ('life_date', '=', expiry), | ||
488 | 943 | ('name', '=', batch), | ||
489 | 944 | ], context=context) | ||
490 | 945 | if batch_ids: | ||
491 | 946 | batch = pl_obj.browse(cr, uid, batch_ids[0], context=context).name | ||
492 | 947 | vals['prodlot_name'] = batch | ||
493 | 948 | else: | ||
494 | 949 | batch = False | ||
495 | 950 | vals['prodlot_name'] = False | ||
496 | 951 | # if expiry and not batch: | ||
497 | 952 | # comment += _('Expiry date will be created (with its internal batch).\n') | ||
498 | 953 | # just_warn = True | ||
499 | 954 | # vals.update({ | ||
500 | 955 | # 'to_correct_ok': False, | ||
501 | 956 | # 'prodlot_name': False, | ||
502 | 957 | # }) | ||
503 | 958 | # if expiry and batch: | ||
504 | 959 | # comment += _('Expiry date selected (with its internal batch).\n') | ||
505 | 960 | # just_warn = True | ||
506 | 961 | if not expiry: | ||
507 | 962 | if bad_expiry: | ||
508 | 963 | comment += _('Incorrectly formatted expiry date.\n') | ||
509 | 964 | vals['prodlot_name'] = False | ||
510 | 965 | else: | ||
511 | 966 | comment += _('Expiry date is missing.\n') | ||
512 | 967 | |||
513 | 968 | if hidden_batch_management_mandatory and batch and expiry: | ||
514 | 969 | pl_ids = pl_obj.search(cr, uid, [('name', '=', batch), ('product_id', '=', vals.get('product_id'))], context=context) | ||
515 | 970 | if pl_ids and pl_obj.read(cr, uid, pl_ids[0], ['life_date'], context=context)['life_date'] != expiry: | ||
516 | 971 | comment += _('Expiry date and batch not consistent.\n') | ||
517 | 972 | vals.update({ | ||
518 | 973 | 'prod_lot_id': False, | ||
519 | 974 | 'prodlot_name': '', | ||
520 | 975 | 'expiry_date': False, | ||
521 | 976 | }) | ||
522 | 851 | 977 | ||
523 | 852 | if not comment: | 978 | if not comment: |
524 | 979 | if vals.get('comment'): | ||
525 | 980 | comment = vals.get('comment') | ||
526 | 853 | vals.update({'comment': comment, 'to_correct_ok': False}) | 981 | vals.update({'comment': comment, 'to_correct_ok': False}) |
529 | 854 | else: | 982 | elif context.get('import_in_progress'): |
530 | 855 | vals.update({'comment': comment, 'to_correct_ok': True}) | 983 | if just_warn: |
531 | 984 | vals.update({'comment': comment, 'to_correct_ok': False}) | ||
532 | 985 | else: | ||
533 | 986 | vals.update({'comment': comment, 'to_correct_ok': False}) | ||
534 | 987 | |||
535 | 856 | 988 | ||
536 | 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) |
537 | 858 | return res | 990 | return res |
538 | @@ -877,10 +1009,7 @@ | |||
539 | 877 | if not location_id: | 1009 | if not location_id: |
540 | 878 | comment += _('Location is missing.\n') | 1010 | comment += _('Location is missing.\n') |
541 | 879 | if hidden_batch_management_mandatory and not batch: | 1011 | if hidden_batch_management_mandatory and not batch: |
546 | 880 | if batch_name: | 1012 | comment += _('Batch is missing.\n') |
543 | 881 | comment += _('Batch not found.\n') | ||
544 | 882 | else: | ||
545 | 883 | comment += _('Batch is missing.\n') | ||
547 | 884 | if hidden_perishable_mandatory and not expiry: | 1013 | if hidden_perishable_mandatory and not expiry: |
548 | 885 | comment += _('Expiry date is missing.\n') | 1014 | comment += _('Expiry date is missing.\n') |
549 | 886 | 1015 |