summaryrefslogtreecommitdiff
path: root/addons/product_expiry/models/stock_picking.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/product_expiry/models/stock_picking.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/product_expiry/models/stock_picking.py')
-rw-r--r--addons/product_expiry/models/stock_picking.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/addons/product_expiry/models/stock_picking.py b/addons/product_expiry/models/stock_picking.py
new file mode 100644
index 00000000..35d275ba
--- /dev/null
+++ b/addons/product_expiry/models/stock_picking.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, _
+
+
+class StockPicking(models.Model):
+ _inherit = "stock.picking"
+
+ def _pre_action_done_hook(self):
+ res = super()._pre_action_done_hook()
+ # We use the 'skip_expired' context key to avoid to make the check when
+ # user did already confirmed the wizard about expired lots.
+ if res is True and not self.env.context.get('skip_expired'):
+ pickings_to_warn_expired = self._check_expired_lots()
+ if pickings_to_warn_expired:
+ return pickings_to_warn_expired._action_generate_expired_wizard()
+ return res
+
+ def _check_expired_lots(self):
+ expired_pickings = self.move_line_ids.filtered(lambda ml: ml.lot_id.product_expiry_alert).picking_id
+ return expired_pickings
+
+ def _action_generate_expired_wizard(self):
+ expired_lot_ids = self.move_line_ids.filtered(lambda ml: ml.lot_id.product_expiry_alert).lot_id.ids
+ context = dict(self.env.context)
+ context.update({
+ 'default_picking_ids': [(6, 0, self.ids)],
+ 'default_lot_ids': [(6, 0, expired_lot_ids)],
+ })
+ return {
+ 'name': _('Confirmation'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'expiry.picking.confirmation',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': context,
+ }