mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[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:
@@ -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")
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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),
|
||||
'&', ('product_tmpl_id.product_variant_ids', 'in', [product_id]),
|
||||
('product_id', '=', False)]"
|
||||
attrs="{'readonly': [('state', '!=', 'draft'), ('id', '!=', False)]}"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user