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 May 14, 2024
1 parent ad7936d commit 0f1a25f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
4 changes: 4 additions & 0 deletions stock_product_pack/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Contributors
- Sergio Teruel
- João Marques

- `ADHOC SA <https://www.adhoc.com.ar>`__:

- Bruno Zanotti

Maintainers
-----------

Expand Down
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
2 changes: 2 additions & 0 deletions stock_product_pack/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
- Pedro M. Baeza
- Sergio Teruel
- João Marques
- [ADHOC SA](https://www.adhoc.com.ar):
- Bruno Zanotti
5 changes: 4 additions & 1 deletion stock_product_pack/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -429,6 +428,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>João Marques</li>
</ul>
</li>
<li><a class="reference external" href="https://www.adhoc.com.ar">ADHOC SA</a>:<ul>
<li>Bruno Zanotti</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
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(

Check warning on line 173 in stock_product_pack/tests/test_stock_product_pack.py

View check run for this annotation

Codecov / codecov/patch

stock_product_pack/tests/test_stock_product_pack.py#L173

Added line #L173 was not covered by tests
self.env[(wizard_dict.get("res_model"))].with_context(
**wizard_dict["context"]
)
).save()
wizard.process()

Check warning on line 178 in stock_product_pack/tests/test_stock_product_pack.py

View check run for this annotation

Codecov / codecov/patch

stock_product_pack/tests/test_stock_product_pack.py#L178

Added line #L178 was not covered by tests
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 0f1a25f

Please sign in to comment.