diff --git a/stock_picking_volume_packaging/models/__init__.py b/stock_picking_volume_packaging/models/__init__.py index 6bda2d242..5c74c8c30 100644 --- a/stock_picking_volume_packaging/models/__init__.py +++ b/stock_picking_volume_packaging/models/__init__.py @@ -1 +1 @@ -from . import stock_move +from . import product_product diff --git a/stock_picking_volume_packaging/models/stock_move.py b/stock_picking_volume_packaging/models/product_product.py similarity index 56% rename from stock_picking_volume_packaging/models/stock_move.py rename to stock_picking_volume_packaging/models/product_product.py index 0a5fdde4a..e6d1571c9 100644 --- a/stock_picking_volume_packaging/models/stock_move.py +++ b/stock_picking_volume_packaging/models/product_product.py @@ -1,26 +1,26 @@ # Copyright 2020-2022 Camptocamp SA # Copyright 2023 ACSONE SA/NV +# Copyright 2023 Michael Tietz (MT Software) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import models -class StockMove(models.Model): +class ProductProduct(models.Model): + _inherit = "product.product" - _inherit = "stock.move" - - def _get_volume_for_qty(self, qty): + def _get_volume_for_qty(self, qty, from_uom=None): self.ensure_one() - product = self.product_id - if not product.packaging_ids.filtered("volume"): - return super()._get_volume_for_qty(qty=qty) - packagings_with_volume = product.with_context( + if not self.packaging_ids.filtered("volume"): + return super()._get_volume_for_qty(qty, from_uom) + qty = from_uom and from_uom._compute_quantity(qty, self.uom_id) or qty + packagings_with_volume = self.with_context( _packaging_filter=lambda p: p.volume ).product_qty_by_packaging(qty) volume = 0 for packaging_info in packagings_with_volume: if packaging_info.get("is_unit"): - pack_volume = product.volume + pack_volume = self.volume else: packaging = self.env["product.packaging"].browse(packaging_info["id"]) pack_volume = packaging.volume diff --git a/stock_picking_volume_packaging/tests/test_stock_move_volume.py b/stock_picking_volume_packaging/tests/test_stock_move_volume.py index 4b4e0b4b2..d6d735738 100644 --- a/stock_picking_volume_packaging/tests/test_stock_move_volume.py +++ b/stock_picking_volume_packaging/tests/test_stock_move_volume.py @@ -51,7 +51,7 @@ class TestStockMoveVolume(TransactionCase): move = self.env["stock.move"].new( {"product_id": self.product, "product_uom_qty": 16} ) - self.assertEqual(move._get_volume_for_qty(16), 2400) + self.assertEqual(move.product_id._get_volume_for_qty(16), 2400) def test_move_volume_package_with_dimension(self): """ @@ -87,4 +87,4 @@ class TestStockMoveVolume(TransactionCase): {"product_id": self.product, "product_uom_qty": 16} ) - self.assertEqual(move._get_volume_for_qty(16), 153) + self.assertEqual(move.product_id._get_volume_for_qty(16), 153)