|
1 | 1 | # Copyright 2020-2022 Camptocamp SA
|
2 | 2 | # Copyright 2023 ACSONE SA/NV
|
| 3 | +# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de> |
3 | 4 | # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
4 | 5 |
|
5 | 6 | from odoo import models
|
6 | 7 |
|
7 | 8 |
|
8 |
| -class StockMove(models.Model): |
| 9 | +class ProductProduct(models.Model): |
| 10 | + _inherit = "product.product" |
9 | 11 |
|
10 |
| - _inherit = "stock.move" |
11 |
| - |
12 |
| - def _get_volume_for_qty(self, qty): |
| 12 | + def _get_volume_for_qty(self, qty, from_uom=None): |
13 | 13 | self.ensure_one()
|
14 |
| - product = self.product_id |
15 |
| - if not product.packaging_ids.filtered("volume"): |
16 |
| - return super()._get_volume_for_qty(qty=qty) |
17 |
| - packagings_with_volume = product.with_context( |
| 14 | + if not self.packaging_ids.filtered("volume"): |
| 15 | + return super()._get_volume_for_qty(qty, from_uom) |
| 16 | + qty = from_uom and from_uom._compute_quantity(qty, self.uom_id) or qty |
| 17 | + packagings_with_volume = self.with_context( |
18 | 18 | _packaging_filter=lambda p: p.volume
|
19 | 19 | ).product_qty_by_packaging(qty)
|
20 | 20 | volume = 0
|
21 | 21 | for packaging_info in packagings_with_volume:
|
22 | 22 | if packaging_info.get("is_unit"):
|
23 |
| - pack_volume = product.volume |
| 23 | + pack_volume = self.volume |
24 | 24 | else:
|
25 | 25 | packaging = self.env["product.packaging"].browse(packaging_info["id"])
|
26 | 26 | pack_volume = packaging.volume
|
|
0 commit comments