summaryrefslogtreecommitdiff
path: root/addons/stock/wizard/stock_warn_insufficient_qty.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/stock/wizard/stock_warn_insufficient_qty.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/stock/wizard/stock_warn_insufficient_qty.py')
-rw-r--r--addons/stock/wizard/stock_warn_insufficient_qty.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/addons/stock/wizard/stock_warn_insufficient_qty.py b/addons/stock/wizard/stock_warn_insufficient_qty.py
new file mode 100644
index 00000000..19dccd23
--- /dev/null
+++ b/addons/stock/wizard/stock_warn_insufficient_qty.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+class StockWarnInsufficientQty(models.AbstractModel):
+ _name = 'stock.warn.insufficient.qty'
+ _description = 'Warn Insufficient Quantity'
+
+ product_id = fields.Many2one('product.product', 'Product', required=True)
+ location_id = fields.Many2one('stock.location', 'Location', domain="[('usage', '=', 'internal')]", required=True)
+ quant_ids = fields.Many2many('stock.quant', compute='_compute_quant_ids')
+ quantity = fields.Float(string="Quantity", required=True)
+ product_uom_name = fields.Char("Unit of Measure", required=True)
+
+ def _get_reference_document_company_id(self):
+ raise NotImplementedError()
+
+ @api.depends('product_id')
+ def _compute_quant_ids(self):
+ for quantity in self:
+ quantity.quant_ids = self.env['stock.quant'].search([
+ ('product_id', '=', quantity.product_id.id),
+ ('location_id.usage', '=', 'internal'),
+ ('company_id', '=', quantity._get_reference_document_company_id().id)
+ ])
+
+ def action_done(self):
+ raise NotImplementedError()
+
+
+class StockWarnInsufficientQtyScrap(models.TransientModel):
+ _name = 'stock.warn.insufficient.qty.scrap'
+ _inherit = 'stock.warn.insufficient.qty'
+ _description = 'Warn Insufficient Scrap Quantity'
+
+ scrap_id = fields.Many2one('stock.scrap', 'Scrap')
+
+ def _get_reference_document_company_id(self):
+ return self.scrap_id.company_id
+
+ def action_done(self):
+ return self.scrap_id.do_scrap()
+
+ def action_cancel(self):
+ # FIXME in master: we should not have created the scrap in a first place
+ if self.env.context.get('not_unlink_on_discard'):
+ return True
+ else:
+ return self.scrap_id.sudo().unlink()