odoo-addon-shipment-advice 16.0.1.3.1.3__py3-none-any.whl → 16.0.1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. odoo/addons/shipment_advice/README.rst +1 -1
  2. odoo/addons/shipment_advice/__manifest__.py +5 -1
  3. odoo/addons/shipment_advice/data/queue_job_channel.xml +9 -0
  4. odoo/addons/shipment_advice/data/queue_job_function.xml +26 -0
  5. odoo/addons/shipment_advice/i18n/es.po +274 -178
  6. odoo/addons/shipment_advice/i18n/shipment_advice.pot +68 -0
  7. odoo/addons/shipment_advice/models/res_company.py +6 -0
  8. odoo/addons/shipment_advice/models/res_config_settings.py +3 -0
  9. odoo/addons/shipment_advice/models/shipment_advice.py +119 -52
  10. odoo/addons/shipment_advice/static/description/index.html +1 -1
  11. odoo/addons/shipment_advice/tests/__init__.py +1 -0
  12. odoo/addons/shipment_advice/tests/test_shipment_advice.py +1 -1
  13. odoo/addons/shipment_advice/tests/test_shipment_advice_async.py +299 -0
  14. odoo/addons/shipment_advice/views/res_config_settings.xml +17 -0
  15. odoo/addons/shipment_advice/views/shipment_advice.xml +8 -1
  16. odoo/addons/shipment_advice/wizards/load_shipment.py +1 -1
  17. odoo/addons/shipment_advice/wizards/plan_shipment.py +1 -1
  18. odoo/addons/shipment_advice/wizards/unload_shipment.py +2 -2
  19. {odoo_addon_shipment_advice-16.0.1.3.1.3.dist-info → odoo_addon_shipment_advice-16.0.1.4.0.dist-info}/METADATA +3 -2
  20. {odoo_addon_shipment_advice-16.0.1.3.1.3.dist-info → odoo_addon_shipment_advice-16.0.1.4.0.dist-info}/RECORD +22 -19
  21. {odoo_addon_shipment_advice-16.0.1.3.1.3.dist-info → odoo_addon_shipment_advice-16.0.1.4.0.dist-info}/WHEEL +0 -0
  22. {odoo_addon_shipment_advice-16.0.1.3.1.3.dist-info → odoo_addon_shipment_advice-16.0.1.4.0.dist-info}/top_level.txt +0 -0
@@ -13,6 +13,13 @@ msgstr ""
13
13
  "Content-Transfer-Encoding: \n"
14
14
  "Plural-Forms: \n"
15
15
 
16
+ #. module: shipment_advice
17
+ #. odoo-python
18
+ #: code:addons/shipment_advice/models/shipment_advice.py:0
19
+ #, python-format
20
+ msgid "%(sa)s: %(pick)s background validation"
21
+ msgstr ""
22
+
16
23
  #. module: shipment_advice
17
24
  #: model:ir.actions.report,print_report_name:shipment_advice.action_report_shipment_advice
18
25
  msgid "'Shipment Advice - %s' % (object.name)"
@@ -63,6 +70,15 @@ msgstr ""
63
70
  msgid "Activity Type Icon"
64
71
  msgstr ""
65
72
 
73
+ #. module: shipment_advice
74
+ #. odoo-python
75
+ #: code:addons/shipment_advice/models/shipment_advice.py:0
76
+ #, python-format
77
+ msgid ""
78
+ "An error occurred while processing:\n"
79
+ "- %(related_object_name)s: %(error)s"
80
+ msgstr ""
81
+
66
82
  #. module: shipment_advice
67
83
  #: model:ir.model.fields,field_description:shipment_advice.field_shipment_advice__arrival_date
68
84
  msgid "Arrival Date"
@@ -236,6 +252,16 @@ msgstr ""
236
252
  msgid "Driver signature"
237
253
  msgstr ""
238
254
 
255
+ #. module: shipment_advice
256
+ #: model:ir.model.fields.selection,name:shipment_advice.selection__shipment_advice__state__error
257
+ msgid "Error"
258
+ msgstr ""
259
+
260
+ #. module: shipment_advice
261
+ #: model:ir.model.fields,field_description:shipment_advice.field_shipment_advice__error_message
262
+ msgid "Error Message"
263
+ msgstr ""
264
+
239
265
  #. module: shipment_advice
240
266
  #: model:ir.model.fields,field_description:shipment_advice.field_shipment_advice__message_follower_ids
241
267
  msgid "Followers"
@@ -309,6 +335,11 @@ msgid ""
309
335
  "If you want to mark deliveries as done only when they are all loaded in a shipment advice choose 'Leave open'. This last option is useful when your deliveries will be shipped by several trucks."
310
336
  msgstr ""
311
337
 
