From 67d8da181854dda468453297b937debb8a728ac9 Mon Sep 17 00:00:00 2001 From: Bruno Zanotti Date: Mon, 18 Dec 2023 16:09:10 -0300 Subject: [PATCH] [MIG] stock_product_pack: Migration to 17.0 --- stock_product_pack/__manifest__.py | 2 +- stock_product_pack/models/product_product.py | 24 ++++++++++++++++--- .../tests/test_stock_product_pack.py | 15 +++++++----- .../views/product_template_views.xml | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/stock_product_pack/__manifest__.py b/stock_product_pack/__manifest__.py index 7ab78dc1c..f58301350 100644 --- a/stock_product_pack/__manifest__.py +++ b/stock_product_pack/__manifest__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Stock product Pack", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "Warehouse", "summary": "This module allows you to get the right available quantities " "of the packs", diff --git a/stock_product_pack/models/product_product.py b/stock_product_pack/models/product_product.py index ba2989823..9be2c0689 100644 --- a/stock_product_pack/models/product_product.py +++ b/stock_product_pack/models/product_product.py @@ -4,7 +4,7 @@ import math -from odoo import models +from odoo import api, models class ProductProduct(models.Model): @@ -13,10 +13,10 @@ class ProductProduct(models.Model): def _compute_quantities_dict( self, lot_id, owner_id, package_id, from_date=False, to_date=False ): - res = super()._compute_quantities_dict( + packs = self.filtered("pack_ok") + res = super(ProductProduct, self - packs)._compute_quantities_dict( lot_id, owner_id, package_id, from_date=from_date, to_date=to_date ) - packs = self.filtered("pack_ok") for product in packs.with_context(prefetch_fields=False): pack_qty_available = [] pack_virtual_available = [] @@ -27,6 +27,7 @@ def _compute_quantities_dict( for subproduct in subproducts: subproduct_stock = subproduct.product_id sub_qty = subproduct.quantity + # import pdb;pdb.set_trace() if sub_qty: pack_qty_available.append( math.floor(subproduct_stock.qty_available / sub_qty) @@ -48,6 +49,23 @@ def _compute_quantities_dict( } return res + @api.depends( + "stock_move_ids.product_qty", + "pack_line_ids.product_id.stock_move_ids.product_qty", + "stock_move_ids.state", + "pack_line_ids.product_id.stock_move_ids.state", + "stock_move_ids.quantity", + "pack_line_ids.product_id.stock_move_ids.quantity", + ) + @api.depends_context( + "lot_id", + "owner_id", + "package_id", + "from_date", + "to_date", + "location", + "warehouse", + ) def _compute_quantities(self): """In v13 Odoo introduces a filter for products not services. To keep how it was working on v12 we try to get stock for diff --git a/stock_product_pack/tests/test_stock_product_pack.py b/stock_product_pack/tests/test_stock_product_pack.py index cf789af2b..74fb7f199 100644 --- a/stock_product_pack/tests/test_stock_product_pack.py +++ b/stock_product_pack/tests/test_stock_product_pack.py @@ -166,13 +166,16 @@ def test_compute_quantities_dict(self): picking.action_confirm() self.assertEqual(self.pack_dc.virtual_available, 5) self.assertEqual(self.pack_dc.qty_available, 0) + # self.cr.commit() wizard_dict = picking.button_validate() - wizard = Form( - self.env[(wizard_dict.get("res_model"))].with_context( - **wizard_dict["context"] - ) - ).save() - wizard.process() + # import pdb;pdb.set_trace() + if wizard_dict is not True: + wizard = Form( + self.env[(wizard_dict.get("res_model"))].with_context( + **wizard_dict["context"] + ) + ).save() + wizard.process() self.assertEqual(self.pack_dc.virtual_available, 5) self.assertEqual(self.pack_dc.qty_available, 5) diff --git a/stock_product_pack/views/product_template_views.xml b/stock_product_pack/views/product_template_views.xml index 89c459003..79239a54a 100644 --- a/stock_product_pack/views/product_template_views.xml +++ b/stock_product_pack/views/product_template_views.xml @@ -11,7 +11,7 @@