| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from odoo import models, _ |
| 5 |
|
| 6 |
|
| 7 |
class MrpProduction(models.Model): |
| 8 |
_inherit = 'mrp.production' |
| 9 |
|
| 10 |
def pre_button_mark_done(self): |
| 11 |
confirm_expired_lots = self._check_expired_lots() |
| 12 |
if confirm_expired_lots: |
| 13 |
return confirm_expired_lots |
| 14 |
return super().pre_button_mark_done() |
| 15 |
|
| 16 |
def _check_expired_lots(self): |
| 17 |
|
| 18 |
|
| 19 |
if self.env.context.get('skip_expired'): |
| 20 |
return False |
| 21 |
expired_lot_ids = self.move_raw_ids.move_line_ids.filtered(lambda ml: ml.lot_id.product_expiry_alert).lot_id.ids |
| 22 |
if expired_lot_ids: |
| 23 |
return { |
| 24 |
'name': _('Confirmation'), |
| 25 |
'type': 'ir.actions.act_window', |
| 26 |
'res_model': 'expiry.picking.confirmation', |
| 27 |
'view_mode': 'form', |
| 28 |
'views': [(False, 'form')], |
| 29 |
'target': 'new', |
| 30 |
'context': self._get_expired_context(expired_lot_ids), |
| 31 |
} |
| 32 |
|
| 33 |
def _get_expired_context(self, expired_lot_ids): |
| 34 |
context = dict(self.env.context) |
| 35 |
context.update({ |
| 36 |
'default_lot_ids': [(6, 0, expired_lot_ids)], |
| 37 |
'default_production_ids': self.ids, |
| 38 |
}) |
| 39 |
return context |