summaryrefslogtreecommitdiff
path: root/addons/mrp_product_expiry/models
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/mrp_product_expiry/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/mrp_product_expiry/models')
-rw-r--r--addons/mrp_product_expiry/models/__init__.py5
-rw-r--r--addons/mrp_product_expiry/models/mrp_production.py38
2 files changed, 43 insertions, 0 deletions
diff --git a/addons/mrp_product_expiry/models/__init__.py b/addons/mrp_product_expiry/models/__init__.py
new file mode 100644
index 00000000..3728a50a
--- /dev/null
+++ b/addons/mrp_product_expiry/models/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import mrp_production
+
diff --git a/addons/mrp_product_expiry/models/mrp_production.py b/addons/mrp_product_expiry/models/mrp_production.py
new file mode 100644
index 00000000..21522a84
--- /dev/null
+++ b/addons/mrp_product_expiry/models/mrp_production.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 MrpWorkorder(models.Model):
+ _inherit = 'mrp.production'
+
+ def _pre_button_mark_done(self):
+ confirm_expired_lots = self._check_expired_lots()
+ if confirm_expired_lots:
+ return confirm_expired_lots
+ return super()._pre_button_mark_done()
+
+ def _check_expired_lots(self):
+ # We use the 'skip_expired' context key to avoid to make the check when
+ # user already confirmed the wizard about using expired lots.
+ if self.env.context.get('skip_expired'):
+ return False
+ expired_lot_ids = self.move_raw_ids.move_line_ids.filtered(lambda ml: ml.lot_id.product_expiry_alert).lot_id.ids
+ if expired_lot_ids:
+ return {
+ 'name': _('Confirmation'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'expiry.picking.confirmation',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': self._get_expired_context(expired_lot_ids),
+ }
+
+ def _get_expired_context(self, expired_lot_ids):
+ context = dict(self.env.context)
+ context.update({
+ 'default_lot_ids': [(6, 0, expired_lot_ids)],
+ 'default_production_ids': self.ids,
+ })
+ return context