Skip to content

Commit

Permalink
[MIG] stock_picking_product_availability_inline: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Feb 17, 2025
1 parent 2eed50f commit b6ad847
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 85 deletions.
5 changes: 3 additions & 2 deletions stock_picking_product_availability_inline/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Stock Picking Product Availability Inline
!! source digest: sha256:bde30e8b7f2c6162ec6fb4c9b318c9c404d028e74a8d7c3b347c7aa781b4c02b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
Expand Down Expand Up @@ -74,6 +74,7 @@ Contributors

- Ernesto Tejeda
- Sergio Teruel
- Carlos Roca

Maintainers
-----------
Expand Down
7 changes: 4 additions & 3 deletions stock_picking_product_availability_inline/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Product Availability Inline",
"summary": "Show product availability in product drop-down in stock picking form view.",
"version": "15.0.1.0.1",
"development_status": "Beta",
"summary": "Show product availability in product drop-down of picking form view.",
"version": "18.0.1.0.0",
"development_status": "Production/Stable",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-availability",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"maintainers": ["CarlosRoca13"],
"depends": ["stock", "base_view_inheritance_extension"],
"data": ["views/stock_picking_views.xml", "views/stock_move_line_views.xml"],
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
from odoo import api, models


class ProductProduct(models.Model):
_inherit = "product.product"

def name_get(self):
res = super().name_get()
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
res = super().name_search(name=name, args=args, operator=operator, limit=limit)
if self.env.context.get("sp_product_stock_inline"):
product_dict = {r.id: r for r in self}
dp = self.env["decimal.precision"].precision_get("Product Unit of Measure")
new_res = []
for rec_name in res:
prod = product_dict[rec_name[0]]
name = f"{rec_name[1]} ({prod.free_qty:.{dp}f} {prod.uom_id.name})"
new_res.append((prod.id, name))
for product_id, display_name in res:
product = self.env["product.product"].browse(product_id)
new_res.append(
(
product_id,
f"{display_name} ({product.free_qty:.{dp}f}"
+ f" {product.uom_id.name})",
)
)
res = new_res
return res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class StockPicking(models.Model):
Expand All @@ -14,22 +14,6 @@ class StockPicking(models.Model):
)


class StockMove(models.Model):
_inherit = "stock.move"

@api.onchange("product_id")
def _onchange_product_id(self):
"""Avoid calling product name_get method several times
with 'sp_product_stock_inline' context key.
"""
sp_line = self
if self.env.context.get("sp_product_stock_inline"):
sp_line = self.with_context(
sp_product_stock_inline=False, warehouse=self.warehouse_id.id
)
return super(StockMove, sp_line)._onchange_product_id()


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

Expand All @@ -38,16 +22,3 @@ class StockMoveLine(models.Model):
string="Stock picking type warehouse",
related="picking_id.picking_type_id.warehouse_id",
)

