From b345e1963bfc2956e9e3d9dc59ee5fa54270ae43 Mon Sep 17 00:00:00 2001 From: niyasraphy Date: Sat, 22 Oct 2022 07:15:01 +0000 Subject: [PATCH] [FIX] stock: scrap order with 0 quantity currently odoo is allowing to create a scrap order record with 0 quantty, which doesn't make sense and also if it is allowed, user wont be able to edit change the quantity later. currently zero quantity is not blocked by _check_positive_qty_done on stock.move.line. And it doesn't make sense to scrap 0, thus preventing the same by raising a validation closes odoo/odoo#105752 X-original-commit: eb899fe8dda12d0f0e4ae515bb01e65981f4fbcd Signed-off-by: Arnold Moyaux (arm) --- addons/stock/i18n/stock.pot | 6 ++++++ addons/stock/models/stock_scrap.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 373d305d54d..c5a2a965bb6 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -9042,6 +9042,12 @@ msgstr "" msgid "You can only delete draft moves." msgstr "" +#. module: stock +#: code:addons/stock/models/stock_scrap.py:0 +#, python-format +msgid "You can only enter positive quantities." +msgstr "" + #. module: stock #: code:addons/stock/models/stock_move_line.py:0 #, python-format diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py index 4192a8e0fc1..575491301ec 100644 --- a/addons/stock/models/stock_scrap.py +++ b/addons/stock/models/stock_scrap.py @@ -3,7 +3,7 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError -from odoo.tools import float_compare +from odoo.tools import float_compare, float_is_zero class StockScrap(models.Model): @@ -171,6 +171,9 @@ class StockScrap(models.Model): def action_validate(self): self.ensure_one() + if float_is_zero(self.scrap_qty, + precision_rounding=self.product_uom_id.rounding): + raise UserError(_('You can only enter positive quantities.')) if self.product_id.type != 'product': return self.do_scrap() precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')