338
+ #. module: shipment_advice
339
+ #: model:ir.model.fields.selection,name:shipment_advice.selection__shipment_advice__state__in_process
340
+ msgid "In process"
341
+ msgstr ""
342
+
312
343
  #. module: shipment_advice
313
344
  #: model:ir.model.fields.selection,name:shipment_advice.selection__shipment_advice__state__in_progress
314
345
  msgid "In progress"
@@ -686,6 +717,13 @@ msgstr ""
686
717
  msgid "Number of messages with delivery error"
687
718
  msgstr ""
688
719
 
720
+ #. module: shipment_advice
721
+ #. odoo-python
722
+ #: code:addons/shipment_advice/models/shipment_advice.py:0
723
+ #, python-format
724
+ msgid "One of the pickings to process failed to validate"
725
+ msgstr ""
726
+
689
727
  #. module: shipment_advice
690
728
  #: model:ir.model.fields,field_description:shipment_advice.field_wizard_load_shipment__open_shipment
691
729
  msgid "Open Shipment"
@@ -913,6 +951,13 @@ msgstr ""
913
951
  msgid "Responsible User"
914
952
  msgstr ""
915
953
 
954
+ #. module: shipment_advice
955
+ #: model:ir.model.fields,field_description:shipment_advice.field_res_company__shipment_advice_run_in_queue_job
956
+ #: model:ir.model.fields,field_description:shipment_advice.field_res_config_settings__shipment_advice_run_in_queue_job
957
+ #: model:ir.model.fields,field_description:shipment_advice.field_shipment_advice__run_in_queue_job
958
+ msgid "Run shipment advice in queue job"
959
+ msgstr ""
960
+
916
961
  #. module: shipment_advice
917
962
  #: model:ir.actions.report,name:shipment_advice.action_report_shipment_advice
918
963
  #: model:ir.model,name:shipment_advice.model_shipment_advice
@@ -1034,6 +1079,24 @@ msgstr ""
1034
1079
  msgid "To plan in Shipment Advice"
1035
1080
  msgstr ""
1036
1081
 
1082
+ #. module: shipment_advice
1083
+ #: model_terms:ir.ui.view,arch_db:shipment_advice.res_config_settings_view_form
1084
+ msgid ""
1085
+ "To prevent timeouts for large shipments, enable this option to execute\n"
1086
+ " shipment advice validation through a queued job. Each picking will be\n"
1087
+ " validated in a separate jobs."
1088
+ msgstr ""
1089
+
1090
+ #. module: shipment_advice
1091
+ #: model:ir.model.fields,help:shipment_advice.field_res_company__shipment_advice_run_in_queue_job
1092
+ #: model:ir.model.fields,help:shipment_advice.field_res_config_settings__shipment_advice_run_in_queue_job
1093
+ #: model:ir.model.fields,help:shipment_advice.field_shipment_advice__run_in_queue_job
1094
+ msgid ""
1095
+ "To prevent timeouts for large shipments, enable this option to execute "
1096
+ "shipment advice validation through a queued jobs. Each picking will be "
1097
+ "validated in a separate job."
1098
+ msgstr ""
1099
+
1037
1100
  #. module: shipment_advice
1038
1101
  #: model_terms:ir.ui.view,arch_db:shipment_advice.shipment_advice_view_search
1039
1102
  msgid "Today"
@@ -1321,3 +1384,8 @@ msgid ""
1321
1384
  "You cannot unload this move line alone, you have to unload the whole package"
1322
1385
  " content."
1323
1386
  msgstr ""
1387
+
1388
+ #. module: shipment_advice
1389
+ #: model_terms:ir.ui.view,arch_db:shipment_advice.res_config_settings_view_form
1390
+ msgid "shipment_advice_run_in_queue_job"
1391
+ msgstr ""
@@ -23,3 +23,9 @@ class ResCompany(models.Model):
23
23
  "deliveries will be shipped by several trucks."
24
24
  ),
25
25
  )
26
+ shipment_advice_run_in_queue_job = fields.Boolean(
27
+ string="Run shipment advice in queue job",
28
+ help="To prevent timeouts for large shipments, enable this option to execute "
29
+ "shipment advice validation through a queued jobs. Each picking will be "
30
+ "validated in a separate job.",
31
+ )
@@ -10,3 +10,6 @@ class ResConfigSettings(models.TransientModel):
10
10
  shipment_advice_outgoing_backorder_policy = fields.Selection(
11
11
  related="company_id.shipment_advice_outgoing_backorder_policy", readonly=False
12
12
  )
13
+ shipment_advice_run_in_queue_job = fields.Boolean(
14
+ related="company_id.shipment_advice_run_in_queue_job", readonly=False
15
+ )
@@ -4,6 +4,9 @@
4
4
  from odoo import _, api, fields, models
