Skip to content

[MIG] stock_by_warehouse_sale: Migration to 19.0 T#98915#1732

Open
rolandojduartem wants to merge 18 commits into
Vauxoo:19.0from
vauxoo-dev:19.0-stock_by_warehouse_sale-mig-t98915-dev-rolando
Open

[MIG] stock_by_warehouse_sale: Migration to 19.0 T#98915#1732
rolandojduartem wants to merge 18 commits into
Vauxoo:19.0from
vauxoo-dev:19.0-stock_by_warehouse_sale-mig-t98915-dev-rolando

Conversation

@rolandojduartem
Copy link
Copy Markdown
Contributor

Summary

This migration adapts the stock_by_warehouse_sale module to Odoo 19.0, updating its metadata, view structure, context passing, and test suite to align with Odoo 19.0 standards.

Changes

1. View Adaptation & Formats (views/sale_order_views.xml)

  • Renamed the tree view XPath target to list to match Odoo 19.0 view architecture changes (//field[@name='order_line']/list).
  • Replaced the deprecated product_type != 'product' visibility check with the Odoo 19.0 standard not is_storable inside the alert widget layout.
  • Kept the original UX decision to disable inline list editing (editable="bottom") by removing the editable attribute.

2. Context Passing Fix (models/sale_order_line.py)

  • Modified the JSON stock retrieval method (_compute_get_warehouses_stock) to pass the raw integer line.warehouse_id.id in context instead of the full recordset.
  • This complies with Odoo 19.0 SQL query compiler requirements (e.g., in _get_domain_locations), resolving a silent warning and preventing the inline widget from displaying incorrect 0.00 values while displaying correct stock levels in the dropdown.
  • Fixed a loop scope issue where record.warehouse_id was set correcting the assignment path dynamically.

3. Manifest (__manifest__.py)

  • Upgraded the module version to 19.0.1.0.0.
  • Ensured dependencies are clean and correctly mapped.

4. Robust Deterministic Unit Tests (tests/test_sale_order.py)

  • Created a fully deterministic test suite (TestStockByWarehouseSale) validating the warehouse stock calculation and recomputation functionality.
  • Relies on native environment triggers by updating the warehouses_stock_recompute field instead of manually invoking calculations.
  • Cleaned database cache before assertion by using invalidate_recordset(), ensuring solid and repeatable test executions.

Testing

Procedure to verify the migration and context correction:

  1. Create a Sale Order and add a sale order line with a storable product (is_storable = True).
  2. Verify that there is stock unreserved in the chosen warehouse for that product (e.g., 10.00).
  3. Toggle the warehouses_stock_recompute checkbox on the sale order line form.
  4. Verify that the inline text on the widget displays the accurate unreserved stock level matching the popover table.
  • Related Task: T#98915
Screenshot from 2026-05-21 23-31-55

@rolandojduartem rolandojduartem force-pushed the 19.0-stock_by_warehouse_sale-mig-t98915-dev-rolando branch from ebb463a to 6f168c1 Compare May 22, 2026 05:53
@rolandojduartem
Copy link
Copy Markdown
Contributor Author

Hi, @luisg123v and @desdelinux, please, could you review it?

this depends on #1731

@desdelinux
Copy link
Copy Markdown

@luisg123v review

@luisg123v luisg123v self-requested a review May 25, 2026 17:27
Comment thread stock_by_warehouse_sale/__manifest__.py Outdated
"demo": [],
"test": [],
"installable": True,
"auto_install": False,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this in the source version, similar as done in #1730.

def _compute_warehouse_stock(self):
for record in self:
record.warehouse_id = self.order_id.warehouse_id
record.warehouse_id = record.order_id.warehouse_id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix, do it in the source version.


@tagged("sale_order", "post_install", "-at_install")
class TestStockByWarehouseSale(TransactionCase):
"""Test suite to verify warehouse stock reporting functionality in sales orders."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous docstring, remove.

Same in similar cases like the setUpClass

super().setUpClass()
cls.company = cls.env.company
cls.partner = cls.env["res.partner"].create({"name": "Test Customer"})
cls.warehouse = cls.env["stock.warehouse"].search([("company_id", "=", cls.company.id)], limit=1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it have an external ID?

)
cls.env["stock.quant"]._update_available_quantity(cls.product, cls.warehouse.lot_stock_id, 10.0)

def test_sale_order_line_warehouse_stock(self) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_01


sale_order_line = self.env["sale.order.line"].create(
{
"order_id": sale_order.id,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create it inside the order's vals, using Command.create. That would be more accurate, as usually both are created at the same time.

rolandojduartem and others added 18 commits May 28, 2026 06:46
…warehouse

Ensure the JSON stock calculation methods in both product.product and
product.template robustly handle context values of 'warehouse_id' that
are integers or sequences of integers by automatically browsing them
into standard recordsets.

This prevents stock calculation issues when Odoo's core query compiler
(which expects integer IDs in context for '_get_domain_locations')
is invoked by caller modules.
…ad (Vauxoo#1358)

We need avoid using compute fields as possible because of the following issue:
 - odoo/odoo#30578
warehouses_stock is a computed field used just one time but re-computed too many times:
 - Opening sale order (one time by each line)
 - Saving sale order
 - Choosing a product_id
And it computation is more and more slow when the database grows.
It is making a big overhead saving sale.order.

With this change we have the same behaviour using it just for onchange
product_id or forcing from a seudo-button (field boolean)
A real button is not used since that it requires save the record to work

Using the technical of fields with store=False and onchange methods

Check more details from Vauxoo#1358
In order to get the real value, since that this field is not set when onchange method is used
The following is performed:
- Remove useless test that actually did nothing
- Remove data tags from views
- Remove encoding headers from Python files
- Remove superfluous readonly attribute from related fields
- Remove useless keys from the manifest
- Fix typos on the README
* [I18N] stock_by_warehouse_sale: Fix term names

Some term names are handled differently on v12.0, but those changes were
not taken into account when migrating this module from v11.0.

* [I18N] stock_by_warehouse_purchase: Fix term names

Some term names are handled differently on v12.0, but those changes were
not taken into account when migrating this module from v11.0.
This removes:
- Hencoding headers, fixing lint `utf8-coding-comment`
- Headers like `# Part of Odoo`
- And other ones
In previous Odoo versions, the form view was poped up when editing a
sale order line, as long as the option "Manage Product packaging" was
enabled. This is no longer the case [1], so we re-enable it manually,
in order to be able to see current inventory when filling a line.

[1] odoo/odoo@e813487e75f1
…able products

This functionality is for storable products to show the information in
the warehouses, now this field is invisible for products which are not
storable products.
- Simplify the way to define modifiers as states, required, readonly,
  invisible and column_invisible as part of [1].
- Adapt the stock by warehouse field to be computed.

[1] odoo/odoo#104741
…tock compute

Fix a multi-record issue in _compute_warehouse_stock where 'self' was
incorrectly referenced instead of the loop variable 'record' when
assigning warehouse_id. This prevented correct evaluation and raised
singleton errors on multi-line actions.

Additionally, remove redundant empty/default keys from the manifest.
Migrate the module to Odoo 19.0 to ensure the warehouse stock overview
feature remains fully operational in sales orders.

Changes have been introduced to align with the framework shifts:
- Adopt Odoo 19.0's view simplifications [1], where the `tree` view was
  renamed to `list` view.
- Support Odoo 19.0's simplified product type logic [2], where physical
  products are identified by the `is_storable` flag instead of the legacy `type == 'product'`.
- Fix a multi-record context bug in the compute method where looping over
  `self` was incorrectly referencing the collective `self.order_id`. Looping
  with `record.order_id` prevents incorrect values and performance loss when
  processing multiple sale order lines at once.
- Clean up manifest keys that match default values to comply with the updated
  linter guidelines.

[1]: odoo/odoo@4d5e84f7
[2]: odoo/odoo@728d9f83
@rolandojduartem rolandojduartem force-pushed the 19.0-stock_by_warehouse_sale-mig-t98915-dev-rolando branch from 6f168c1 to 4223655 Compare May 28, 2026 07:32
@rolandojduartem
Copy link
Copy Markdown
Contributor Author

@luisg123v done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants