summaryrefslogtreecommitdiff
path: root/addons/mrp_product_expiry/wizard
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mrp_product_expiry/wizard')
-rw-r--r--addons/mrp_product_expiry/wizard/__init__.py4
-rw-r--r--addons/mrp_product_expiry/wizard/confirm_expiry.py44
-rw-r--r--addons/mrp_product_expiry/wizard/confirm_expiry_view.xml42
3 files changed, 90 insertions, 0 deletions
diff --git a/addons/mrp_product_expiry/wizard/__init__.py b/addons/mrp_product_expiry/wizard/__init__.py
new file mode 100644
index 00000000..e6eb849c
--- /dev/null
+++ b/addons/mrp_product_expiry/wizard/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import confirm_expiry
diff --git a/addons/mrp_product_expiry/wizard/confirm_expiry.py b/addons/mrp_product_expiry/wizard/confirm_expiry.py
new file mode 100644
index 00000000..df65be83
--- /dev/null
+++ b/addons/mrp_product_expiry/wizard/confirm_expiry.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models, _
+
+
+class ConfirmExpiry(models.TransientModel):
+ _inherit = 'expiry.picking.confirmation'
+
+ production_ids = fields.Many2many('mrp.production', readonly=True)
+ workorder_id = fields.Many2one('mrp.workorder', readonly=True)
+
+ @api.depends('lot_ids')
+ def _compute_descriptive_fields(self):
+ if self.production_ids or self.workorder_id:
+ # Shows expired lots only if we are more than one expired lot.
+ self.show_lots = len(self.lot_ids) > 1
+ if self.show_lots:
+ # For multiple expired lots, they are listed in the wizard view.
+ self.description = _(
+ "You are going to use some expired components."
+ "\nDo you confirm you want to proceed ?"
+ )
+ else:
+ # For one expired lot, its name is written in the wizard message.
+ self.description = _(
+ "You are going to use the component %(product_name)s, %(lot_name)s which is expired."
+ "\nDo you confirm you want to proceed ?",
+ product_name=self.lot_ids.product_id.display_name,
+ lot_name=self.lot_ids.name,
+ )
+ else:
+ super(ConfirmExpiry, self)._compute_descriptive_fields()
+
+ def confirm_produce(self):
+ ctx = dict(self._context, skip_expired=True)
+ ctx.pop('default_lot_ids')
+ return self.production_ids.with_context(ctx).button_mark_done()
+
+ def confirm_workorder(self):
+ ctx = dict(self._context, skip_expired=True)
+ ctx.pop('default_lot_ids')
+ return self.workorder_id.with_context(ctx).record_production()
+
diff --git a/addons/mrp_product_expiry/wizard/confirm_expiry_view.xml b/addons/mrp_product_expiry/wizard/confirm_expiry_view.xml
new file mode 100644
index 00000000..5256ebd2
--- /dev/null
+++ b/addons/mrp_product_expiry/wizard/confirm_expiry_view.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="confirm_expiry_view_mrp_inherit" model="ir.ui.view">
+ <field name="name">Confirm</field>
+ <field name="model">expiry.picking.confirmation</field>
+ <field name="inherit_id" ref="product_expiry.confirm_expiry_view"/>
+ <field name="arch" type="xml">
+ <xpath expr="//field[@name='description']" position="after">
+ <field name="picking_ids" invisible="1"/>
+ <field name="production_ids" invisible="1"/>
+ <field name="workorder_id" invisible="1"/>
+ </xpath>
+ <xpath expr="//button[@name='process']" position="attributes">
+ <attribute name="attrs">{'invisible': [('picking_ids', '=', [])]}</attribute>
+ </xpath>
+ <xpath expr="//button[@name='process_no_expired']" position="attributes">
+ <attribute name="attrs">{'invisible': [('picking_ids', '=', [])]}</attribute>
+ </xpath>
+ <xpath expr="//button[@special='cancel']" position="attributes">
+ <attribute name="attrs">{'invisible': [('production_ids', '!=', [])]}</attribute>
+ </xpath>
+ <xpath expr="//button[@name='process']" position="after">
+ <!-- From Produce Product wizard -->
+ <button name="confirm_produce"
+ string="Confirm"
+ type="object"
+ attrs="{'invisible': [('production_ids', '=', [])]}"
+ class="btn-primary"/>
+ <button special="cancel"
+ string="Discard"
+ attrs="{'invisible': [('production_ids', '=', [])]}"
+ class="btn-secondary"/>
+ <!-- From a Workorder -->
+ <button name="confirm_workorder"
+ string="Confirm"
+ type="object"
+ attrs="{'invisible': [('workorder_id', '=', False)]}"
+ class="btn-primary"/>
+ </xpath>
+ </field>
+ </record>
+</odoo>