5
5
  from odoo.exceptions import UserError
6
6
 
7
+ from odoo.addons.queue_job.delay import chain, group
8
+ from odoo.addons.queue_job.job import identity_exact
9
+
7
10
 
8
11
  class ShipmentAdvice(models.Model):
9
12
  _name = "shipment.advice"
@@ -23,11 +26,14 @@ class ShipmentAdvice(models.Model):
23
26
  ("draft", "Draft"),
24
27
  ("confirmed", "Confirmed"),
25
28
  ("in_progress", "In progress"),
29
+ ("in_process", "In process"),
30
+ ("error", "Error"),
26
31
  ("done", "Done"),
27
32
  ("cancel", "Cancelled"),
28
33
  ],
29
34
  string="Status",
30
35
  default="draft",
36
+ tracking=True,
31
37
  )
32
38
  warehouse_id = fields.Many2one(
33
39
  comodel_name="stock.warehouse",
@@ -168,6 +174,10 @@ class ShipmentAdvice(models.Model):
168
174
  "(e.g. through the shopfloor application)."
169
175
  ),
170
176
  )
177
+ run_in_queue_job = fields.Boolean(
178
+ related="company_id.shipment_advice_run_in_queue_job"
179
+ )
180
+ error_message = fields.Text(tracking=True)
171
181
 
