[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) <awt@odoo.com>
Signed-off-by: Eteil Junior Djoumatchoua (etdj) <etdj@odoo.com>
This commit is contained in:
Eteil Djoumatchoua(etdj)
2023-08-28 16:42:07 +00:00
parent 9d49150afa
commit 821e7b2cc9
+1 -1
View File
@@ -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')],