From 821e7b2cc96cd0f6cd114deb1a80a1cbbc7d7716 Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua(etdj)" Date: Tue, 22 Aug 2023 13:54:01 +0000 Subject: [PATCH] [FIX] stock: Get the right quantity when saving a scrap order Steps: - Create a product tracked by serial number - Create a new scrap order in inventory -> operations - Add the created product, the serial number and save. Issue: The quantity is automatically set to 0.00 after saving. Reason: The ``StockScrap.scrap_qty`` field is computed and has a default value set to 0.0. On the xml form view when ``StockScrap.tracking`` is set to 'serial' the field is readonly and is not sent to the server when saving so the default value is used. The problem appears because initially the ``StockScrap.scrap_qty`` was precomputed so even it wasn't sent by the form, we already had the value. With the changes made we can't use ``precompute=True`` because ``StockScrap.scrap_qty`` depends on fields which aren't precomputed. Solution: In this context we have 3 cases: - If ``StockScrap.tracking`` is 'none', ``scrap_qty`` is not readonly so sent. - If ``StockScrap.tracking`` is 'lot', ``scrap_qty`` is not readonly so sent. - If ``StockScrap.tracking`` is 'serial', ``scrap_qty`` is readonly so not sent. As the only case of the issue is when the product is tracked by serial number(only one product) we can, set the default value of ``StockScrap.scrap_qty`` to 1. opw-3470888 closes odoo/odoo#132895 X-original-commit: 0d9fa534c3c17e87210f9d24cc90991d6dd8c0be Signed-off-by: Adrien Widart (awt) Signed-off-by: Eteil Junior Djoumatchoua (etdj) --- addons/stock/models/stock_scrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py index a51b5674b44..9792b46bb80 100644 --- a/addons/stock/models/stock_scrap.py +++ b/addons/stock/models/stock_scrap.py @@ -46,7 +46,7 @@ class StockScrap(models.Model): domain="[('scrap_location', '=', True)]", check_company=True, readonly=False) scrap_qty = fields.Float( 'Quantity', required=True, digits='Product Unit of Measure', - compute='_compute_scrap_qty', default=0.0, readonly=False, store=True) + compute='_compute_scrap_qty', default=1.0, readonly=False, store=True) state = fields.Selection([ ('draft', 'Draft'), ('done', 'Done')],