Skip to content

Commit

Permalink
[MIG] stock_product_pack: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-zanotti committed Dec 18, 2023
1 parent dbad46e commit 67d8da1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion stock_product_pack/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 21 additions & 3 deletions stock_product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import math

from odoo import models
from odoo import api, models


class ProductProduct(models.Model):
Expand All @@ -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 = []
Expand All @@ -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)
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions stock_product_pack/tests/test_stock_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion stock_product_pack/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="pack_modifiable" position="after">
<field
name="dont_create_move"
attrs="{'invisible':['|', ('pack_ok', '=', False), ('detailed_type', '=', 'service')]}"
invisible="not pack_ok or detailed_type == 'service'"
/>
</field>
</field>
Expand Down

0 comments on commit 67d8da1

Please sign in to comment.