[FIX] stock_secondary_unit: The second qty is computed when a sml is created. Second qty compute the qty_done field.

The second uom not locked for non draft move lines
This commit is contained in:
sergio-teruel
2023-11-23 17:26:27 +01:00
committed by lk-eska
parent 90a78dd04d
commit 35374e3958
3 changed files with 4 additions and 12 deletions

View File

@@ -1,7 +1,6 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools.float_utils import float_round
class StockMove(models.Model):
@@ -49,16 +48,7 @@ class StockMoveLine(models.Model):
def create(self, vals):
move = self.env["stock.move"].browse(vals.get("move_id", False))
if move.secondary_uom_id:
uom = self.env["uom.uom"].browse(vals["product_uom_id"])
factor = move.secondary_uom_id.factor * uom.factor
move_line_qty = vals.get("product_uom_qty", vals.get("qty_done", 0.0))
qty = float_round(
move_line_qty / (factor or 1.0),
precision_rounding=move.secondary_uom_id.uom_id.rounding,
)
vals.update(
{"secondary_uom_qty": qty, "secondary_uom_id": move.secondary_uom_id.id}
)
vals["secondary_uom_id"] = move.secondary_uom_id.id
return super().create(vals)
@api.depends("secondary_uom_id", "secondary_uom_qty")

View File

@@ -156,7 +156,7 @@ class TestProductSecondaryUnit(TransactionCase):
delivery_order.move_line_ids.mapped("secondary_uom_qty")
)
self.assertEqual(uom_qty, 20.0)
self.assertEqual(secondary_uom_qty, 40.0)
self.assertEqual(secondary_uom_qty, 0.0)
def test_picking_secondary_unit(self):
product = self.product_template.product_variant_ids[0]

View File

@@ -15,6 +15,7 @@
domain="['|', ('product_id', '=', product_id),
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
('product_id', '=', False)]"
attrs="{'readonly': [('state', '!=', 'draft'), ('id', '!=', False)]}"
options="{'no_create': True}"
/>
</field>
@@ -36,6 +37,7 @@
domain="['|', ('product_id', '=', product_id),
'&amp;', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
('product_id', '=', False)]"
attrs="{'readonly': [('state', '!=', 'draft'), ('id', '!=', False)]}"
options="{'no_create': True}"
/>
</field>