@api.onchange("product_id")
def _onchange_product_id(self):
"""Avoid calling product name_get method several times
with 'sp_product_stock_inline' context key.
"""
sp_line = self
if self.env.context.get("sp_product_stock_inline"):
sp_line = self.with_context(
sp_product_stock_inline=False,
warehouse=self.picking_type_warehouse_id.id,
)
return super(StockMoveLine, sp_line)._onchange_product_id()
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [Tecnativa](https://www.tecnativa.com):
- Ernesto Tejeda
- Sergio Teruel
- Carlos Roca
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Stock Picking Product Availability Inline</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bde30e8b7f2c6162ec6fb4c9b318c9c404d028e74a8d7c3b347c7aa781b4c02b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-availability/tree/18.0/stock_picking_product_availability_inline"><img alt="OCA/stock-logistics-availability" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--availability-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-availability-18-0/stock-logistics-availability-18-0-stock_picking_product_availability_inline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-availability&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_product_availability_inline"><img alt="OCA/stock-logistics-workflow" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-workflow-18-0/stock-logistics-workflow-18-0-stock_picking_product_availability_inline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of ‘Warehouse Management’ to show
you the stock availability (Free To Use Quantity) of each product as
part of its name in the product drop-down widget on stock picking.</p>
Expand Down Expand Up @@ -400,10 +400,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-availability/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/stock-logistics-availability/issues/new?body=module:%20stock_picking_product_availability_inline%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/issues/new?body=module:%20stock_picking_product_availability_inline%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -420,6 +420,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Ernesto Tejeda</li>
<li>Sergio Teruel</li>
<li>Carlos Roca</li>
</ul>
</li>
</ul>
Expand All @@ -433,7 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<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>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-availability/tree/18.0/stock_picking_product_availability_inline">OCA/stock-logistics-availability</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-workflow/tree/18.0/stock_picking_product_availability_inline">OCA/stock-logistics-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT


@tagged("post_install", "-at_install")
class TestStockPickingProductAvailabilityInline(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.partner = cls.env["res.partner"].create({"name": "Partner"})
cls.product = cls.env["product.product"].create(
{"name": "Product", "type": "product"}
{
"name": "Product Availability Inline",
"default_code": "TEST",
"type": "consu",
"is_storable": True,
}
)
cls.warehouse1 = cls.env["stock.warehouse"].create(
{"name": "Warehouse 1", "code": "AI1"}
Expand Down Expand Up @@ -51,35 +49,23 @@ def test_stock_picking_product_rec_name(self):
self.env.ref("product.decimal_product_uom").write({"digits": 3})
# Show free_qty in warehouse1
self.assertEqual(
self.product.with_context(warehouse=self.warehouse1.id).free_qty,
self.product.with_context(warehouse_id=self.warehouse1.id).free_qty,
10.0,
)
picking_form = Form(
self.env["stock.picking"].with_context(
warehouse=self.warehouse1.id, sp_product_stock_inline=True
)
name_search = (
self.env["product.product"]
.with_context(warehouse_id=self.warehouse1.id, sp_product_stock_inline=True)
.name_search(name=self.product.display_name)
)
picking_form.partner_id = self.partner
picking_form.picking_type_id = self.env.ref("stock.picking_type_out")
with picking_form.move_ids_without_package.new() as line_form:
line_form.product_id = self.product
self.assertTrue(
line_form.product_id.display_name.endswith("(10.000 Units)")
)
self.assertTrue(name_search[0][1].endswith("(10.000 Units)"))
# Show free_qty in warehouse2
self.assertEqual(
self.product.with_context(warehouse=self.warehouse2.id).free_qty,
self.product.with_context(warehouse_id=self.warehouse2.id).free_qty,
20.0,
)
picking_form = Form(
self.env["stock.picking"].with_context(
warehouse=self.warehouse2.id, sp_product_stock_inline=True
)
name_search = (
self.env["product.product"]
.with_context(warehouse_id=self.warehouse2.id, sp_product_stock_inline=True)
.name_search(name=self.product.display_name)
)
picking_form.partner_id = self.partner
picking_form.picking_type_id = self.env.ref("stock.picking_type_out")
with picking_form.move_ids_without_package.new() as line_form:
line_form.product_id = self.product
self.assertTrue(
line_form.product_id.display_name.endswith("(20.000 Units)")
)
self.assertTrue(name_search[0][1].endswith("(20.000 Units)"))
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<attribute name="context" operation="update">
{
"sp_product_stock_inline": True,
"warehouse": picking_type_warehouse_id
"warehouse_id": picking_type_warehouse_id
}
</attribute>
</xpath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<field name="picking_type_warehouse_id" invisible="1" />
</xpath>
<xpath
expr="//field[@name='move_ids_without_package']/tree/field[@name='product_id']"
expr="//field[@name='move_ids_without_package']/list/field[@name='product_id']"
position="attributes"
>
<attribute name="context" operation="update">
{
"sp_product_stock_inline": True,
"warehouse": parent.picking_type_warehouse_id
"warehouse_id": parent.picking_type_warehouse_id
}
</attribute>
</xpath>
Expand Down

0 comments on commit b6ad847

Please sign in to comment.