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 authored and natuan9 committed Dec 10, 2024
1 parent 9132c70 commit 16ea92d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
14 changes: 9 additions & 5 deletions stock_product_pack/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ Authors
Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Ernesto Tejeda
- Pedro M. Baeza
- Sergio Teruel
- João Marques
- Ernesto Tejeda
- Pedro M. Baeza
- 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
35 changes: 22 additions & 13 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 Down Expand Up @@ -48,6 +48,11 @@ def _compute_quantities_dict(
}
return res

@api.depends(
"pack_line_ids.product_id.stock_move_ids.product_qty",
"pack_line_ids.product_id.stock_move_ids.state",
"pack_line_ids.product_id.stock_move_ids.quantity",
)
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 All @@ -60,16 +65,20 @@ def _compute_quantities(self):
ProductProduct, self - service_pack_products
)._compute_quantities()
res = service_pack_products._compute_quantities_dict(
self._context.get("lot_id"),
self._context.get("owner_id"),
self._context.get("package_id"),
self._context.get("from_date"),
self._context.get("to_date"),
self.env.context.get("lot_id"),
self.env.context.get("owner_id"),
self.env.context.get("package_id"),
self.env.context.get("from_date"),
self.env.context.get("to_date"),
)
for product in service_pack_products:
product.qty_available = res[product.id]["qty_available"]
product.incoming_qty = res[product.id]["incoming_qty"]
product.outgoing_qty = res[product.id]["outgoing_qty"]
product.virtual_available = res[product.id]["virtual_available"]
product.free_qty = res[product.id]["free_qty"]
product.update(
{
"qty_available": res[product.id]["qty_available"],
"incoming_qty": res[product.id]["incoming_qty"],
"outgoing_qty": res[product.id]["outgoing_qty"],
"virtual_available": res[product.id]["virtual_available"],
"free_qty": res[product.id]["free_qty"],
}
)
return result
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
16 changes: 11 additions & 5 deletions 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 All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -429,12 +429,18 @@ <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">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
18 changes: 10 additions & 8 deletions stock_product_pack/tests/test_stock_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import logging

from odoo.tests import Form, TransactionCase
from odoo.tests import Form, TransactionCase, tagged

_logger = logging.getLogger(__name__)


class TestSaleProductPack(TransactionCase):
@tagged("post_install", "-at_install")
class TestStockProductPack(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -167,12 +168,13 @@ def test_compute_quantities_dict(self):
self.assertEqual(self.pack_dc.virtual_available, 5)
self.assertEqual(self.pack_dc.qty_available, 0)
wizard_dict = picking.button_validate()
wizard = Form(
self.env[(wizard_dict.get("res_model"))].with_context(
**wizard_dict["context"]
)
).save()
wizard.process()
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 16ea92d

Please sign in to comment.