172
182
  _sql_constraints = [
173
183
  (
@@ -295,64 +305,121 @@ class ShipmentAdvice(models.Model):
295
305
  self.env.cr.execute(sql, (tuple(records.ids),), log_exceptions=False)
296
306
 
297
307
  def action_done(self):
298
- wiz_model = self.env["stock.backorder.confirmation"]
308
+ self._check_action_done_allowed()
309
+ for shipment in self:
310
+ shipment._action_done()
311
+ return True
312
+
313
+ def _get_picking_to_process(self):
314
+ self.ensure_one()
315
+ if self.shipment_type == "incoming":
316
+ return self.planned_picking_ids
317
+ return self.loaded_picking_ids
318
+
319
+ def _action_done(self):
320
+ # Validate transfers (create backorders for unprocessed lines)
321
+ self.ensure_one()
322
+ self.write({"state": "in_process", "error_message": False})
323
+
324
+ if self.shipment_type == "incoming":
325
+ backorder_policy = "create_backorder"
326
+ else:
327
+ backorder_policy = self.company_id.shipment_advice_outgoing_backorder_policy
328
+ pickings = self._get_picking_to_process().filtered(
329
+ lambda p: p.state not in ("cancel", "done")
330
+ )
331
+ if self.run_in_queue_job:
332
+ chain(
333
+ group(
334
+ *[
335
+ self.delayable(
336
+ identity_key=identity_exact,
337
+ description=_(
338
+ "%(sa)s: %(pick)s background validation",
339
+ sa=self.name,
340
+ pick=picking.name,
341
+ ),
342
+ )._validate_picking(picking, backorder_policy)
343
+ for picking in pickings
344
+ ]
345
+ ),
346
+ group(self.delayable(description=self.name)._unplan_undone_moves()),
347
+ group(self.delayable(description=self.name)._postprocess_action_done()),
348
+ ).delay()
349
+ return
350
+ for picking in pickings:
351
+ self._validate_picking(picking, backorder_policy)
352
+ self._unplan_undone_moves()
353
+ self._postprocess_action_done()
354
+
355
+ def _check_action_done_allowed(self):
299
356
  for shipment in self:
300
- if shipment.state != "in_progress":
357
+ if shipment.state not in ("in_progress", "error"):
301
358
  raise UserError(
302
359
  _("Shipment {} is not started, operation aborted.").format(
303
360
  shipment.name
304
361
  )
305
362
  )
306
- # Validate transfers (create backorders for unprocessed lines)
307
- if shipment.shipment_type == "incoming":
308
- self._lock_records(self.planned_picking_ids)
309
- for picking in self.planned_picking_ids:
310
- if picking.state in ("cancel", "done"):
311
- continue
312
- if picking._check_backorder():
313
- wiz = wiz_model.create({})
314
- wiz.pick_ids = picking
315
- wiz.with_context(
316
- button_validate_picking_ids=picking.ids
317
- ).process()
318
- else:
319
- picking._action_done()
320
- else:
321
- backorder_policy = (
322
- shipment.company_id.shipment_advice_outgoing_backorder_policy
323
- )
324
- self._lock_records(self.loaded_picking_ids)
325
- if backorder_policy == "create_backorder":
326
- for picking in self.loaded_picking_ids:
327
- if picking.state in ("cancel", "done"):
328
- continue
329
- if picking._check_backorder():
330
- wiz = wiz_model.create({})
331
- wiz.pick_ids = picking
332
- wiz.with_context(
333
- button_validate_picking_ids=picking.ids
334
- ).process()
335
- else:
336
- picking._action_done()
337
- else:
338
- for picking in self.loaded_picking_ids:
339
- if picking.state in ("cancel", "done"):
340
- continue
341
- if not picking._check_backorder():
342
- # no backorder needed means that all qty_done are
343
- # set to fullfill the need => validate
344
- picking._action_done()
345
- # Unplan moves that were not loaded and validated
346
- moves_to_unplan = (
347
- self.loaded_move_line_ids.move_id | self.planned_move_ids
348
- ).filtered(
349
- lambda m: m.state not in ("cancel", "done") and not m.quantity_done
350
- )
351
- moves_to_unplan.shipment_advice_id = False
352
- if not shipment.departure_date:
353
- shipment.departure_date = fields.Datetime.now()
354
- shipment.state = "done"
355
- return True
363
+
364
+ def _validate_picking(self, picking, backorder_policy="create_backorder"):
365
+ self.ensure_one()
366
+ self._lock_records(picking)
367
+ try:
368
+ with self.env.cr.savepoint():
369
+ if (
370
+ picking._check_backorder()
371
+ and backorder_policy == "create_backorder"
372
+ ):
373
+ wiz = self.env["stock.backorder.confirmation"].create({})
374
+ wiz.pick_ids = picking
375
+ wiz.with_context(button_validate_picking_ids=picking.ids).process()
376
+ elif not picking._check_backorder():
377
+ picking._action_done()
378
+ except UserError as error:
379
+ self.write(
380
+ {
381
+ "state": "error",
382
+ "error_message": self._get_error_message(error, picking),
383
+ }
384
+ )
385
+
386
+ def _unplan_undone_moves(self):
387
+ """Unplan moves that were not loaded and validated"""
388
+ self.ensure_one()
389
+ if self.state != "in_process" or self.shipment_type != "outgoing":
390
+ return
391
+ moves_to_unplan = (
392
+ self.loaded_move_line_ids.move_id | self.planned_move_ids
393
+ ).filtered(lambda m: m.state not in ("cancel", "done") and not m.quantity_done)
394
+ moves_to_unplan.shipment_advice_id = False
395
+
396
+ def _postprocess_action_done(self):
397
+ self.ensure_one()
398
+ if self.state != "in_process":
399
+ return
400
+ if self._get_picking_to_process().filtered(
401
+ lambda p: p.state not in ("done", "cancel")
402
+ ):
403
+ self.write(
404
+ {
405
+ "state": "error",
406
+ "error_message": _(
407
+ "One of the pickings to process failed to validate"
408
+ ),
409
+ }
410
+ )
411
+ return
412
+ if not self.departure_date:
413
+ self.departure_date = fields.Datetime.now()
414
+ self.write({"state": "done", "error_message": False})
415
+
416
+ @api.model
417
+ def _get_error_message(self, error, related_object):
418
+ return _(
419
+ "An error occurred while processing:\n- %(related_object_name)s: %(error)s",
420
+ related_object_name=related_object.display_name,
421
+ error=str(error),
422
+ )
356
423
 
357
424
  def action_cancel(self):
358
425
  for shipment in self:
@@ -366,7 +366,7 @@ ul.auto-toc {
366
366
  !! This file is generated by oca-gen-addon-readme !!
367
367
  !! changes will be overwritten. !!
368
368
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369
- !! source digest: sha256:2ce9096e86385f60cb183efb0745bb01324df6f1dee67604801fd7b364a0a68e
369
+ !! source digest: sha256:d15a08534108c95673383be523fd4d221150eb3270f749dad244c6f2504036b0
370
370
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371
371
  <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-transport/tree/16.0/shipment_advice"><img alt="OCA/stock-logistics-transport" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--transport-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-transport-16-0/stock-logistics-transport-16-0-shipment_advice"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-transport&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372
372
  <p>Manage your (un)loading process through shipment advices.</p>
@@ -1,4 +1,5 @@
1
1
  from . import test_shipment_advice
2
+ from . import test_shipment_advice_async
2
3
  from . import test_shipment_advice_plan
3
4
  from . import test_shipment_advice_load
4
5
  from . import test_shipment_advice_unload
@@ -108,7 +108,7 @@ class TestShipmentAdvice(Common):
108
108
  # Validate the shipment => the transfer is still open
109
109
  self.shipment_advice_out.action_done()
110
110
  picking = package_level.picking_id
111
- self.assertEqual(self.shipment_advice_out.state, "done")
111
+ self.assertEqual(self.shipment_advice_out.state, "error")
112
112
  # Check the transfer
113
113
  self.assertTrue(
114
114
  all(