Skip to content

Commit

Permalink
[MIG] stock_by_warehouse: Migration to 17.0
Browse files Browse the repository at this point in the history
- Simplify the way to define modifiers as states, required, readonly,
  invisible and column_invisible as part of [1].
- Remove owl="1" from OWL templates, as it's not needed anymore as all
  of them are OWL now as part of [2].
- Change qty_done to quantity and picked = True as part of [3].
- Adapt use of read_group to _read_group as part of [4].

[1] odoo/odoo#104741
[2] odoo/odoo#130467
[3] odoo/odoo#137864
[4] odoo/odoo#110737
  • Loading branch information
xmglord committed Apr 4, 2024
1 parent 6fb07d6 commit e3bb94f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion stock_by_warehouse/__manifest__.py
@@ -1,6 +1,6 @@
{
"name": "Stock by Warehouse",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"summary": """
Know the stock in all your warehouses with a simple click
from the product form.
Expand Down
14 changes: 9 additions & 5 deletions stock_by_warehouse/models/product_product.py
Expand Up @@ -51,13 +51,17 @@ def _compute_qty_available_not_reserved(self):
quants = (
self.env["stock.quant"]
.with_context(lang=False)
.read_group(domain_quant, fields=["product_id", "quantity", "reserved_quantity"], groupby="product_id")
._read_group(
domain_quant,
groupby=["product_id"],
aggregates=["quantity:sum", "reserved_quantity:sum"],
)
)

res = {}
for quant in quants:
quantity = quant.get("quantity") - quant.get("reserved_quantity")
res[quant.get("product_id")[0]] = max(quantity, 0.0)
res = {
product.id: max(quantity - reserved_quantity, 0.0)
for product, quantity, reserved_quantity in quants
}

for prod in self:
prod.qty_available_not_res = res.get(prod.id, 0.0)
Expand Down
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="stock_by_warehouse.ShowWarehouseInfo" owl="1">
<t t-name="stock_by_warehouse.ShowWarehouseInfo">
<div>
<p t-if="this.props.byLocation" class="availability_product my-0 mr-2">
The product is available in: <t t-out="show" /> locations.
Expand All @@ -24,7 +24,7 @@
</div>
</t>

<t t-name="stock_by_warehouse.ProductWarehousePopOver" owl="1">
<t t-name="stock_by_warehouse.ProductWarehousePopOver">
<h3 t-if="this.props.title" class="o_popover_header" t-out="this.props.title" />
<div class="popover-body stock-by-warehouse-widget">
<div class="panel clearfix container">
Expand Down Expand Up @@ -85,7 +85,7 @@
</div>
</t>

<t t-name="stock_by_warehouse.StockAvailabilityPopOver" owl="1">
<t t-name="stock_by_warehouse.StockAvailabilityPopOver">
<h3 t-if="this.props.title" class="o_popover_header" t-out="this.props.title" />
<div class="popover-body stock-by-warehouse-widget">
<div t-if="this.props.title">
Expand Down
6 changes: 3 additions & 3 deletions stock_by_warehouse/tests/test_stock_available_unreserved.py
Expand Up @@ -142,7 +142,7 @@ def test01_stock_levels(self):
self.compare_qty_available_not_res(product_a, 0)
self.compare_qty_available_not_res(self.template_ab, 0)

picking_in_a.move_line_ids.write({"qty_done": 2})
picking_in_a.move_line_ids.write({"quantity": 2, "picked": True})
picking_in_a.button_validate()
self.compare_qty_available_not_res(product_a, 2)
self.compare_qty_available_not_res(self.template_ab, 2)
Expand All @@ -159,7 +159,7 @@ def test01_stock_levels(self):

picking_in_b.action_confirm()
picking_in_b.action_assign()
picking_in_b.move_line_ids.write({"qty_done": 3})
picking_in_b.move_line_ids.write({"quantity": 3, "picked": True})
picking_in_b.button_validate()
self.compare_qty_available_not_res(product_a, 2)
self.compare_qty_available_not_res(product_b, 3)
Expand Down Expand Up @@ -203,7 +203,7 @@ def test01_stock_levels(self):
product.warehouses_stock_recompute = True
self.assertEqual(safe_eval(product.warehouses_stock)["warehouse"], 3)

picking_out_a.move_line_ids.write({"qty_done": 2})
picking_out_a.move_line_ids.write({"quantity": 2, "picked": True})
picking_out_a.button_validate()
self.compare_qty_available_not_res(product_b, 1)
self.compare_qty_available_not_res(self.template_ab, 3)
6 changes: 3 additions & 3 deletions stock_by_warehouse/views/product_product_views.xml
Expand Up @@ -11,18 +11,18 @@
name="warehouses_stock"
widget="warehouse"
groups="stock.group_stock_multi_warehouses"
attrs="{'invisible': [('detailed_type', '!=', 'product')]}"
invisible="detailed_type != 'product'"
/>
<label
for="warehouses_stock_location"
groups="stock.group_stock_multi_warehouses"
attrs="{'invisible': [('detailed_type', '!=', 'product')]}"
invisible="detailed_type != 'product'"
/>
<div
name="location_widget"
class="d-flex"
groups="stock.group_stock_multi_warehouses"
attrs="{'invisible': [('detailed_type', '!=', 'product')]}"
invisible="detailed_type != 'product'"
>
<field name="warehouses_stock_location" widget="warehouse" options='{"by_location": True}' />
<field name="warehouses_stock_recompute" widget="boolean_toggle" />
Expand Down
4 changes: 2 additions & 2 deletions stock_by_warehouse/views/product_template_views.xml
Expand Up @@ -10,13 +10,13 @@
<label
for="warehouses_stock"
groups="stock.group_stock_multi_warehouses"
attrs="{'invisible': [('detailed_type', '!=', 'product')]}"
invisible="detailed_type != 'product'"
/>
<div
name="warehouse_widget"
class="d-flex"
groups="stock.group_stock_multi_warehouses"
attrs="{'invisible': [('detailed_type', '!=', 'product')]}"
invisible="detailed_type != 'product'"
>
<field name="warehouses_stock" widget="warehouse" />
<field name="warehouses_stock_recompute" widget="boolean_toggle" />
Expand Down

0 comments on commit e3bb94f

Please sign in to comment.